diff pidgin-twitter.c @ 170:c3f205ec4619

work in progress asymmetric bracket code.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 30 Jul 2008 21:06:08 +0900
parents 56e3873e58a8
children dfe644871483
line wrap: on
line diff
--- a/pidgin-twitter.c	Wed Jul 30 17:11:03 2008 +0900
+++ b/pidgin-twitter.c	Wed Jul 30 21:06:08 2008 +0900
@@ -61,6 +61,21 @@
 /* our implementation */
 /**********************/
 
+gchar *
+twitter_memrchr(const gchar *s, int c, size_t n)
+{
+    int nn = n;
+
+    g_return_val_if_fail(s != NULL, NULL);
+
+    while(nn+1) {
+        if((int)*(s+nn) == c)
+            return (gchar *)(s+nn);
+        nn--;
+    }
+    return NULL;
+}
+
 static gchar *html_tags[] = {
     "<a href=",
     "</a>",
@@ -141,6 +156,7 @@
         return str;
     }
 
+#if 0
     begin = strchr(startp, '<');
     if(begin)
         end = strchr(begin + 1, '>');
@@ -151,6 +167,33 @@
         g_free(html);
         return str; /* no corresponding >, we have done. */
     }
+#else
+    /* xxx needs test */
+    end = strchr(startp, '>');
+    if(end) {
+        begin = twitter_memrchr(startp, '<', end - startp);
+        if(begin < startp)
+            begin = NULL;
+    }
+
+    if(!begin && !end) {
+        tmp = g_strconcat(str, startp, NULL);
+        g_free(str);
+        str = tmp;
+        g_free(html);
+        return str; /* no corresponding >, we have done. */
+    }
+
+    /* xxx simplify */
+    if(!begin && end) {
+        tmp = g_strndup(startp, end - startp + 1);
+        tmp2 = g_strconcat(str, tmp, NULL);
+        g_free(str);
+        str = tmp2;
+        startp = end + 1;
+        goto loop;
+    }
+#endif
 
     /* here, both < and > are found */
     /* concatenate leading part to dest */