Mercurial > pidgin.yaz
diff libpurple/util.c @ 27768:969a2aeae461
propagate from branch 'im.pidgin.pidgin' (head b7875f81b48bb1a776ac4b2473cc7376cb35b0f9)
to branch 'im.pidgin.pidgin.yaz' (head e22890a44520ea1129da935f8ce82ea795081201)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 27 Feb 2008 12:21:29 +0000 |
parents | dc47e908965f e9cf897bd873 |
children | c9b4fdb3fdb1 |
line wrap: on
line diff
--- a/libpurple/util.c Wed Feb 27 09:18:06 2008 +0000 +++ b/libpurple/util.c Wed Feb 27 12:21:29 2008 +0000 @@ -1209,6 +1209,8 @@ return FALSE; q = strstr(p, end_token); + if(q == NULL) //yaz + return FALSE; /* Trim leading blanks */ while (*p != '\n' && g_ascii_isspace(*p)) { @@ -1221,7 +1223,7 @@ } /* Don't bother with null strings */ - if (p == q) + if (p >= q) return FALSE; if (q != NULL && (!no_value_token || @@ -4707,3 +4709,232 @@ return g_string_free(string, FALSE); } +void botch_ucs(gchar *ucs, gssize len) +{ + gint i; + + for(i=0;i<len;i+=2){ + switch(*(ucs+i)){ + case 0x00: + switch(*(ucs+i+1)){ + case 0xa2: // ¢ + *(ucs+i) = 0xff; + *(ucs+i+1) = 0xe0; + break; + case 0xa3: // £ + *(ucs+i) = 0xff; + *(ucs+i+1) = 0xe1; + break; + case 0xac: // ¬ + *(ucs+i) = 0xff; + *(ucs+i+1) = 0xe2; + break; + } + break; + case 0x20: // ‖ + if(*(ucs+i+1) == 0x16){ + *(ucs+i) = 0x22; + *(ucs+i+1) = 0x25; + } + break; + case 0x22: // − + if(*(ucs+i+1) == 0x12){ + *(ucs+i) = 0xff; + *(ucs+i+1) = 0x0d; + } + break; + case 0x30: // 〜 + if(*(ucs+i+1) == 0x1c){ + *(ucs+i) = 0xff; + *(ucs+i+1) = 0x5e; + } + break; + } + } + +} + +void sanitize_ucs(gchar *ucs, gssize len) +{ + gint i; + + for(i=0;i<len;i+=2){ + switch(*(ucs+i)){ + case 0x22: + switch(*(ucs+i+1)){ + case 0x25: // ‖ + *(ucs+i) = 0x20; + *(ucs+i+1) = 0x16; + break; + } + break; + case 0xff: + switch(*(ucs+i+1)){ + case 0x0d: // − + *(ucs+i) = 0x22; + *(ucs+i+1) = 0x12; + break; + case 0x5e: // 〜 + *(ucs+i) = 0x30; + *(ucs+i+1) = 0x1c; + break; + case 0xe0: // ¢ + *(ucs+i) = 0x00; + *(ucs+i+1) = 0xa2; + break; + case 0xe1: // £ + *(ucs+i) = 0x00; + *(ucs+i+1) = 0xa3; + break; + case 0xe2: // ¬ + *(ucs+i) = 0x00; + *(ucs+i+1) = 0xac; + break; + } + break; + } + } +} + +guchar *sanitize_utf(unsigned char *msg, size_t len, size_t *newlen) +{ + gint i; + size_t bytes; + unsigned char *utf; + + utf = g_strndup(msg, len); + + bytes = len; + + for(i=0;i<len;i++){ + switch(*(utf+i)){ + case 0xe2: + if(*(utf+i+1) == 0x88) { + if(*(utf+i+2) == 0xa5) { // ‖ + *(utf+i) = 0xe2; + *(utf+i+1) = 0x80; + *(utf+i+2) = 0x96; + } + } + break; + case 0xef: + switch(*(utf+i+1)){ + case 0xbc: + if(*(utf+i+2) == 0x8d) { // − + *(utf+i) = 0xe2; + *(utf+i+1) = 0x88; + *(utf+i+2) = 0x92; + } + break; + case 0xbd: + if(*(utf+i+2) == 0x9e) { // 〜 + *(utf+i) = 0xe3; + *(utf+i+1) = 0x80; + *(utf+i+2) = 0x9c; + } + break; + case 0xbf: + switch(*(utf+i+2)){ + case 0xa0:// ¢ + *(utf+i) = 0xc2; + *(utf+i+1) = 0xa2; + memmove(utf+i+2, utf+i+3, + len-i-3); //1byte詰める + bytes--; + break; + case 0xa1: // £ + *(utf+i) = 0xc2; + *(utf+i+1) = 0xa3; + memmove(utf+i+2, utf+i+3, + len-i-3); //1byte詰める + bytes--; + break; + case 0xa2: // ¬ + *(utf+i) = 0xc2; + *(utf+i+1) = 0xac; + memmove(utf+i+2, utf+i+3, + len-i-3); //1byte詰める + bytes--; + break; + } + break; + } + break; + } + } + *(utf+bytes)= 0x00; //terminate + *newlen = bytes; + return utf; +} + + +guchar *botch_utf(const void *msg, size_t len, size_t *newlen) +{ + int i,bytes; + unsigned char *utf; + + bytes = len; + + utf = g_malloc0(bytes*3/2+1); /* new length might be 3/2 in the worst case */ + memcpy(utf, msg, bytes); + + for(i=0;i<bytes;i++){ + switch(*(utf+i)){ + case 0xc2: + switch(*(utf+i+1)){ + case 0xa2: // ¢ + *(utf+i) = 0xef; + *(utf+i+1) = 0xbf; + memmove(utf+i+3, utf+i+2, bytes-i-2); + *(utf+i+2) = 0xa0; + bytes++; + break; + case 0xa3: // £ + *(utf+i) = 0xef; + *(utf+i+1) = 0xbf; + memmove(utf+i+3, utf+i+2, bytes-i-2); + *(utf+i+2) = 0xa1; + bytes++; + break; + case 0xac: // ¬ + *(utf+i) = 0xef; + *(utf+i+1) = 0xbf; + memmove(utf+i+3, utf+i+2, bytes-i-2); + *(utf+i+2) = 0xa2; + bytes++; + break; + } + break; + case 0xe2: + switch(*(utf+i+1)){ + case 0x80: // ‖ + if(*(utf+i+2) == 0x96){ + *(utf+i) = 0xe2; + *(utf+i+1) = 0x88; + *(utf+i+2) = 0xa5; + } + break; + case 0x88: // − + if(*(utf+i+1) == 0x92){ + *(utf+i) = 0xef; + *(utf+i+1) = 0xbc; + *(utf+i+2) = 0x8d; + } + break; + } + break; + case 0xe3: // 〜 + if(*(utf+i+1) == 0x80){ + if(*(utf+i+2) == 0x9c){ + *(utf+i) = 0xef; + *(utf+i+1) = 0xbd; + *(utf+i+2) = 0x9e; + } + } + break; + } //switch + } + *(utf+bytes) = 0x00; //terminate + *newlen = bytes; + return utf; +}