changeset 7287:3a41c3f80228

[gaim-migrate @ 7868] more fun html entity stuff committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 17 Oct 2003 05:58:16 +0000
parents 0b961945c8ae
children ff9127038a5a
files src/gtkimhtml.c src/util.c
diffstat 2 files changed, 51 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkimhtml.c	Thu Oct 16 22:22:18 2003 +0000
+++ b/src/gtkimhtml.c	Fri Oct 17 05:58:16 2003 +0000
@@ -757,7 +757,7 @@
 			  gchar       **replace,
 			  gint        *length)
 {
-	static char buf[6];
+	static char buf[7];
 	g_return_val_if_fail (string != NULL, FALSE);
 	g_return_val_if_fail (replace != NULL, FALSE);
 	g_return_val_if_fail (length != NULL, FALSE);
@@ -789,9 +789,11 @@
 	} else if (*(string + 1) == '#') {
 		guint pound = 0;
 		if ((sscanf (string, "&#%u;", &pound) == 1) && pound != 0) {
+			int buflen;
 			if (*(string + 3 + (gint)log10 (pound)) != ';')
 				return FALSE;
-			g_unichar_to_utf8((gunichar)pound, buf);
+			buflen = g_unichar_to_utf8((gunichar)pound, buf);
+			buf[buflen] = '\0';
 			*replace = buf;
 			*length = 2;
 			while (isdigit ((gint) string [*length])) (*length)++;
--- a/src/util.c	Thu Oct 16 22:22:18 2003 +0000
+++ b/src/util.c	Fri Oct 17 05:58:16 2003 +0000
@@ -790,6 +790,53 @@
 				plain = g_string_append_c(plain, '<');
 				c++;
 			}
+		} else if(*c == '&') {
+			char buf[7];
+			char *pln;
+			int len = 1;
+			guint pound;
+			if(!g_ascii_strncasecmp(c, "&amp;", 5)) {
+				pln = "&";
+				len = 5;
+			} else if(!g_ascii_strncasecmp(c, "&lt;", 4)) {
+				pln = "<";
+				len = 4;
+			} else if(!g_ascii_strncasecmp(c, "&gt;", 4)) {
+				pln = ">";
+				len = 4;
+			} else if(!g_ascii_strncasecmp(c, "&nbsp;", 6)) {
+				pln = " ";
+				len = 6;
+			} else if(!g_ascii_strncasecmp(c, "&copy;", 6)) {
+				pln = "©";
+				len = 6;
+			} else if(!g_ascii_strncasecmp(c, "&quot;", 6)) {
+				pln = "\"";
+				len = 6;
+			} else if(!g_ascii_strncasecmp(c, "&reg;", 5)) {
+				pln = "®";
+				len = 5;
+			} else if(!g_ascii_strncasecmp(c, "&apos;", 6)) {
+				pln = "\'";
+				len = 6;
+			} else if(*(c+1) == '#' && (sscanf(c, "&#%u;", &pound) == 1) &&
+					pound != 0 && *(c+3+(gint)log10(pound)) == ';') {
+				int buflen = g_unichar_to_utf8((gunichar)pound, buf);
+				buf[buflen] = '\0';
+				pln = buf;
+
+
+				len = 2;
+				while(isdigit((gint) c [len])) len++;
+				if(c [len] == ';') len++;
+			} else {
+				len = 1;
+				g_snprintf(buf, sizeof(buf), "%c", *c);
+				pln = buf;
+			}
+			xhtml = g_string_append_len(xhtml, c, len);
+			plain = g_string_append(plain, pln);
+			c += len;
 		} else {
 			xhtml = g_string_append_c(xhtml, *c);
 			plain = g_string_append_c(plain, *c);