Mercurial > pidgin
comparison libpurple/util.c @ 27019:bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
We will no longer send messages which contain entities considered invalid
in XML 1.0 (i.e.  and other ASCII control characters). Closes #5768.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 03 Jun 2009 19:09:16 +0000 |
parents | af4a4ebc6441 |
children | c59918579c3a |
comparison
equal
deleted
inserted
replaced
27016:22bcf150f6c7 | 27019:bf9db4c67679 |
---|---|
4422 } while (*str != '\0'); | 4422 } while (*str != '\0'); |
4423 | 4423 |
4424 return g_string_free(workstr, FALSE); | 4424 return g_string_free(workstr, FALSE); |
4425 } | 4425 } |
4426 | 4426 |
4427 gchar * | |
4428 purple_utf8_strip_unprintables(const gchar *str) | |
4429 { | |
4430 gchar *workstr, *iter; | |
4431 | |
4432 g_return_val_if_fail(str != NULL, NULL); | |
4433 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL); | |
4434 | |
4435 workstr = iter = g_new(gchar, strlen(str) + 1); | |
4436 while (*str) { | |
4437 gunichar c = g_utf8_get_char(str); | |
4438 const gchar *next = g_utf8_next_char(str); | |
4439 size_t len = next - str; | |
4440 | |
4441 if (g_unichar_isprint(c)) { | |
4442 memcpy(iter, str, len); | |
4443 iter += len; | |
4444 } | |
4445 | |
4446 str = next; | |
4447 } | |
4448 | |
4449 /* nul-terminate the new string */ | |
4450 *iter = '\0'; | |
4451 | |
4452 return workstr; | |
4453 } | |
4454 | |
4427 /* | 4455 /* |
4428 * This function is copied from g_strerror() but changed to use | 4456 * This function is copied from g_strerror() but changed to use |
4429 * gai_strerror(). | 4457 * gai_strerror(). |
4430 */ | 4458 */ |
4431 G_CONST_RETURN gchar * | 4459 G_CONST_RETURN gchar * |