Date: Wednesday, January 24, 2007 @ 11:40:46
  Author: marc
    Path: /cvsroot/carob/carob/src

Modified: StringCodecs.cpp (1.20 -> 1.21)

Implemented more explicit CAROB_FORCE_UNICODE_WCHAR iconv hack for
FreeBSD. CAROB-79


------------------+
 StringCodecs.cpp |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)


Index: carob/src/StringCodecs.cpp
diff -u carob/src/StringCodecs.cpp:1.20 carob/src/StringCodecs.cpp:1.21
--- carob/src/StringCodecs.cpp:1.20     Tue Jan 23 19:23:53 2007
+++ carob/src/StringCodecs.cpp  Wed Jan 24 11:40:46 2007
@@ -176,17 +176,38 @@
 #define TOSTRING(x) STRINGIFY(x)
 
 
-// From iconv_open() @ opengroup:
-// "Settings of fromcode and tocode and their permitted combinations are 
implementation-defined."
+
+/**
+ * Unreliable FreeBSD hack. According to Bruno Haible, in 2000
+ * wchar_t on FreeBSD was: "All bytes belonging to the multibyte char,
+ * packed in a single word. This makes the widechar <--> multibyte
+ * converter quite fast."
+ *
+ * ==> locale-dependent and definitely not unicode.
+ */
+#ifdef __FreeBSD__   // TODO:  __FreeBSD__ > ?
+#define CAROB_FORCE_UNICODE_WCHAR
+#endif
+
 namespace {
+
+/**
+ * Trying to figure out which codeset wchar_t is using.
+ *
+ * On some systems it may depend on the locale... => better not use
+ * iconv at all in this case but locales instead.
+ */
 inline const char *wchar_codeset() throw (CodecException)
 {
 #ifdef CAROB_WCHAR_CODESET
-    // command line override
+    // let the command line decide for us
     return TOSTRING(CAROB_WCHAR_CODESET);
 #elif defined(__GLIBC__)
+    // the easiest way: not deciding.
     return "WCHAR_T";
-#else
+#elif defined(__STDC_ISO_10646__) || CAROB_FORCE_UNICODE_WCHAR
+    // __STDC_ISO_10646__ is from C99 (ISO 9899:1999, 6.10.8.2)
+
     // UCS-N-INTERNAL = native + no BOM
 
     if (sizeof(wchar_t) == 4) // compiler will optimize this away
@@ -196,12 +217,16 @@
         return "UCS-2-INTERNAL";
 
     throw CodecException(L"Unsupported sizeof(wchar_t) in wchar_codeset()");
+#else
+#error iconv problem: unknown wchar_t codeset. Define CAROB_WCHAR_CODESET?
 #endif
 }
 }
 
 IconvCodec::IconvCodec(const std::string &code) throw (CodecException)
 {
+    // From iconv_open() @ opengroup: "Settings of fromcode and tocode
+    // and their permitted combinations are implementation-defined."
   const char * wide_codeset = wchar_codeset();
 
   if (isDebugEnabled())

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to