changeset 171:dfe644871483

revised asymmetric bracket code.
author Yoshiki Yazawa <yaz@honeyplnaet.jp>
date Thu, 31 Jul 2008 04:36:21 +0900
parents c3f205ec4619
children 3c5fc8d7b506 7fb35f47a477
files pidgin-twitter.c
diffstat 1 files changed, 19 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Wed Jul 30 21:06:08 2008 +0900
+++ b/pidgin-twitter.c	Thu Jul 31 04:36:21 2008 +0900
@@ -61,7 +61,7 @@
 /* our implementation */
 /**********************/
 
-gchar *
+static gchar *
 twitter_memrchr(const gchar *s, int c, size_t n)
 {
     int nn = n;
@@ -108,7 +108,7 @@
 {
     gchar *head, *tail;     /* head and tail of html */
     gchar *begin, *end;     /* begin:<  end:> */
-    gchar *html, *str;      /* copied src and str to be returned */
+    gchar *html, *str;      /* copied src and string to be returned */
 /*    gchar *vis1, *vis2; */     /* begin and end of address part */
     gchar *startp;          /* starting point marker */
     gchar **tagp;           /* tag iterator */
@@ -156,45 +156,29 @@
         return str;
     }
 
-#if 0
-    begin = strchr(startp, '<');
-    if(begin)
-        end = strchr(begin + 1, '>');
-    if(!end) {
-        tmp = g_strconcat(str, startp, NULL);
-        g_free(str);
-        str = tmp;
-        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) { /* '>' found but no corresponding '<' */
+            tmp = g_strndup(startp, end - startp + 1); /* concat until '>' */
+            tmp2 = g_strconcat(str, tmp, NULL);
+            g_free(str);
+            str = tmp2;
+            startp = end + 1;
+            goto loop;
+        }
     }
-
-    if(!begin && !end) {
-        tmp = g_strconcat(str, startp, NULL);
+    else { /* neither '>' nor '<' were found */
+        tmp = g_strconcat(str, startp, NULL); /* concat the rest */
         g_free(str);
         str = tmp;
         g_free(html);
-        return str; /* no corresponding >, we have done. */
+        return str;
     }
 
-    /* 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 */
     tmp = g_strndup(startp, begin - startp);
@@ -230,15 +214,16 @@
                 startp = end + 1;
                 goto loop;
             } /* <a href= */
-#else
-            if(0) {
-            }
-#endif
             else {
                 /* anything else: discard whole <>. */
                 startp = end + 1;
                 goto loop;
             }
+#else
+            /* anything else: discard whole <>. */
+            startp = end + 1;
+            goto loop;
+#endif
         }  /* valid tag */
     }