pidgin: 31251ef1: Correct me if I'm wrong, but why would t...
qulogic at pidgin.im
qulogic at pidgin.im
Sat Aug 14 02:25:47 EDT 2010
----------------------------------------------------------------------
Revision: 31251ef18953a338888e0e80b1492a59cd564154
Parent: 6ae822f48b2ae071757c1243f097973203c6f07f
Author: qulogic at pidgin.im
Date: 08/13/10 23:55:19
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/31251ef18953a338888e0e80b1492a59cd564154
Changelog:
Correct me if I'm wrong, but why would the length be in UTF8, when
the string is not?
Changes against parent 6ae822f48b2ae071757c1243f097973203c6f07f
patched libpurple/protocols/qq/char_conv.c
-------------- next part --------------
============================================================
--- libpurple/protocols/qq/char_conv.c d9ceaac50ebda9a6adacf8da27d76ed0847d90ba
+++ libpurple/protocols/qq/char_conv.c a35f813a6ca5562cedb6bea32cd17c83fb4152bd
@@ -37,7 +37,7 @@
/* convert a string from from_charset to to_charset, using g_convert */
/* Warning: do not return NULL */
-static gchar *do_convert(const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset)
+static gchar *do_convert(const gchar *str, gssize len, guint8 *out_len, const gchar *to_charset, const gchar *from_charset)
{
GError *error = NULL;
gchar *ret;
@@ -48,6 +48,8 @@ static gchar *do_convert(const gchar *st
ret = g_convert(str, len, to_charset, from_charset, &byte_read, &byte_write, &error);
if (error == NULL) {
+ if (out_len)
+ *out_len = byte_write;
return ret; /* convert is OK */
}
@@ -67,7 +69,8 @@ gint qq_get_vstr(gchar **ret, const gcha
*/
gint qq_get_vstr(gchar **ret, const gchar *from_charset, guint8 *data)
{
- guint8 len;
+ gssize len;
+ guint8 out_len;
g_return_val_if_fail(data != NULL && from_charset != NULL, -1);
@@ -76,9 +79,9 @@ gint qq_get_vstr(gchar **ret, const gcha
*ret = g_strdup("");
return 1;
}
- *ret = do_convert((gchar *) (data + 1), (gssize) len, UTF8, from_charset);
+ *ret = do_convert((gchar *) (data + 1), len, &out_len, UTF8, from_charset);
- return len + 1;
+ return out_len + 1;
}
gint qq_put_vstr(guint8 *buf, const gchar *str_utf8, const gchar *to_charset)
@@ -86,12 +89,11 @@ gint qq_put_vstr(guint8 *buf, const gcha
gchar *str;
guint8 len;
- if (str_utf8 == NULL || (len = strlen(str_utf8)) == 0) {
+ if (str_utf8 == NULL || str_utf8[0] == '\0') {
buf[0] = 0;
return 1;
}
- str = do_convert(str_utf8, -1, to_charset, UTF8);
- len = strlen(str_utf8);
+ str = do_convert(str_utf8, -1, &len, to_charset, UTF8);
buf[0] = len;
if (len > 0) {
memcpy(buf + 1, str, len);
@@ -102,12 +104,12 @@ gchar *utf8_to_qq(const gchar *str, cons
/* Warning: do not return NULL */
gchar *utf8_to_qq(const gchar *str, const gchar *to_charset)
{
- return do_convert(str, -1, to_charset, UTF8);
+ return do_convert(str, -1, NULL, to_charset, UTF8);
}
/* Warning: do not return NULL */
gchar *qq_to_utf8(const gchar *str, const gchar *from_charset)
{
- return do_convert(str, -1, UTF8, from_charset);
+ return do_convert(str, -1, NULL, UTF8, from_charset);
}
More information about the Commits
mailing list