Mercurial > pidgin
diff libpurple/protocols/irc/parse.c @ 20869:2a6ef74f5a4e
merge of '3efb5d625e5a73423be8be77a6baeed0b65f7e55'
and 'c848ad4c20988b5dac9ac164455d3ba2d7307230'
| author | Sadrul Habib Chowdhury <imadil@gmail.com> |
|---|---|
| date | Wed, 10 Oct 2007 01:06:16 +0000 |
| parents | c6232f341ea5 |
| children | 88aa557b997f |
line wrap: on
line diff
--- a/libpurple/protocols/irc/parse.c Wed Oct 10 01:01:21 2007 +0000 +++ b/libpurple/protocols/irc/parse.c Wed Oct 10 01:06:16 2007 +0000 @@ -281,6 +281,61 @@ return purple_utf8_salvage(string); } +/* This function is shamelessly stolen from glib--it is an old version of the + * private function append_escaped_text, used by g_markup_escape_text, whose + * behavior changed in glib 2.12. */ +static void irc_append_escaped_text(GString *str, const char *text, gssize length) +{ + const char *p = text; + const char *end = text + length; + const char *next = NULL; + + while(p != end) { + next = g_utf8_next_char(p); + + switch(*p) { + case '&': + g_string_append(str, "&"); + break; + case '<': + g_string_append(str, "<"); + break; + case '>': + g_string_append(str, ">"); + break; + case '\'': + g_string_append(str, "'"); + break; + case '"': + g_string_append(str, """); + break; + default: + g_string_append_len(str, p, next - p); + break; + } + + p = next; + } +} + +/* This function is shamelessly stolen from glib--it is an old version of the + * function g_markup_escape_text, whose behavior changed in glib 2.12. */ +char *irc_escape_privmsg(const char *text, gssize length) +{ + GString *str; + + g_return_val_if_fail(text != NULL, NULL); + + if(length < 0) + length = strlen(text); + + str = g_string_sized_new(length); + + irc_append_escaped_text(str, text, length); + + return g_string_free(str, FALSE); +} + /* XXX tag closings are not necessarily correctly nested here! If we * get a ^O or reach the end of the string and there are open * tags, they are closed in a fixed order ... this means, for
