changeset 29359:05d727f76ca9

Combine the three purple_unescape_text()s into one. purple_unescape_text is like purple_unescape_html, except better. I say better, but really, what I should say is "libxml2 BLOWS", because of its crazy way of leaving attributes "unescaped".
author Paul Aurich <paul@darkrain42.org>
date Wed, 10 Feb 2010 04:05:50 +0000
parents 93afc09a5e18
children 5dec9d90fb51
files ChangeLog.API libpurple/protocols/bonjour/parser.c libpurple/protocols/jabber/parser.c libpurple/util.c libpurple/util.h libpurple/xmlnode.c
diffstat 6 files changed, 50 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Wed Feb 10 04:01:16 2010 +0000
+++ b/ChangeLog.API	Wed Feb 10 04:05:50 2010 +0000
@@ -13,13 +13,14 @@
 		* purple_media_manager_set_backend_type
 		* purple_network_get_all_local_system_ips
 		* purple_prpl_got_media_caps
+		* purple_unescape_text
 		* purple_uuid_random
 		* media_caps to the PurpleBuddy struct
 		* buddy-caps-changed blist signal
 		* ui-caps-changed media manager signal
 		* sent-attention conversation signal
 		* got-attention conversation signal
-	
+
 	Pidgin:
 		Added:
 		* pidgin_dialogs_buildinfo (should not be used by anything but Pidgin)
--- a/libpurple/protocols/bonjour/parser.c	Wed Feb 10 04:01:16 2010 +0000
+++ b/libpurple/protocols/bonjour/parser.c	Wed Feb 10 04:05:50 2010 +0000
@@ -49,31 +49,6 @@
 	return FALSE;
 }
 
-static char *purple_unescape_text(const char *in)
-{
-    GString *ret;
-    const char *c = in;
-
-    if (in == NULL)
-        return NULL;
-
-    ret = g_string_new("");
-    while (*c) {
-        int len;
-        const char *ent;
-
-        if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
-            g_string_append(ret, ent);
-            c += len;
-        } else {
-            g_string_append_c(ret, *c);
-            c++;
-        }
-    }
-
-    return g_string_free(ret, FALSE);
-}
-
 static void
 bonjour_parser_element_start_libxml(void *user_data,
 				   const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace,
--- a/libpurple/protocols/jabber/parser.c	Wed Feb 10 04:01:16 2010 +0000
+++ b/libpurple/protocols/jabber/parser.c	Wed Feb 10 04:05:50 2010 +0000
@@ -31,31 +31,6 @@
 #include "util.h"
 #include "xmlnode.h"
 
-static char *purple_unescape_text(const char *in)
-{
-    GString *ret;
-    const char *c = in;
-
-    if (in == NULL)
-        return NULL;
-
-    ret = g_string_new("");
-    while (*c) {
-        int len;
-        const char *ent;
-
-        if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
-            g_string_append(ret, ent);
-            c += len;
-        } else {
-            g_string_append_c(ret, *c);
-            c++;
-        }
-    }
-
-    return g_string_free(ret, FALSE);
-}
-
 static void
 jabber_parser_element_start_libxml(void *user_data,
 				   const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace,
--- a/libpurple/util.c	Wed Feb 10 04:01:16 2010 +0000
+++ b/libpurple/util.c	Wed Feb 10 04:05:50 2010 +0000
@@ -2367,6 +2367,31 @@
 	return g_string_free(ret, FALSE);
 }
 
+char *purple_unescape_text(const char *in)
+{
+    GString *ret;
+    const char *c = in;
+
+    if (in == NULL)
+        return NULL;
+
+    ret = g_string_new("");
+    while (*c) {
+        int len;
+        const char *ent;
+
+        if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
+            g_string_append(ret, ent);
+            c += len;
+        } else {
+            g_string_append_c(ret, *c);
+            c++;
+        }
+    }
+
+    return g_string_free(ret, FALSE);
+}
+
 char *purple_unescape_html(const char *html)
 {
 	GString *ret;
--- a/libpurple/util.h	Wed Feb 10 04:01:16 2010 +0000
+++ b/libpurple/util.h	Wed Feb 10 04:05:50 2010 +0000
@@ -516,18 +516,35 @@
 char *purple_markup_linkify(const char *str);
 
 /**
- * Unescapes HTML entities to their literal characters. Also translates
- * "<br>" to "\n".
- * For example "&amp;" is replaced by '&' and so on.
+ * Unescapes HTML entities to their literal characters in the text.
+ * For example "&amp;" is replaced by '&' and so on.  Also converts
+ * numerical entities (e.g. "&#38;" is also '&').
+ *
+ * This function currently supports the following named entities:
+ *     "&amp;", "&lt;", "&gt;", "&copy;", "&quot;", "&reg;", "&apos;"
+ *
+ * purple_unescape_html() is similar, but also converts "<br>" into "\n".
+ *
+ * @param text The string in which to unescape any HTML entities
  *
- * The following named entities are supported (in addition to numerical
- * entities):
- *    "&amp;", "&lt;", "&gt;", "&copy;", "&quot;", "&reg;", "&apos;"
+ * @return The text with HTML entities literalized.  You must g_free
+ *         this string when finished with it.
+ *
+ * @see purple_unescape_html()
+ * @since 2.7.0
+ */
+char *purple_unescape_text(const char *text);
+
+/**
+ * Unescapes HTML entities to their literal characters and converts
+ * "<br>" to "\n".  See purple_unescape_text() for more details.
  *
  * @param html The string in which to unescape any HTML entities
  *
  * @return The text with HTML entities literalized.  You must g_free
  *         this string when finished with it.
+ *
+ * @see purple_unescape_text()
  */
 char *purple_unescape_html(const char *html);
 
--- a/libpurple/xmlnode.c	Wed Feb 10 04:01:16 2010 +0000
+++ b/libpurple/xmlnode.c	Wed Feb 10 04:05:50 2010 +0000
@@ -545,31 +545,6 @@
 	return xml_with_declaration;
 }
 
-static char *purple_unescape_text(const char *in)
-{
-    GString *ret;
-    const char *c = in;
-
-    if (in == NULL)
-        return NULL;
-
-    ret = g_string_new("");
-    while (*c) {
-        int len;
-        const char *ent;
-
-        if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
-            g_string_append(ret, ent);
-            c += len;
-        } else {
-            g_string_append_c(ret, *c);
-            c++;
-        }
-    }
-
-    return g_string_free(ret, FALSE);
-}
-
 struct _xmlnode_parser_data {
 	xmlnode *current;
 	gboolean error;