tConversion routines made much more robust; rather than truncating suspect stri… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit dcfe8719abb7b436b510f5c0c4479b8ea7a85249 | |
parent 144a831286a6d11ed7e534b991e412ad8bed983f | |
Author: Ben Webb <[email protected]> | |
Date: Mon, 5 Aug 2002 11:37:25 +0000 | |
Conversion routines made much more robust; rather than truncating suspect | |
strings, the offending characters are replaced by ? symbols. | |
Diffstat: | |
M src/convert.c | 19 +++++++++++++------ | |
1 file changed, 13 insertions(+), 6 deletions(-) | |
--- | |
diff --git a/src/convert.c b/src/convert.c | |
t@@ -100,16 +100,23 @@ static gchar *do_convert(const gchar *from_codeset, cons… | |
gchar *to_str; | |
if (strcmp(to_codeset, "UTF-8") == 0 && strcmp(from_codeset, "UTF-8") == 0) { | |
- const gchar *end; | |
+ const gchar *start, *end; | |
- to_str = g_strdup(from_str); | |
- if (!g_utf8_validate(to_str, -1, &end) && end) { | |
- *((gchar *)end) = '\0'; | |
+ if (from_len == -1) { | |
+ to_str = g_strdup(from_str); | |
+ } else { | |
+ to_str = g_strndup(from_str, from_len); | |
+ } | |
+ start = to_str; | |
+ while (start && *start && !g_utf8_validate(start, -1, &end) | |
+ && end && *end) { | |
+ *((gchar *)end) = '?'; | |
+ start = ++end; | |
} | |
return to_str; | |
} else { | |
- to_str = g_convert(from_str, from_len, to_codeset, from_codeset, | |
- NULL, NULL, NULL); | |
+ to_str = g_convert_with_fallback(from_str, from_len, to_codeset, | |
+ from_codeset, "?", NULL, NULL, NULL); | |
if (to_str) { | |
return to_str; | |
} else { |