Mercurial > pidgin.yaz
diff libpurple/util.c @ 27791:ab1185e87ca5
- more normalization for window title
- apply botch_utf() to outgoing alias name in msn14 protocol
- now botch_utf() and sanitize_utf() accept -1 and NULL as the length of source string and the pointer to length of converted string respectively.
- now botch_ucs() and botch_utf() skip conversion if _WIN32 is defined.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 13 Mar 2008 14:50:21 +0000 |
parents | 2cb44870580d |
children | 85d5b6c06a6c |
line wrap: on
line diff
--- a/libpurple/util.c Wed Mar 12 19:31:01 2008 +0000 +++ b/libpurple/util.c Thu Mar 13 14:50:21 2008 +0000 @@ -4709,6 +4709,13 @@ return g_string_free(string, FALSE); } + +#ifdef _WIN32 +void botch_ucs(gchar *ucs_src, gsize len) +{ + /* no operation */ +} +#else void botch_ucs(gchar *ucs_src, gsize len) { gint i; @@ -4757,6 +4764,7 @@ } } +#endif #ifdef _WIN32 void sanitize_ucs(gchar *ucs, gsize len) @@ -4815,9 +4823,12 @@ gchar *sanitize_utf(const gchar *msg, gsize len, gsize *newlen) { g_return_val_if_fail(msg != NULL, NULL); + if(len == -1) + len = strlen(msg); g_return_val_if_fail(len > 0, NULL); - *newlen = len; + if(newlen) + *newlen = len; return g_strndup(msg, len); } @@ -4829,6 +4840,8 @@ guchar *utf; g_return_val_if_fail(msg != NULL, NULL); + if(len == -1) + len = strlen(msg); g_return_val_if_fail(len > 0, NULL); utf = (guchar *)g_strndup(msg, len); @@ -4864,25 +4877,25 @@ break; case 0xbf: switch(*(utf+i+2)){ - case 0xa0:// ¢ + case 0xa0: // ¢ *(utf+i) = 0xc2; *(utf+i+1) = 0xa2; memmove(utf+i+2, utf+i+3, - len-i-3); //1byte詰める + len-i-3); //shorten by 1byte bytes--; break; case 0xa1: // £ *(utf+i) = 0xc2; *(utf+i+1) = 0xa3; memmove(utf+i+2, utf+i+3, - len-i-3); //1byte詰める + len-i-3); //shorten by 1byte bytes--; break; case 0xa2: // ¬ *(utf+i) = 0xc2; *(utf+i+1) = 0xac; memmove(utf+i+2, utf+i+3, - len-i-3); //1byte詰める + len-i-3); //shorten by 1byte bytes--; break; } @@ -4892,20 +4905,36 @@ } } *(utf+bytes)= 0x00; //terminate - *newlen = bytes; + if(newlen) + *newlen = bytes; return (gchar *)utf; } #endif - +#ifdef _WIN32 +gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) +{ + g_return_val_if_fail(msg != NULL, NULL); + if(len == -1) + len = strlen(msg); + g_return_val_if_fail(len > 0, NULL); + + if(newlen) + *newlen = len; + + return g_strndup(msg, len); +} +#else gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) { int i,bytes; unsigned char *utf; g_return_val_if_fail(msg != NULL, NULL); + if(len == -1) + len = strlen(msg); g_return_val_if_fail(len > 0, NULL); - + bytes = len; utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */ @@ -4968,6 +4997,8 @@ } //switch } *(utf+bytes) = 0x00; //terminate - *newlen = bytes; + if(newlen) + *newlen = bytes; return (gchar *)utf; } +#endif