Date: Tuesday, January 23, 2007 @ 19:23:53
  Author: marc
    Path: /cvsroot/carob/carob/src

Modified: StringCodecs.cpp (1.19 -> 1.20)

In IconvCodec, replaced hardcoded "WCHAR_T" native wchar_t by new
wchar_codeset() function returning UCS-4-INTERNAL on non-__GLIBC__
platforms.  Should finally make non-ASCII characters work on
FreeBSD. CAROB-79


------------------+
 StringCodecs.cpp |   46 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 42 insertions(+), 4 deletions(-)


Index: carob/src/StringCodecs.cpp
diff -u carob/src/StringCodecs.cpp:1.19 carob/src/StringCodecs.cpp:1.20
--- carob/src/StringCodecs.cpp:1.19     Fri Jan 19 16:04:31 2007
+++ carob/src/StringCodecs.cpp  Tue Jan 23 19:23:53 2007
@@ -171,15 +171,53 @@
 
 #include <errno.h>
 
+// need two steps to delay expansion of argument
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+
+
+// From iconv_open() @ opengroup:
+// "Settings of fromcode and tocode and their permitted combinations are 
implementation-defined."
+namespace {
+inline const char *wchar_codeset() throw (CodecException)
+{
+#ifdef CAROB_WCHAR_CODESET
+    // command line override
+    return TOSTRING(CAROB_WCHAR_CODESET);
+#elif defined(__GLIBC__)
+    return "WCHAR_T";
+#else
+    // UCS-N-INTERNAL = native + no BOM
+
+    if (sizeof(wchar_t) == 4) // compiler will optimize this away
+        return "UCS-4-INTERNAL";
+
+    if (sizeof(wchar_t) == 2)
+        return "UCS-2-INTERNAL";
+
+    throw CodecException(L"Unsupported sizeof(wchar_t) in wchar_codeset()");
+#endif
+}
+}
+
 IconvCodec::IconvCodec(const std::string &code) throw (CodecException)
 {
-  cd_from = iconv_open(code.c_str(), "WCHAR_T");
+  const char * wide_codeset = wchar_codeset();
+
+  if (isDebugEnabled())
+      logDebug(L"IconvCodec::IconvCodec",
+               std::wstring(L"creating new codec ")
+               + fromString(wide_codeset) + L" / " + fromString(code));
+
+  cd_from = iconv_open(code.c_str(), wide_codeset);
   if (cd_from == (iconv_t) -1)
-      throw CodecException(L"Failed to open iconv encoder to " + 
fromString(code));
+      throw CodecException(L"Failed to open iconv encoder from "
+                           + fromString(wide_codeset) + L" to " + 
fromString(code));
 
-  cd_to = iconv_open("WCHAR_T", code.c_str());
+  cd_to = iconv_open(wide_codeset, code.c_str());
   if (cd_to == (iconv_t) -1)
-      throw CodecException(L"Failed to open iconv decoder from " + 
fromString(code));
+      throw CodecException(L"Failed to open iconv decoder from " + 
fromString(code)
+                           + L" to " + fromString(wide_codeset));
 
   encodingName = StaticCodecs::fromASCII(code);
 

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

Reply via email to