You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2007/04/04 08:23:37 UTC

svn commit: r525438 - in /logging/log4cxx/trunk/src: charsetdecoder.cpp charsetencoder.cpp unicodehelper.cpp

Author: carnold
Date: Tue Apr  3 23:23:36 2007
New Revision: 525438

URL: http://svn.apache.org/viewvc?view=rev&rev=525438
Log:
LOGCXX-178: Fix to get wchar_t on Win32 working again

Modified:
    logging/log4cxx/trunk/src/charsetdecoder.cpp
    logging/log4cxx/trunk/src/charsetencoder.cpp
    logging/log4cxx/trunk/src/unicodehelper.cpp

Modified: logging/log4cxx/trunk/src/charsetdecoder.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/charsetdecoder.cpp?view=diff&rev=525438&r1=525437&r2=525438
==============================================================================
--- logging/log4cxx/trunk/src/charsetdecoder.cpp (original)
+++ logging/log4cxx/trunk/src/charsetdecoder.cpp Tue Apr  3 23:23:36 2007
@@ -24,7 +24,7 @@
 #include <log4cxx/helpers/pool.h>
 #include <apr_xlate.h>
 #include <log4cxx/private/log4cxx_private.h>
-#include <langinfo.h>
+#include <locale.h>
 #include <apr_portable.h>
 
 

Modified: logging/log4cxx/trunk/src/charsetencoder.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/charsetencoder.cpp?view=diff&rev=525438&r1=525437&r2=525438
==============================================================================
--- logging/log4cxx/trunk/src/charsetencoder.cpp (original)
+++ logging/log4cxx/trunk/src/charsetencoder.cpp Tue Apr  3 23:23:36 2007
@@ -303,7 +303,7 @@
                       const logchar* const srcEnd = srcBase + in.length();
                       const logchar* src = in.data() + (iter - in.begin());
                       while(out.remaining() >= 8 && src < srcEnd) {
-                           unsigned int sv = UnicodeHelper::decode(src, srcEnd);
+                           unsigned int sv = decodeWide(src, srcEnd);
                            if (sv == 0xFFFF) {
                                stat = APR_BADARG;
                                break;
@@ -311,7 +311,7 @@
                            int bytes = UnicodeHelper::encodeUTF8(sv, out.data() + out.position());
                            out.position(out.position() + bytes);
                       }
-                 iter = in.begin() + (src - srcBase);
+                      iter = in.begin() + (src - srcBase);
                   }
                   return APR_SUCCESS;
               }
@@ -319,6 +319,26 @@
           private:
                   UTF8CharsetEncoder(const UTF8CharsetEncoder&);
                   UTF8CharsetEncoder& operator=(const UTF8CharsetEncoder&);
+
+#if defined(_WIN32)
+				  unsigned int decodeWide(const wchar_t*& src, const wchar_t* srcEnd) {
+                       unsigned int sv = *(src++);
+                       if (sv < 0xDC00 || sv >= 0xDC00) {
+                          return sv;
+					   }
+                       if (src < srcEnd) {
+                           unsigned short ls = *(src++);
+                           unsigned char w = (unsigned char) ((sv >> 6) & 0x0F);
+                           return ((w + 1) << 16) + ((sv & 0x3F) << 10) + (ls & 0x3FF);
+					   }
+                       return 0xFFFF;
+				  }
+#endif
+#if defined(__STDC_ISO_10646__)
+                  unsigned int decodeWide(const wchar_t*& src, const wchar_t* /* srcEnd */) {
+						return *(src++);
+				  }
+#endif
           };
 #else
 #error logchar cannot be wchar_t unless _WIN32 or __STDC_ISO_10646___ is defined          

Modified: logging/log4cxx/trunk/src/unicodehelper.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/unicodehelper.cpp?view=diff&rev=525438&r1=525437&r2=525438
==============================================================================
--- logging/log4cxx/trunk/src/unicodehelper.cpp (original)
+++ logging/log4cxx/trunk/src/unicodehelper.cpp Tue Apr  3 23:23:36 2007
@@ -201,7 +201,7 @@
 
 #if LOG4CXX_LOGCHAR_IS_WCHAR
 #if defined(_WIN32)
-int UnicodeHelper::encode(unsigned int sv, logchar* out) {
+int UnicodeHelper::encode(unsigned int ch, logchar* dst) {
   if (ch <= 0xFFFF) {
       *dst = (wchar_t) ch;
       return 1;