Don't use conversion with transliteration in u{8,16,32}_strcoll.
authorBruno Haible <bruno@clisp.org>
Mon, 24 May 2010 21:00:42 +0000 (23:00 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 24 May 2010 21:00:42 +0000 (23:00 +0200)
ChangeLog
lib/unistr/u-strcoll.h
lib/unistr/u16-strcoll.c
lib/unistr/u32-strcoll.c
lib/unistr/u8-strcoll.c
modules/unistr/u16-strcoll
modules/unistr/u32-strcoll
modules/unistr/u8-strcoll

index bfbd9249eeb606cd379322d6dc18cce103687344..45828dcab97cd5b32185d1b22126fc94c89a2e80 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2010-05-24  Bruno Haible  <bruno@clisp.org>
+
+       Don't use conversion with transliteration in u{8,16,32}_strcoll.
+       * lib/unistr/u-strcoll.h (FUNC): Use U_STRCONV_TO_ENCODING with
+       iconveh_error argument.
+       * lib/unistr/u8-strcoll.c: Define U_STRCONV_TO_ENCODING instead of
+       U_STRCONV_TO_LOCALE.
+       * lib/unistr/u16-strcoll.c: Likewise.
+       * lib/unistr/u32-strcoll.c: Likewise.
+       * modules/unistr/u8-strcoll (Depends-on): Add
+       uniconv/u8-strconv-to-enc, localcharset. Remove
+       uniconv/u8-strconv-to-locale.
+       (configure.ac): Bump version number.
+       * modules/unistr/u16-strcoll (Depends-on): Add
+       uniconv/u16-strconv-to-enc, localcharset. Remove
+       uniconv/u16-strconv-to-locale.
+       (configure.ac): Bump version number.
+       * modules/unistr/u32-strcoll (Depends-on): Add
+       uniconv/u32-strconv-to-enc, localcharset. Remove
+       uniconv/u32-strconv-to-locale.
+       (configure.ac): Bump version number.
+
 2010-05-24  Bruno Haible  <bruno@clisp.org>
 
        Avoid a test failure on NetBSD 5.0.
index 9ec5c60170bc5356fad99848b7b8b27451b9900f..62addbaf1a7c354e4686fdf41da04754f38fa157 100644 (file)
@@ -23,14 +23,19 @@ FUNC (const UNIT *s1, const UNIT *s2)
      When it fails, it sets errno, but also returns a meaningful return value,
      for the sake of callers which ignore errno.  */
   int final_errno = errno;
+  const char *encoding = locale_charset ();
   char *sl1;
   char *sl2;
   int result;
 
-  sl1 = U_STRCONV_TO_LOCALE (s1);
+  /* Pass iconveh_error here, not iconveh_question_mark.  Otherwise the
+     conversion to locale encoding can do transliteration or map some
+     characters to question marks, leading to results that depend on the
+     iconv() implementation and are not obvious.  */
+  sl1 = U_STRCONV_TO_ENCODING (s1, encoding, iconveh_error);
   if (sl1 != NULL)
     {
-      sl2 = U_STRCONV_TO_LOCALE (s2);
+      sl2 = U_STRCONV_TO_ENCODING (s2, encoding, iconveh_error);
       if (sl2 != NULL)
         {
           /* Compare sl1 and sl2.  */
@@ -41,10 +46,10 @@ FUNC (const UNIT *s1, const UNIT *s2)
               /* strcoll succeeded.  */
               free (sl1);
               free (sl2);
-              /* The conversion to locale encoding can do transliteration or
-                 map some characters to question marks.  Therefore sl1 and sl2
-                 may be equal when s1 and s2 were in fact different.  Return a
-                 nonzero result in this case.  */
+              /* The conversion to locale encoding can drop Unicode TAG
+                 characters.  Therefore sl1 and sl2 may be equal when s1
+                 and s2 were in fact different.  Return a nonzero result
+                 in this case.  */
               if (result == 0)
                 result = U_STRCMP (s1, s2);
             }
@@ -68,7 +73,7 @@ FUNC (const UNIT *s1, const UNIT *s2)
   else
     {
       final_errno = errno;
-      sl2 = U_STRCONV_TO_LOCALE (s2);
+      sl2 = U_STRCONV_TO_ENCODING (s2, encoding, iconveh_error);
       if (sl2 != NULL)
         {
           /* s2 could be converted to locale encoding, s1 not.  */
index 5a504bf4d90960ba9d243a088f60d4f829b0df63..b75ba34a3d6902cfb5e12b2b401cd4b73750f1b8 100644 (file)
@@ -29,5 +29,5 @@
 #define FUNC u16_strcoll
 #define UNIT uint16_t
 #define U_STRCMP u16_strcmp
-#define U_STRCONV_TO_LOCALE u16_strconv_to_locale
+#define U_STRCONV_TO_ENCODING u16_strconv_to_encoding
 #include "u-strcoll.h"
index 9748855342f0be284b47c45edb039786d918bd21..95bab075751b7dacd2eff9e9b02e0877e1dd67ee 100644 (file)
@@ -29,5 +29,5 @@
 #define FUNC u32_strcoll
 #define UNIT uint32_t
 #define U_STRCMP u32_strcmp
-#define U_STRCONV_TO_LOCALE u32_strconv_to_locale
+#define U_STRCONV_TO_ENCODING u32_strconv_to_encoding
 #include "u-strcoll.h"
index 9ffa135e68d5ce2ba40a715c67480dfa085b689a..b4d01061cf712acbe110d80bb6a1b42c73e6f10e 100644 (file)
@@ -29,5 +29,5 @@
 #define FUNC u8_strcoll
 #define UNIT uint8_t
 #define U_STRCMP u8_strcmp
-#define U_STRCONV_TO_LOCALE u8_strconv_to_locale
+#define U_STRCONV_TO_ENCODING u8_strconv_to_encoding
 #include "u-strcoll.h"
index 718f7d9e3cd526f477e3c9a7a274966d150be49c..d364454f68dd2b80f7a5ddb033b3587721b3ec24 100644 (file)
@@ -8,10 +8,11 @@ lib/unistr/u-strcoll.h
 Depends-on:
 unistr/base
 unistr/u16-strcmp
-uniconv/u16-strconv-to-locale
+uniconv/u16-strconv-to-enc
+localcharset
 
 configure.ac:
-gl_LIBUNISTRING_LIBSOURCE([0.9.3], [unistr/u16-strcoll.c])
+gl_LIBUNISTRING_LIBSOURCE([0.9.4], [unistr/u16-strcoll.c])
 
 Makefile.am:
 
index e2441758d7f1672a0d9461db88658325d06ae107..1cdd5952322ca995104b0be2cd25913d85403c2c 100644 (file)
@@ -8,10 +8,11 @@ lib/unistr/u-strcoll.h
 Depends-on:
 unistr/base
 unistr/u32-strcmp
-uniconv/u32-strconv-to-locale
+uniconv/u32-strconv-to-enc
+localcharset
 
 configure.ac:
-gl_LIBUNISTRING_LIBSOURCE([0.9.3], [unistr/u32-strcoll.c])
+gl_LIBUNISTRING_LIBSOURCE([0.9.4], [unistr/u32-strcoll.c])
 
 Makefile.am:
 
index e28e7719332492b3a5423809f7d4f56e18a761de..45d563f5563a19eaeb8d6758ba4a62636572cac7 100644 (file)
@@ -8,10 +8,11 @@ lib/unistr/u-strcoll.h
 Depends-on:
 unistr/base
 unistr/u8-strcmp
-uniconv/u8-strconv-to-locale
+uniconv/u8-strconv-to-enc
+localcharset
 
 configure.ac:
-gl_LIBUNISTRING_LIBSOURCE([0.9.3], [unistr/u8-strcoll.c])
+gl_LIBUNISTRING_LIBSOURCE([0.9.4], [unistr/u8-strcoll.c])
 
 Makefile.am: