comparison libpurple/protocols/yahoo/util.c @ 27743:a0a8b61301c8

Simplify a wee bit
author Mark Doliner <mark@kingant.net>
date Thu, 30 Jul 2009 23:43:01 +0000
parents 908be3822215
children 6d37c29df78a
comparison
equal deleted inserted replaced
27741:9d5d6b9ae18a 27743:a0a8b61301c8
170 } 170 }
171 171
172 char *yahoo_convert_to_numeric(const char *str) 172 char *yahoo_convert_to_numeric(const char *str)
173 { 173 {
174 GString *gstr = NULL; 174 GString *gstr = NULL;
175 char *retstr;
176 const unsigned char *p; 175 const unsigned char *p;
177 176
178 gstr = g_string_sized_new(strlen(str) * 6 + 1); 177 gstr = g_string_sized_new(strlen(str) * 6 + 1);
179 178
180 for (p = (unsigned char *)str; *p; p++) { 179 for (p = (unsigned char *)str; *p; p++) {
181 g_string_append_printf(gstr, "&#%u;", *p); 180 g_string_append_printf(gstr, "&#%u;", *p);
182 } 181 }
183 182
184 retstr = gstr->str; 183 return g_string_free(gstr, FALSE);
185
186 g_string_free(gstr, FALSE);
187
188 return retstr;
189 } 184 }
190 185
191 /* 186 /*
192 * I found these on some website but i don't know that they actually 187 * I found these on some website but i don't know that they actually
193 * work (or are supposed to work). I didn't implement them yet. 188 * work (or are supposed to work). I didn't implement them yet.
343 338
344 char *yahoo_codes_to_html(const char *x) 339 char *yahoo_codes_to_html(const char *x)
345 { 340 {
346 GString *s, *tmp; 341 GString *s, *tmp;
347 int i, j, xs, nomoreendtags = 0; /* s/endtags/closinganglebrackets */ 342 int i, j, xs, nomoreendtags = 0; /* s/endtags/closinganglebrackets */
348 char *match, *ret; 343 char *match;
349 344
350 s = g_string_sized_new(strlen(x)); 345 s = g_string_sized_new(strlen(x));
351 346
352 for (i = 0, xs = strlen(x); i < xs; i++) { 347 for (i = 0, xs = strlen(x); i < xs; i++) {
353 if ((x[i] == 0x1b) && (x[i+1] == '[')) { 348 if ((x[i] == 0x1b) && (x[i+1] == '[')) {
428 else 423 else
429 g_string_append_c(s, x[i]); 424 g_string_append_c(s, x[i]);
430 } 425 }
431 } 426 }
432 427
433 ret = s->str; 428 purple_debug_misc("yahoo", "yahoo_codes_to_html: Returning string: '%s'.\n", s->str);
434 g_string_free(s, FALSE); 429 return g_string_free(s, FALSE);
435 purple_debug_misc("yahoo", "yahoo_codes_to_html: Returning string: '%s'.\n", ret);
436 return ret;
437 } 430 }
438 431
439 /* borrowed from gtkimhtml */ 432 /* borrowed from gtkimhtml */
440 #define MAX_FONT_SIZE 7 433 #define MAX_FONT_SIZE 7
441 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1]) 434 #define POINT_SIZE(x) (_point_sizes [MIN ((x > 0 ? x : 1), MAX_FONT_SIZE) - 1])
640 633
641 char *yahoo_html_to_codes(const char *src) 634 char *yahoo_html_to_codes(const char *src)
642 { 635 {
643 int i, j, len; 636 int i, j, len;
644 GString *dest; 637 GString *dest;
645 char *ret, *esc; 638 char *esc;
646 GQueue *colors, *tags; 639 GQueue *colors, *tags;
647 GQueue *ftattr = NULL; 640 GQueue *ftattr = NULL;
648 gboolean no_more_specials = FALSE; 641 gboolean no_more_specials = FALSE;
649 642
650 colors = g_queue_new(); 643 colors = g_queue_new();
825 g_string_append_c(dest, src[i]); 818 g_string_append_c(dest, src[i]);
826 } 819 }
827 } 820 }
828 } 821 }
829 822
830 ret = dest->str; 823 esc = g_strescape(dest->str, NULL);
831 g_string_free(dest, FALSE);
832
833 esc = g_strescape(ret, NULL);
834 purple_debug_misc("yahoo", "yahoo_html_to_codes: Returning string: '%s'.\n", esc); 824 purple_debug_misc("yahoo", "yahoo_html_to_codes: Returning string: '%s'.\n", esc);
835 g_free(esc); 825 g_free(esc);
836 826
837 yahoo_htc_queue_cleanup(colors); 827 yahoo_htc_queue_cleanup(colors);
838 yahoo_htc_queue_cleanup(tags); 828 yahoo_htc_queue_cleanup(tags);
839 829
840 return ret; 830 return g_string_free(dest, FALSE);
841 } 831 }