diff libpurple/protocols/irc/parse.c @ 20325:4ff4e3aeab27

applied changes from 6c08c628ee64e16c824829c25befc0ca09338f9d through 6b57335241f2c9a501643280407bdc3374100dee
author Luke Schierer <lschiere@pidgin.im>
date Fri, 19 Oct 2007 17:59:00 +0000
parents 44b4e8bd759b
children 88aa557b997f 271d154bbb91
line wrap: on
line diff
--- a/libpurple/protocols/irc/parse.c	Fri Oct 19 17:58:04 2007 +0000
+++ b/libpurple/protocols/irc/parse.c	Fri Oct 19 17:59:00 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, "&amp;");
+				break;
+			case '<':
+				g_string_append(str, "&lt;");
+				break;
+			case '>':
+				g_string_append(str, "&gt;");
+				break;
+			case '\'':
+				g_string_append(str, "&apos;");
+				break;
+			case '"':
+				g_string_append(str, "&quot;");
+				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