| 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 *_my_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 |
| 109 ret = g_convert(str, len, to_charset, from_charset, &byte_read, &byte_write, &error); |
109 ret = g_convert(str, len, to_charset, from_charset, &byte_read, &byte_write, &error); |
| 110 |
110 |
| 111 if (error == NULL) { |
111 if (error == NULL) { |
| 112 return ret; /* conversion is OK */ |
112 return ret; /* conversion is OK */ |
| 113 } |
113 } |
| 114 |
114 |
| 115 /* conversion error */ |
115 /* conversion error */ |
| 116 purple_debug_error("QQ_CONVERT", "%s\n", error->message); |
116 purple_debug_error("QQ_CONVERT", "%s\n", error->message); |
| 117 |
117 |
| 118 qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ_CONVERT", |
118 qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ_CONVERT", |
| 119 (guint8 *) str, (len == -1) ? strlen(str) : len, |
119 (guint8 *) str, (len == -1) ? strlen(str) : len, |
| 125 |
125 |
| 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 convert_as_pascal_string(guint8 *data, gchar **ret, const gchar *from_charset) |
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 |
| 220 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset) |
220 gchar *qq_to_utf8(const gchar *str, const gchar *from_charset) |
| 221 { |
221 { |
| 222 return _my_convert(str, -1, UTF8, from_charset); |
222 return _my_convert(str, -1, UTF8, from_charset); |
| 223 } |
223 } |
| 224 |
224 |
| 225 /* QQ uses binary code for smiley, while purple uses strings. |
225 /* QQ uses binary code for smiley, while purple uses strings. |
| 226 * There is a mapping relation between these two. */ |
226 * There is a mapping relation between these two. */ |
| 227 gchar *qq_smiley_to_purple(gchar *text) |
227 gchar *qq_smiley_to_purple(gchar *text) |
| 228 { |
228 { |
| 229 gint index; |
229 gint index; |
| 230 gchar qq_smiley, *cur_seg, **segments, *ret; |
230 gchar qq_smiley, *cur_seg, **segments, *ret; |