comparison src/protocols/yahoo/util.c @ 7827:ee32e030c9be

[gaim-migrate @ 8479] marv asserts that these character set conversions are more correct than the previous yahoo conversions, which assumed that pretty much everything was UTF-8. I believe him. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Wed, 10 Dec 2003 16:48:23 +0000
parents f80e23e66de0
children 1556970088d4
comparison
equal deleted inserted replaced
7826:5ba07997ade3 7827:ee32e030c9be
24 #include "config.h" 24 #include "config.h"
25 #endif 25 #endif
26 26
27 #include "prpl.h" 27 #include "prpl.h"
28 #include "debug.h" 28 #include "debug.h"
29 #include "yahoo.h"
29 30
30 #include <string.h> 31 #include <string.h>
32
33 /**
34 * Encode some text to send to the yahoo server.
35 *
36 * @param gc The connection handle.
37 * @param str The null terminated utf8 string to encode.
38 * @param utf8 If not @c NULL, whether utf8 is okay or not.
39 * Even if it is okay, we may not use it. If we
40 * used it, we set this to @c TRUE, else to
41 * @c FALSE. If @c NULL, false is assumed, and
42 * it is not dereferenced.
43 * @return The g_malloced string in the appropriate encoding.
44 */
45 char *yahoo_string_encode(GaimConnection *gc, const char *str, gboolean *utf8)
46 {
47 char *ret;
48 char *to_codeset;
49
50 if (utf8 && *utf8) /* FIXME: maybe don't use utf8 if it'll fit in latin1 */
51 return g_strdup(str);
52
53 to_codeset = "ISO-8859-1";
54
55 ret = g_convert_with_fallback(str, strlen(str), to_codeset, "UTF-8", NULL, NULL, NULL, NULL);
56 if (ret)
57 return ret;
58 else
59 return g_strdup("");
60 }
61
62 /**
63 * Decode some text received from the server.
64 *
65 * @param gc The gc handle.
66 * @param str The null terminated string to decode.
67 * @param utf8 Did the server tell us it was supposed to be utf8?
68 * @return The decoded, utf-8 string, which must be g_free()'d.
69 */
70 char *yahoo_string_decode(GaimConnection *gc, const char *str, gboolean utf8)
71 {
72 char *ret;
73 char *from_codeset;
74
75 if (utf8) {
76 if (g_utf8_validate(str, -1, NULL))
77 return g_strdup(str);
78 }
79
80 from_codeset = "ISO-8859-1";
81
82 ret = g_convert_with_fallback(str, strlen(str), "UTF-8", from_codeset, NULL, NULL, NULL, NULL);
83
84 if (ret)
85 return ret;
86 else
87 return g_strdup("");
88 }
89
31 90
32 91
33 /* 92 /*
34 * I found these on some website but i don't know that they actually 93 * I found these on some website but i don't know that they actually
35 * work (or are supposed to work). I didn't impliment them yet. 94 * work (or are supposed to work). I didn't impliment them yet.