diff pidgin-twitter.c @ 42:68db38b5b401

fixed changeset 41:0a81ccfa1941
author mikanbako <maoutwo@gmail.com>
date Tue, 13 May 2008 02:06:32 +0900
parents 0a81ccfa1941
children caa42301f520
line wrap: on
line diff
--- a/pidgin-twitter.c	Tue May 13 00:35:42 2008 +0900
+++ b/pidgin-twitter.c	Tue May 13 02:06:32 2008 +0900
@@ -36,6 +36,8 @@
 #define COMMAND     2
 #define PSEUDO      3
 #define EXCESS_MARKUP  4
+#define FONT_MARKUP  5
+#define ATMARK_AFTER_A 6
 
 #define PLUGIN_ID	            "gtk-honeyplanet-pidgin_twitter"
 #define PLUGIN_NAME	            "pidgin-twitter"
@@ -62,7 +64,7 @@
 #define twitter_error(fmt, ...)	purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, "%s():%4d:  " fmt, __FUCTION__, (int)__LINE__, ## __VA_ARGS__);
 
 /* globals */
-static GRegex *regp[5];
+static GRegex *regp[7];
 static gboolean suppress_oops = FALSE;
 
 /* prototypes */
@@ -95,9 +97,21 @@
 {
     gchar *newstr = NULL;
 
-    /* replace senders with link */
+    /* strip font */
+    newstr = g_regex_replace(regp[FONT_MARKUP], *str, -1, 0, "\\1", 0, NULL);
+    twitter_debug("*str = %s newstr = %s\n", *str, newstr);
+    g_free(*str);
+    *str = newstr;
+
+    /* change from atmark after a to atmark before a */
+    newstr = g_regex_replace(regp[ATMARK_AFTER_A], *str, -1, 0, "@\\1", 0, NULL);
+    twitter_debug("*str = %s newstr = %s\n", *str, newstr);
+    g_free(*str);
+    *str = newstr;
+
+    /* strip link */
     newstr =
-        g_regex_replace(regp[EXCESS_MARKUP], *str, -1, 0, "\\1\\2\\3", 0, NULL);
+        g_regex_replace(regp[EXCESS_MARKUP], *str, -1, 0, "\\1", 0, NULL);
 
     twitter_debug("*str = %s newstr = %s\n", *str, newstr);
 
@@ -517,8 +531,10 @@
          G_REGEX_RAW, 0, NULL);
     regp[EXCESS_MARKUP] =
         g_regex_new
-        ("([@dDfFgGlLmMnNtTwW]{1})(\\s?)(?:<font .+>)?<a href=.+>(?:<font .+>)?([A-Za-z0-9_]+)(?:</font>)?</a>(?:</font>)?", 0, 0,
+        ("<a href=\"http://twitter.com/([A-Za-z0-9_]+)\">\\1</a>", 0, 0,
          NULL);
+    regp[FONT_MARKUP] = g_regex_new("<font .+?>(.+?)</font>", 0, 0, NULL);
+    regp[ATMARK_AFTER_A] = g_regex_new("(<a href=.+?>)@", 0, 0, NULL);
 
     /* attach counter to the existing twitter window */
     gboolean enabled = purple_prefs_get_bool(OPT_COUNTER);
@@ -554,6 +570,8 @@
     g_regex_unref(regp[COMMAND]);
     g_regex_unref(regp[PSEUDO]);
     g_regex_unref(regp[EXCESS_MARKUP]);
+    g_regex_unref(regp[FONT_MARKUP]);
+    g_regex_unref(regp[ATMARK_AFTER_A]);
 
     /* detach from twitter window */
     detach_from_window();