# HG changeset patch # User Yoshiki Yazawa # Date 1217446581 -32400 # Node ID dfe644871483e836df8a50b25a8499042d4a5fb5 # Parent c3f205ec461991a0de26b67305c61088b9a0281b revised asymmetric bracket code. diff -r c3f205ec4619 -r dfe644871483 pidgin-twitter.c --- 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; } /* . */ startp = end + 1; goto loop; } +#else + /* anything else: discard whole <>. */ + startp = end + 1; + goto loop; +#endif } /* valid tag */ }