Mercurial > pidgin
comparison libpurple/util.c @ 27393:57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
in oscar. This function is identical to glib's g_markup_escape_text() except that
it does not replace ' with '
' is not a valid HTML entity in HTML 4, and IE7 displays it as the
raw characters and not as an apostrophe. gtk of course displays it as
an apostrophe, but gtk seems to have no problems with unescaped apostrophes
I really don't know why g_markup_escape_text() escapes this character.
So this change should not affect Pidgin at all, and it should help any
user of libpurple who displays our HTML in IE (or possibly other web
browsers--I'm not sure how webkit handles ')
Are people ok with this change? We should probably change a lot of other
places to use this function instead of the glib one. Basically anything
that converts text to html should use this. I think anything that escapes
XML should continue using g_markup_escape_text().
And entry_key_pressed() in Finch can be changed to use this instead of
g_markup_escape_text() and purple_strreplace()
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 06 Jul 2009 23:46:56 +0000 |
parents | 6275df9d2d62 |
children | 52298a298260 |
comparison
equal
deleted
inserted
replaced
27392:d7ac2ad0db5a | 27393:57fdb7853fc7 |
---|---|
939 } | 939 } |
940 | 940 |
941 /************************************************************************** | 941 /************************************************************************** |
942 * Markup Functions | 942 * Markup Functions |
943 **************************************************************************/ | 943 **************************************************************************/ |
944 | |
945 /* | |
946 * This function is stolen from glib's gmarkup.c and modified to not | |
947 * replace ' with ' | |
948 */ | |
949 static void append_escaped_text(GString *str, | |
950 const gchar *text, gssize length) | |
951 { | |
952 const gchar *p; | |
953 const gchar *end; | |
954 gunichar c; | |
955 | |
956 p = text; | |
957 end = text + length; | |
958 | |
959 while (p != end) | |
960 { | |
961 const gchar *next; | |
962 next = g_utf8_next_char (p); | |
963 | |
964 switch (*p) | |
965 { | |
966 case '&': | |
967 g_string_append (str, "&"); | |
968 break; | |
969 | |
970 case '<': | |
971 g_string_append (str, "<"); | |
972 break; | |
973 | |
974 case '>': | |
975 g_string_append (str, ">"); | |
976 break; | |
977 | |
978 case '"': | |
979 g_string_append (str, """); | |
980 break; | |
981 | |
982 default: | |
983 c = g_utf8_get_char (p); | |
984 if ((0x1 <= c && c <= 0x8) || | |
985 (0xb <= c && c <= 0xc) || | |
986 (0xe <= c && c <= 0x1f) || | |
987 (0x7f <= c && c <= 0x84) || | |
988 (0x86 <= c && c <= 0x9f)) | |
989 g_string_append_printf (str, "&#x%x;", c); | |
990 else | |
991 g_string_append_len (str, p, next - p); | |
992 break; | |
993 } | |
994 | |
995 p = next; | |
996 } | |
997 } | |
998 | |
999 /* This function is stolen from glib's gmarkup.c */ | |
1000 gchar *purple_markup_escape_text(const gchar *text, gssize length) | |
1001 { | |
1002 GString *str; | |
1003 | |
1004 g_return_val_if_fail(text != NULL, NULL); | |
1005 | |
1006 if (length < 0) | |
1007 length = strlen(text); | |
1008 | |
1009 /* prealloc at least as long as original text */ | |
1010 str = g_string_sized_new(length); | |
1011 append_escaped_text(str, text, length); | |
1012 | |
1013 return g_string_free(str, FALSE); | |
1014 } | |
944 | 1015 |
945 const char * | 1016 const char * |
946 purple_markup_unescape_entity(const char *text, int *length) | 1017 purple_markup_unescape_entity(const char *text, int *length) |
947 { | 1018 { |
948 const char *pln; | 1019 const char *pln; |