Mercurial > pidgin
changeset 16084:a5a831a5f186
Patch cleanups:
* Whitespace consistency
* Comment cleanups
* if (foo) g_free(foo); fixes
* other small stuff, I'm sure
This closes ticket #78.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 13 Apr 2007 04:15:14 +0000 |
parents | f2a4b05407d7 |
children | 83a17c27b900 |
files | ChangeLog.API libpurple/protocols/msn/msn-utils.c libpurple/util.c libpurple/util.h pidgin/gtkconv.c pidgin/gtkimhtml.c |
diffstat | 6 files changed, 84 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog.API Fri Apr 13 04:13:24 2007 +0000 +++ b/ChangeLog.API Fri Apr 13 04:15:14 2007 +0000 @@ -360,6 +360,8 @@ * gaim_gtk_blist_set_headline * gaim_gtk_set_urgent * GtkGaimScrollBook and its functions. + * purple_markup_unescape_entity() + * purple_markup_get_css_property() Signals - Changed: (See the Doxygen docs for details on all signals.) * Signal propagation now stops after a handler returns a non-NULL value.
--- a/libpurple/protocols/msn/msn-utils.c Fri Apr 13 04:13:24 2007 +0000 +++ b/libpurple/protocols/msn/msn-utils.c Fri Apr 13 04:15:14 2007 +0000 @@ -114,7 +114,8 @@ if (cur && (*(cur = cur + 3) != ';')) { - if(*cur == '1') { + if (*cur == '1') + { /* RTL text was received */ pre = g_string_append(pre, "<SPAN style=\"direction:rtl;text-align:right;\">"); post = g_string_prepend(post, "</SPAN>"); @@ -285,22 +286,20 @@ else if (!g_ascii_strncasecmp(c, "style=\"", 7)) { /* Parse inline CSS attributes */ - char* attributes; + char *attributes; int attr_len = 0; c += 7; while (*(c + attr_len) != '\0' && *(c + attr_len) != '"') attr_len++; - if(*(c + attr_len) == '"') + if (*(c + attr_len) == '"') { char *attr_dir; attributes = g_strndup(c, attr_len); attr_dir = purple_markup_get_css_property(attributes, "direction"); - if(attr_dir && (!strncasecmp(attr_dir, "RTL", 3))) + if (attr_dir && (!strncasecmp(attr_dir, "RTL", 3))) direction = '1'; - if(attr_dir) - g_free(attr_dir); - if(attributes) - g_free(attributes); + g_free(attr_dir); + g_free(attributes); } }
--- a/libpurple/util.c Fri Apr 13 04:13:24 2007 +0000 +++ b/libpurple/util.c Fri Apr 13 04:15:14 2007 +0000 @@ -861,10 +861,8 @@ * Markup Functions **************************************************************************/ -/* Returns a NULL-terminated string after unescaping an entity - * (eg. &, < & etc.) starting at s. Returns NULL on failure.*/ const char * -purple_markup_detect_entity(const char *text, int *length) +purple_markup_unescape_entity(const char *text, int *length) { const char *pln; int len, pound; @@ -909,9 +907,9 @@ return pln; } -gchar* -purple_markup_get_css_property(const gchar *style, - const gchar *opt) +char * +purple_markup_get_css_property(const gchar *style, + const gchar *opt) { const gchar *css_str = style; const gchar *css_value_start; @@ -919,48 +917,50 @@ gchar *tmp; gchar *ret; - if(!css_str) + if (!css_str) return NULL; /* find the CSS property */ - while(1){ - /* skip widespace characters */ - while(*css_str && g_ascii_isspace(*css_str)) + while (1) + { + /* skip whitespace characters */ + while (*css_str && g_ascii_isspace(*css_str)) css_str++; - if(!g_ascii_isalpha(*css_str)) + if (!g_ascii_isalpha(*css_str)) return NULL; - if(g_ascii_strncasecmp(css_str, opt, strlen(opt))) + if (g_ascii_strncasecmp(css_str, opt, strlen(opt))) { /* go to next css property positioned after the next ';' */ - while(*css_str && *css_str != '"' && *css_str != ';') + while (*css_str && *css_str != '"' && *css_str != ';') css_str++; if(*css_str != ';') return NULL; css_str++; } - else break; + else + break; } /* find the CSS value position in the string */ css_str += strlen(opt); - while(*css_str && g_ascii_isspace(*css_str)) + while (*css_str && g_ascii_isspace(*css_str)) css_str++; - if(*css_str != ':') + if (*css_str != ':') return NULL; css_str++; - while(*css_str && g_ascii_isspace(*css_str)) + while (*css_str && g_ascii_isspace(*css_str)) css_str++; - if(*css_str == '\0' || *css_str == '"' || *css_str == ';') + if (*css_str == '\0' || *css_str == '"' || *css_str == ';') return NULL; /* mark the CSS value */ css_value_start = css_str; - while(*css_str && *css_str != '"' && *css_str != ';') + while (*css_str && *css_str != '"' && *css_str != ';') css_str++; css_value_end = css_str - 1; /* Removes trailing whitespace */ - while(css_value_end > css_value_start && g_ascii_isspace(*css_value_end)) + while (css_value_end > css_value_start && g_ascii_isspace(*css_value_end)) css_value_end--; tmp = g_strndup(css_value_start, css_value_end - css_value_start + 1); @@ -1570,7 +1570,7 @@ const char *pln; int len; - if ((pln = purple_markup_detect_entity(c, &len)) == NULL) { + if ((pln = purple_markup_unescape_entity(c, &len)) == NULL) { len = 1; g_snprintf(buf, sizeof(buf), "%c", *c); pln = buf; @@ -1775,7 +1775,7 @@ visible = TRUE; } - if (str2[i] == '&' && (ent = purple_markup_detect_entity(str2 + i, &entlen)) != NULL) + if (str2[i] == '&' && (ent = purple_markup_unescape_entity(str2 + i, &entlen)) != NULL) { while (*ent) str2[j++] = *ent++; @@ -2093,7 +2093,7 @@ int len; const char *ent; - if ((ent = purple_markup_detect_entity(c, &len)) != NULL) { + if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) { ret = g_string_append(ret, ent); c += len; } else if (!strncmp(c, "<br>", 4)) {
--- a/libpurple/util.h Fri Apr 13 04:13:24 2007 +0000 +++ b/libpurple/util.h Fri Apr 13 04:15:14 2007 +0000 @@ -464,32 +464,39 @@ /** * Returns a constant string of the character representation of the HTML - * entity pointed by *text. For example *text="&" will return "&" and so on. - * The *text variable is expected to point to a '&' - the first character - * of the entity. On unrecognized entity the function will return NULL. - * Note that this function, unlike purple_unescape_html() does not seek - * the string for the entity, does not replace the entity and does not + * entity pointed to by @a text. For example, purple_markup_unescape_entity("&") + * will return "&". The @a text variable is expected to point to an '&', + * the first character of the entity. If given an unrecognized entity, the function + * returns @c NULL. + * + * Note that this function, unlike purple_unescape_html(), does not search + * the string for the entity, does not replace the entity, and does not * return a newly allocated string. * - * @param text A string containing HTML entity. - * @param length The string length of the deteced entity is stored in this variable. + * @param text A string containing an HTML entity. + * @param length If not @c NULL, the string length of the entity is stored in this location. + * * @return A constant string containing the character representation of the given entity. */ -const char * purple_markup_detect_entity(const char *text, int *length); +const char * purple_markup_unescape_entity(const char *text, int *length); /** * Returns a newly allocated string containing the value of the CSS property specified - * in opt. The *style argument is expected to point to a HTML inline CSS style. - * ( ie <span style="[inline css]"> ) The function will seek for the CSS propery and - * return it's value. Example: for style="direction:rtl;color:#dc4d1b;" opt="color" - * the function's return value would be #dc4d1b. On error or if the requested property - * was not found, the function returns NULL. + * in opt. The @a style argument is expected to point to a HTML inline CSS. + * (i.e. <span style="[inline css]"> ) The function will seek for the CSS property and + * return its value. + * + * For example, purple_markup_get_css_property("direction:rtl;color:#dc4d1b;", "color") + * would return "#dc4d1b". + * + * On error or if the requested property was not found, the function returns @c NULL. * * @param style A string containing the inline CSS text. - * @param opt The requested CSS property. - * @return the value of the requested CSS property. + * @param opt The requested CSS property. + * + * @return The value of the requested CSS property. */ -gchar* purple_markup_get_css_property(const gchar *style, const gchar *opt); +char * purple_markup_get_css_property(const gchar *style, const gchar *opt); /*@}*/
--- a/pidgin/gtkconv.c Fri Apr 13 04:13:24 2007 +0000 +++ b/pidgin/gtkconv.c Fri Apr 13 04:15:14 2007 +0000 @@ -4895,16 +4895,16 @@ gtkconv->newday = mktime(tm); } -/* Detect string direction and encapsulate the string in a RLE/LRE/PDF unicode characters - str - pointer to string (string is realocated and new pointer is returned) */ +/* Detect string direction and encapsulate the string in RLE/LRE/PDF unicode characters + str - pointer to string (string is re-allocated and the pointer updated) */ static void str_embed_direction_chars(char **str) { char pre_str[4]; char post_str[10]; - char* ret = g_malloc(strlen(*str)+13); - - if (PANGO_DIRECTION_RTL == pango_find_base_dir(*str, strlen(*str))) + char *ret = g_malloc(strlen(*str)+13); + + if (PANGO_DIRECTION_RTL == pango_find_base_dir(*str, -1)) { g_sprintf(pre_str, "%c%c%c", 0xE2, 0x80, 0xAB); /* RLE */ @@ -4927,7 +4927,6 @@ g_free(*str); *str = ret; - return; } /* Returns true if the given HTML contains RTL text */ @@ -4938,22 +4937,22 @@ const gchar *start, *end; gboolean res = FALSE; - if(purple_markup_find_tag("span", html, &start, &end, &attributes)) + if (purple_markup_find_tag("span", html, &start, &end, &attributes)) { /* tmp is a member of attributes and is free with g_datalist_clear call */ const char *tmp = g_datalist_get_data(&attributes, "dir"); - if(tmp && !g_ascii_strcasecmp(tmp, "RTL")) + if (tmp && !g_ascii_strcasecmp(tmp, "RTL")) res = TRUE; - if(!res) + if (!res) { - char *tmp2 = NULL; tmp = g_datalist_get_data(&attributes, "style"); - if(tmp) - tmp2 = purple_markup_get_css_property(tmp, "direction"); - if(tmp2 && !g_ascii_strcasecmp(tmp2, "RTL")) - res = TRUE; - if(tmp2) + if (tmp) + { + char *tmp2 = purple_markup_get_css_property(tmp, "direction"); + if (tmp2 && !g_ascii_strcasecmp(tmp2, "RTL")) + res = TRUE; g_free(tmp2); + } } g_datalist_clear(&attributes); @@ -5112,8 +5111,8 @@ /* Bi-Directional support - set timestamp direction using unicode characters */ is_rtl_message = html_is_rtl(message); - /* Enforce direction only if message is RTL - donesn't effect LTR users */ - if(is_rtl_message) + /* Enforce direction only if message is RTL - doesn't effect LTR users */ + if (is_rtl_message) str_embed_direction_chars(&mdate); if (mtime >= gtkconv->newday) @@ -5168,7 +5167,7 @@ GHashTable *smiley_data = NULL; /* Enforce direction on alias */ - if(is_rtl_message) + if (is_rtl_message) str_embed_direction_chars(&alias_escaped); if (flags & PURPLE_MESSAGE_SEND)
--- a/pidgin/gtkimhtml.c Fri Apr 13 04:13:24 2007 +0000 +++ b/pidgin/gtkimhtml.c Fri Apr 13 04:15:14 2007 +0000 @@ -1744,7 +1744,7 @@ if (!t->values) break; - if(*x == '&' && (amp = purple_markup_detect_entity(x, &alen))) { + if(*x == '&' && (amp = purple_markup_unescape_entity(x, &alen))) { gboolean matched = TRUE; /* Make sure all chars of the unescaped value match */ while (*(amp + 1)) { @@ -2063,7 +2063,7 @@ ret = g_string_new(""); e = val; while(*e) { - if((c = purple_markup_detect_entity(e, &len))) { + if((c = purple_markup_unescape_entity(e, &len))) { ret = g_string_append(ret, c); e += len; } else { @@ -2665,7 +2665,7 @@ /* NEW_BIT (NEW_TEXT_BIT); */ /* Bi-Directional text support */ - if(direction && (!strncasecmp(direction, "RTL", 3))) { + if (direction && (!strncasecmp(direction, "RTL", 3))) { rtl_direction = TRUE; /* insert RLE character to set direction */ ws[wpos++] = 0xE2; @@ -2675,15 +2675,13 @@ gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); ws[0] = '\0'; wpos = 0; } - if(direction) - g_free(direction); - - if(alignment && (!strncasecmp(alignment, "RIGHT", 5))) { + g_free(direction); + + if (alignment && (!strncasecmp(alignment, "RIGHT", 5))) { align_right = TRUE; align_line = gtk_text_iter_get_line(iter); } - if(alignment) - g_free(alignment); + g_free(alignment); font = g_new0 (GtkIMHtmlFontDetail, 1); if (fonts) @@ -2893,7 +2891,7 @@ pos += smilelen; wpos = 0; ws[0] = 0; - } else if (*c == '&' && (amp = purple_markup_detect_entity(c, &tlen))) { + } else if (*c == '&' && (amp = purple_markup_unescape_entity(c, &tlen))) { while(*amp) { ws [wpos++] = *amp++; } @@ -2951,7 +2949,7 @@ ws[wpos++] = 0x80; ws[wpos++] = 0x8F; - if(!rtl_direction) + if (!rtl_direction) { /* insert LRM character to set direction */ /* (alignment=right and direction=LTR) */ @@ -4575,9 +4573,9 @@ /* Bi-directional text support */ /* Get to the first non-neutral character */ - while((PANGO_DIRECTION_NEUTRAL == pango_unichar_direction(gtk_text_iter_get_char(&non_neutral_iter))) + while ((PANGO_DIRECTION_NEUTRAL == pango_unichar_direction(gtk_text_iter_get_char(&non_neutral_iter))) && gtk_text_iter_forward_char(&non_neutral_iter)); - if(PANGO_DIRECTION_RTL == pango_unichar_direction(gtk_text_iter_get_char(&non_neutral_iter))) { + if (PANGO_DIRECTION_RTL == pango_unichar_direction(gtk_text_iter_get_char(&non_neutral_iter))) { is_rtl_message = TRUE; g_string_append(str, "<SPAN style=\"direction:rtl;text-align:right;\">"); } @@ -4668,7 +4666,7 @@ g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); /* Bi-directional text support - close tags */ - if(is_rtl_message) + if (is_rtl_message) g_string_append(str, "</SPAN>"); g_queue_free(q);