Mercurial > pidgin
comparison libpurple/protocols/qq/char_conv.c @ 24145:ec3f7d3e0445
2008.10.04 - lonicerae <lonicerae(at)gmail.com>
* fixed a bug in qq_base.c
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Wed, 22 Oct 2008 14:49:38 +0000 |
parents | a95c7e71064c |
children | ce94189f15ad |
comparison
equal
deleted
inserted
replaced
24144:a95c7e71064c | 24145:ec3f7d3e0445 |
---|---|
96 { | 96 { |
97 return (font_attr & 0x80) ? TRUE : FALSE; | 97 return (font_attr & 0x80) ? TRUE : FALSE; |
98 } | 98 } |
99 | 99 |
100 /* convert a string from from_charset to to_charset, using g_convert */ | 100 /* convert a string from from_charset to to_charset, using g_convert */ |
101 static gchar *do_convert(const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset) | 101 static gchar *_my_convert(const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset) |
102 { | 102 { |
103 GError *error = NULL; | 103 GError *error = NULL; |
104 gchar *ret; | 104 gchar *ret; |
105 gsize byte_read, byte_write; | 105 gsize byte_read, byte_write; |
106 | 106 |
126 /* | 126 /* |
127 * take the input as a pascal string and return a converted c-string in UTF-8 | 127 * take the input as a pascal string and return a converted c-string in UTF-8 |
128 * returns the number of bytes read, return -1 if fatal error | 128 * returns the number of bytes read, return -1 if fatal error |
129 * the converted UTF-8 will be saved in ret | 129 * the converted UTF-8 will be saved in ret |
130 */ | 130 */ |
131 gint qq_get_vstr(gchar **ret, const gchar *from_charset, guint8 *data) | 131 gint convert_as_pascal_string(guint8 *data, gchar **ret, const gchar *from_charset) |
132 { | 132 { |
133 guint8 len; | 133 guint8 len; |
134 | 134 |
135 g_return_val_if_fail(data != NULL && from_charset != NULL, -1); | 135 g_return_val_if_fail(data != NULL && from_charset != NULL, -1); |
136 | 136 |
137 len = data[0]; | 137 len = data[0]; |
138 if (len == 0) { | 138 *ret = _my_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset); |
139 *ret = g_strdup(""); | |
140 return 1; | |
141 } | |
142 *ret = do_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset); | |
143 | 139 |
144 return len + 1; | 140 return len + 1; |
145 } | 141 } |
146 | 142 |
147 /* convert QQ formatted msg to Purple formatted msg (and UTF-8) */ | 143 /* convert QQ formatted msg to Purple formatted msg (and UTF-8) */ |
216 g_string_free(encoded, FALSE); | 212 g_string_free(encoded, FALSE); |
217 | 213 |
218 return ret; | 214 return ret; |
219 } | 215 } |
220 | 216 |
221 /* two convenience methods, using do_convert */ | 217 /* two convenience methods, using _my_convert */ |
222 gchar *utf8_to_qq(const gchar *str, const gchar *to_charset) | 218 gchar *utf8_to_qq(const gchar *str, const gchar *to_charset) |
223 { | 219 { |
224 return do_convert(str, -1, to_charset, UTF8); | 220 return _my_convert(str, -1, to_charset, UTF8); |
225 } | 221 } |
226 | 222 |
227 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset) | 223 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset) |
228 { | 224 { |
229 return do_convert(str, -1, UTF8, from_charset); | 225 return _my_convert(str, -1, UTF8, from_charset); |
230 } | 226 } |
231 | 227 |
232 /* QQ uses binary code for smiley, while purple uses strings. | 228 /* QQ uses binary code for smiley, while purple uses strings. |
233 * There is a mapping relation between these two. */ | 229 * There is a mapping relation between these two. */ |
234 gchar *qq_smiley_to_purple(gchar *text) | 230 gchar *qq_smiley_to_purple(gchar *text) |