Mercurial > pidgin.yaz
comparison src/util.c @ 10258:357d4fa1bfbe
[gaim-migrate @ 11400]
This is the IRC fallback encoding patch and gaim_utf8_salvage function
that just hit oldstatus. If CVS didn't suck, I wouldn't have to
generate two commits for this. :-P
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Wed, 24 Nov 2004 06:39:47 +0000 |
parents | 7ff9b8b22e7d |
children | 8d42237564f6 |
comparison
equal
deleted
inserted
replaced
10257:b98f856e2e5e | 10258:357d4fa1bfbe |
---|---|
3055 g_free(utf8); | 3055 g_free(utf8); |
3056 | 3056 |
3057 return NULL; | 3057 return NULL; |
3058 } | 3058 } |
3059 | 3059 |
3060 #define utf8_first(x) ((x & 0x80) == 0 || (x & 0xe0) == 0xc0 \ | |
3061 || (x & 0xf0) == 0xe0 || (x & 0xf8) == 0xf) | |
3062 gchar * | |
3063 gaim_utf8_salvage(const char *str) | |
3064 { | |
3065 GString *workstr; | |
3066 const char *end; | |
3067 | |
3068 g_return_val_if_fail(str != NULL, NULL); | |
3069 | |
3070 workstr = g_string_sized_new(strlen(str)); | |
3071 | |
3072 do { | |
3073 g_utf8_validate(str, -1, &end); | |
3074 workstr = g_string_append_len(workstr, str, end - str); | |
3075 str = end; | |
3076 if (*str == '\0') | |
3077 break; | |
3078 do { | |
3079 workstr = g_string_append_c(workstr, '?'); | |
3080 str++; | |
3081 } while (!utf8_first(*str)); | |
3082 } while (*str != '\0'); | |
3083 | |
3084 return g_string_free(workstr, FALSE); | |
3085 } | |
3086 | |
3060 char * | 3087 char * |
3061 gaim_utf8_ncr_decode(const char *in) | 3088 gaim_utf8_ncr_decode(const char *in) |
3062 { | 3089 { |
3063 GString *out = g_string_new(""); | 3090 GString *out = g_string_new(""); |
3064 int i; | 3091 int i; |