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/09 22:57:21 UTC
svn commit: r526915 - /logging/log4cxx/trunk/src/charsetencoder.cpp
Author: carnold
Date: Mon Apr 9 13:57:20 2007
New Revision: 526915
URL: http://svn.apache.org/viewvc?view=rev&rev=526915
Log:
LOGCXX-178: Restore WideEncoder
Modified:
logging/log4cxx/trunk/src/charsetencoder.cpp
Modified: logging/log4cxx/trunk/src/charsetencoder.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/charsetencoder.cpp?view=diff&rev=526915&r1=526914&r2=526915
==============================================================================
--- logging/log4cxx/trunk/src/charsetencoder.cpp (original)
+++ logging/log4cxx/trunk/src/charsetencoder.cpp Mon Apr 9 13:57:20 2007
@@ -416,6 +416,63 @@
UTF16LECharsetEncoder& operator=(const UTF16LECharsetEncoder&);
};
+#if LOG4CXX_LOGCHAR_IS_UTF8 && (defined(_WIN32) || defined(__STDC_ISO_10646__))
+
+ /**
+ * Converts a LogString to an array of wchar_t.
+ */
+ class WideCharsetEncoder : public CharsetEncoder
+ {
+ public:
+ WideCharsetEncoder() {
+ }
+
+
+ virtual log4cxx_status_t encode(const LogString& in,
+ LogString::const_iterator& iter,
+ ByteBuffer& out) {
+ log4cxx_status_t stat = APR_SUCCESS;
+ while(iter != in.end() && out.remaining() >= 4) {
+ unsigned int sv = UnicodeHelper::decode(in, iter);
+ if (sv == 0xFFFF) {
+ stat = APR_BADARG;
+ break;
+ }
+ int count = encodeWide(sv, (wchar_t*) out.current());
+ out.position(out.position() + count * sizeof(wchar_t));
+ }
+ return stat;
+ }
+
+ private:
+ WideCharsetEncoder(const WideCharsetEncoder&);
+ WideCharsetEncoder& operator=(const WideCharsetEncoder&);
+
+#if defined(_WIN32)
+ int encodeWide(unsigned int ch, wchar_t* dst) {
+ if (ch <= 0xFFFF) {
+ *dst = (wchar_t) ch;
+ return 1;
+ }
+ unsigned char u = (unsigned char) (ch >> 16);
+ unsigned char w = (unsigned char) (u - 1);
+ wchar_t hs = (wchar_t) (0xD800 + ((w & 0xF) << 6) + ((ch & 0xFFFF) >> 10));
+ wchar_t ls = (wchar_t) (0xDC00 + (ch && 0x3FF));
+ dst[0] = hs;
+ dst[1] = ls;
+ return 2;
+ }
+#endif
+
+#if defined(__STDC_ISO_10646__)
+ int encodeWide(unsigned int ch, wchar_t* dst) {
+ *dst = ch;
+ return 1;
+ }
+#endif
+
+ };
+#endif
} // namespace helpers
@@ -476,8 +533,8 @@
CharsetEncoder* CharsetEncoder::createWideEncoder() {
#if LOG4CXX_LOGCHAR_IS_WCHAR
return new TrivialCharsetEncoder();
-//#elif LOG4CXX_LOGCHAR_IS_UTF8 && (defined(_WIN32) || defined(__STDC_ISO_10646__))
-// return new WideCharsetEncoder();
+#elif LOG4CXX_LOGCHAR_IS_UTF8 && (defined(_WIN32) || defined(__STDC_ISO_10646__))
+ return new WideCharsetEncoder();
#else
return new APRCharsetEncoder("WCHAR_T");
#endif