# HG changeset patch # User maiku@pidgin.im # Date 1251444398 0 # Node ID 776540f773946d1a9590f508c6e470f3bfd40c04 # Parent f628e98e6dff9918068f2ccd9aade34756138ef6# Parent 6b018d1efc5ce4ce7159212271edc9e3bc03b301 merge of '3dc30db9c8f1da2d0c574163fe37658d8b26f95d' and '8e3f07ee41e0a06ef01e353e2162d8fcf3d6bb33' diff -r f628e98e6dff -r 776540f77394 libpurple/util.c --- a/libpurple/util.c Fri Aug 28 07:25:43 2009 +0000 +++ b/libpurple/util.c Fri Aug 28 07:26:38 2009 +0000 @@ -4652,25 +4652,25 @@ purple_utf8_strip_unprintables(const gchar *str) { gchar *workstr, *iter; + const gchar *bad; if (str == NULL) /* Act like g_strdup */ return NULL; - g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); + if (!g_utf8_validate(str, -1, &bad)) { + purple_debug_error("util", "purple_utf8_strip_unprintables(%s) failed; " + "first bad character was %02x (%c)\n", + str, *bad, *bad); + g_return_val_if_reached(NULL); + } workstr = iter = g_new(gchar, strlen(str) + 1); - while (*str) { - gunichar c = g_utf8_get_char(str); - const gchar *next = g_utf8_next_char(str); - size_t len = next - str; - - if (g_unichar_isprint(c)) { - memcpy(iter, str, len); - iter += len; + for ( ; *str; ++str) { + if (*str >= 0x20 || *str == '\t' || *str == '\n' || *str == '\r') { + *iter = *str; + ++iter; } - - str = next; } /* nul-terminate the new string */ diff -r f628e98e6dff -r 776540f77394 libpurple/util.h --- a/libpurple/util.h Fri Aug 28 07:25:43 2009 +0000 +++ b/libpurple/util.h Fri Aug 28 07:26:38 2009 +0000 @@ -1286,16 +1286,14 @@ /** * Removes unprintable characters from a UTF-8 string. These characters * (in particular low-ASCII characters) are invalid in XML 1.0 and thus - * are not allowed in XMPP and are rejected by libxml2 by default. This - * function uses g_unichar_isprint to determine what characters should - * be stripped. The returned string must be freed by the caller. + * are not allowed in XMPP and are rejected by libxml2 by default. + * + * The returned string must be freed by the caller. * * @param str A valid UTF-8 string. * * @return A newly allocated UTF-8 string without the unprintable characters. * @since 2.6.0 - * - * @see g_unichar_isprint */ gchar *purple_utf8_strip_unprintables(const gchar *str);