tConversion routines made much more robust; rather than truncating suspect strings, the offending characters are replaced by ? symbols. - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit dcfe8719abb7b436b510f5c0c4479b8ea7a85249
 (DIR) parent 144a831286a6d11ed7e534b991e412ad8bed983f
 (HTM) Author: Ben Webb <ben@salilab.org>
       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(-)
       ---
 (DIR) diff --git a/src/convert.c b/src/convert.c
       t@@ -100,16 +100,23 @@ static gchar *do_convert(const gchar *from_codeset, const gchar *to_codeset,
          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 {