changeset 1324:99454d030722 trunk

[svn] try to avoid malconversion of latin1 character when chardet has been enabled.
author yaz
date Thu, 22 Jun 2006 07:04:25 -0700
parents 43547cd5e74e
children 4f7d6645972c
files ChangeLog audacious/util.c
diffstat 2 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 22 03:01:46 2006 -0700
+++ b/ChangeLog	Thu Jun 22 07:04:25 2006 -0700
@@ -1,3 +1,12 @@
+2006-06-22 10:01:46 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [1558]
+  - smarter way to detect gmake
+  
+
+  Changes:        Modified:
+  +1 -1           trunk/mk/objective.mk  
+
+
 2006-06-22 09:35:01 +0000  William Pitcock <nenolod@nenolod.net>
   revision [1556]
   - avoid system /bin/test in Makefiles as it may not behave as expected
--- a/audacious/util.c	Thu Jun 22 03:01:46 2006 -0700
+++ b/audacious/util.c	Thu Jun 22 07:04:25 2006 -0700
@@ -1279,14 +1279,22 @@
     if (!str)
         return NULL;
 
+    /* Note: Currently, playlist calls this function repeatedly, even
+     * if the string is already converted into utf-8.
+     * chardet_to_utf8() would convert a valid utf-8 string into a
+     * different utf-8 string, if fallback encodings were supplied and
+     * the given string could be treated as a string in one of fallback
+     * encodings. To avoid this, the order of evaluation has been
+     * changed. (It might cause a drawback?)
+     */
+    /* already UTF-8? */
+    if (g_utf8_validate(str, -1, NULL))
+        return g_strdup(str);
+
     /* chardet encoding detector */
     if ((out_str = chardet_to_utf8(str, strlen(str), NULL, NULL, NULL)))
         return out_str;
 
-    /* already UTF-8? */
-    if (g_utf8_validate(str, -1, NULL))
-        return g_strdup(str);
-
     /* assume encoding associated with locale */
     if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL)))
         return out_str;
@@ -1491,6 +1499,16 @@
 		}
 	}
 
+#ifdef USE_CHARDET
+	/* many tag libraries return 2byte latin1 utf8 character as
+	   converted 8bit iso-8859-1 character, if they are asked to return
+	   latin1 string.
+	 */
+	if(!ret){
+		ret = g_convert(str, len, "UTF-8", "ISO-8859-1", bytes_read, bytes_write, error);
+	}
+#endif
+
 	if(ret){
 		if(g_utf8_validate(ret, -1, NULL))
 			return ret;
@@ -1500,5 +1518,5 @@
 		}
 	}
 	
-	return NULL;	// if I have no idea, return NULL.
+	return NULL;	/* if I have no idea, return NULL. */
 }