~prateek.karandikar/ubuntu/precise/pidgin/add_quicklist

« back to all changes in this revision

Viewing changes to libpurple/protocols/qq/char_conv.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-11-05 19:44:21 UTC
  • mfrom: (62.1.1 maverick-security) (2.3.12 sid)
  • Revision ID: james.westby@ubuntu.com-20101105194421-8r8o4pzw2m5j4hiy
Tags: 1:2.7.5-1ubuntu1
Resync on Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
/* convert a string from from_charset to to_charset, using g_convert */
39
39
/* Warning: do not return NULL */
40
 
static gchar *do_convert(const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset)
 
40
static gchar *do_convert(const gchar *str, gssize len, guint8 *out_len, const gchar *to_charset, const gchar *from_charset)
41
41
{
42
42
        GError *error = NULL;
43
43
        gchar *ret;
48
48
        ret = g_convert(str, len, to_charset, from_charset, &byte_read, &byte_write, &error);
49
49
 
50
50
        if (error == NULL) {
 
51
                if (out_len)
 
52
                        *out_len = byte_write;
51
53
                return ret;     /* convert is OK */
52
54
        }
53
55
 
67
69
 */
68
70
gint qq_get_vstr(gchar **ret, const gchar *from_charset, guint8 *data)
69
71
{
70
 
        guint8 len;
 
72
        gssize len;
 
73
        guint8 out_len;
71
74
 
72
75
        g_return_val_if_fail(data != NULL && from_charset != NULL, -1);
73
76
 
76
79
                *ret = g_strdup("");
77
80
                return 1;
78
81
        }
79
 
        *ret = do_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset);
 
82
        *ret = do_convert((gchar *) (data + 1), len, &out_len, UTF8, from_charset);
80
83
 
81
 
        return len + 1;
 
84
        return out_len + 1;
82
85
}
83
86
 
84
87
gint qq_put_vstr(guint8 *buf, const gchar *str_utf8, const gchar *to_charset)
86
89
        gchar *str;
87
90
        guint8 len;
88
91
 
89
 
        if (str_utf8 == NULL || (len = strlen(str_utf8)) == 0) {
 
92
        if (str_utf8 == NULL || str_utf8[0] == '\0') {
90
93
                buf[0] = 0;
91
94
                return 1;
92
95
        }
93
 
        str = do_convert(str_utf8, -1, to_charset, UTF8);
94
 
        len = strlen(str_utf8);
 
96
        str = do_convert(str_utf8, -1, &len, to_charset, UTF8);
95
97
        buf[0] = len;
96
98
        if (len > 0) {
97
99
                memcpy(buf + 1, str, len);
102
104
/* Warning: do not return NULL */
103
105
gchar *utf8_to_qq(const gchar *str, const gchar *to_charset)
104
106
{
105
 
        return do_convert(str, -1, to_charset, UTF8);
 
107
        return do_convert(str, -1, NULL, to_charset, UTF8);
106
108
}
107
109
 
108
110
/* Warning: do not return NULL */
109
111
gchar *qq_to_utf8(const gchar *str, const gchar *from_charset)
110
112
{
111
 
        return do_convert(str, -1, UTF8, from_charset);
 
113
        return do_convert(str, -1, NULL, UTF8, from_charset);
112
114
}
113
115