diff src/util.c @ 12813:547c199072c8

[gaim-migrate @ 15161] - fixes to sametime administrative notification message dialog to make them a little less obscure as to what the heck they are - added an extra step to the sametime connection login between authenticating and starting services - fix to outgoing encoding of html formatted messages in sametime to use NCR encoding - addition of gaim_utf8_ncr_encode to util.h - fix of minor possible (unlikely) memleak in gaim_utf8_ncr_decode committer: Tailor Script <tailor@pidgin.im>
author Christopher O'Brien <siege@pidgin.im>
date Wed, 11 Jan 2006 03:07:01 +0000
parents 26b31b4c43a2
children bad785371fa5
line wrap: on
line diff
--- a/src/util.c	Wed Jan 11 01:13:20 2006 +0000
+++ b/src/util.c	Wed Jan 11 03:07:01 2006 +0000
@@ -3450,15 +3450,43 @@
 	return g_string_free(workstr, FALSE);
 }
 
+
+char *
+gaim_utf8_ncr_encode(const char *in)
+{
+	GString *out;
+
+	g_return_val_if_fail(in != NULL, NULL);
+	g_return_val_if_fail(g_utf8_validate(in, -1, NULL), NULL);
+
+	out = g_string_new("");
+
+	for(; *in; in = g_utf8_next_char(in)) {
+		gunichar wc = g_utf8_get_char(in);
+		
+		if(wc >= 0x80) { /* super simple check. hopefully not too wrong. */
+			g_string_append_printf(out, "&#%u;", (guint32) wc);
+		} else {
+			g_string_append_unichar(out, wc);
+		}
+	}
+
+	return g_string_free(out, FALSE);
+}
+
+
 char *
 gaim_utf8_ncr_decode(const char *in)
 {
-	GString *out = g_string_new("");
+	GString *out;
 	int i;
 
 	g_return_val_if_fail(in != NULL, NULL);
 	g_return_val_if_fail(g_utf8_validate(in, -1, NULL), NULL);
 
+	out = g_string_new("");
+
+	/** @todo doesn't this break with hex formats? */
 	for (i = 0; in[i]; i += 1) {
 		gboolean ncr_found_p = FALSE;
 		if (in[i] == '&' && in[i + 1] == '#' && isdigit(in[i + 2])) {