libpurple/protocols/oscar/encoding.c

branch
soc.2010.icq-tlc
changeset 30669
e669bab0688e
parent 30667
68619fe61c8b
child 30675
0898ace5d43c
equal deleted inserted replaced
30668:54e684b2d963 30669:e669bab0688e
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
19 */ 19 */
20 20
21 #include "encoding.h" 21 #include "encoding.h"
22 22
23 guint16
24 oscar_charset_check(const char *utf8)
25 {
26 while (*utf8++)
27 {
28 if ((unsigned char)(*utf8) > 0x7f) {
29 /* not ASCII! */
30 return AIM_CHARSET_UNICODE;
31 }
32 }
33 return AIM_CHARSET_ASCII;
34 }
35
36 static gchar * 23 static gchar *
37 encoding_extract(const char *encoding) 24 encoding_extract(const char *encoding)
38 { 25 {
39 char *begin, *end; 26 char *begin, *end;
40 27
212 } 199 }
213 200
214 return ret; 201 return ret;
215 } 202 }
216 203
217 gchar * 204 static guint16
218 oscar_convert_to_best_encoding(const gchar *msg, gsize *result_len, guint16 *charset, gchar **charsetstr) 205 get_simplest_charset(const char *utf8)
219 { 206 {
220 guint16 msg_charset = oscar_charset_check(msg); 207 while (*utf8++)
208 {
209 if ((unsigned char)(*utf8) > 0x7f) {
210 /* not ASCII! */
211 return AIM_CHARSET_UNICODE;
212 }
213 }
214 return AIM_CHARSET_ASCII;
215 }
216
217 gchar *
218 oscar_encode_im(const gchar *msg, gsize *result_len, guint16 *charset, gchar **charsetstr)
219 {
220 guint16 msg_charset = get_simplest_charset(msg);
221 if (charset != NULL) { 221 if (charset != NULL) {
222 *charset = msg_charset; 222 *charset = msg_charset;
223 } 223 }
224 if (charsetstr != NULL) { 224 if (charsetstr != NULL) {
225 *charsetstr = msg_charset == AIM_CHARSET_ASCII ? "us-ascii" : "unicode-2-0"; 225 *charsetstr = msg_charset == AIM_CHARSET_ASCII ? "us-ascii" : "unicode-2-0";

mercurial