From 32546e22828e793e3881e1055acb72b6a044e331 Mon Sep 17 00:00:00 2001 From: Rat Date: Mon, 7 Jun 2010 19:10:55 +0200 Subject: added ace + vcproj for win --HG-- branch : trunk --- externals/ace/UTF8_Encoding_Converter.cpp | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 externals/ace/UTF8_Encoding_Converter.cpp (limited to 'externals/ace/UTF8_Encoding_Converter.cpp') diff --git a/externals/ace/UTF8_Encoding_Converter.cpp b/externals/ace/UTF8_Encoding_Converter.cpp new file mode 100644 index 00000000000..cd6c409d0f8 --- /dev/null +++ b/externals/ace/UTF8_Encoding_Converter.cpp @@ -0,0 +1,92 @@ +// $Id: UTF8_Encoding_Converter.cpp 80826 2008-03-04 14:51:23Z wotte $ + +#include "ace/UTF8_Encoding_Converter.h" + +#if defined (ACE_USES_WCHAR) +#include "ace/UTF16_Encoding_Converter.h" +#include "ace/UTF32_Encoding_Converter.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_Memory.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL + +ACE_UTF8_Encoding_Converter::ACE_UTF8_Encoding_Converter (void) + : native_ (0) +{ + // Choose a converter for the ASCII or UTF-8 string to a wide character + // string which we will use in from_utf8. We have to make an + // assumption here about the encoding based on the size of ACE_TCHAR. + switch (sizeof (ACE_TCHAR)) + { + case 4: + ACE_NEW(this->native_, ACE_UTF32_Encoding_Converter); + break; + case 2: + ACE_NEW(this->native_, ACE_UTF16_Encoding_Converter); + break; + } +} + +ACE_UTF8_Encoding_Converter::~ACE_UTF8_Encoding_Converter (void) +{ + delete native_; +} + +ACE_UTF8_Encoding_Converter::Result +ACE_UTF8_Encoding_Converter::to_utf8 (const void* source, + size_t source_size, + ACE_Byte* target, + size_t target_size, + bool /*strict*/) +{ + if (target_size >= source_size) + { + ACE_OS::memcpy (target, source, source_size); + return CONVERSION_OK; + } + + return TARGET_EXHAUSTED; +} + +ACE_UTF8_Encoding_Converter::Result +ACE_UTF8_Encoding_Converter::from_utf8 (const ACE_Byte* source, + size_t source_size, + void* target, + size_t target_size, + bool strict) +{ + if (this->native_ != 0) + { + return this->native_->from_utf8(source, source_size, + target, target_size, strict); + } + + ACE_TCHAR* targetStart = static_cast (target); + ACE_OS::strncpy (targetStart, + ACE_TEXT_CHAR_TO_TCHAR ( + reinterpret_cast (source)), + source_size); + targetStart[source_size] = 0; + return CONVERSION_OK; +} + +ACE_UTF8_Encoding_Converter* +ACE_UTF8_Encoding_Converter::encoded (const ACE_Byte* source, + size_t source_size) +{ + for(size_t i = 0; i < source_size; i++) + { + if (source[i] < 0x01 || source[i] > 0x7f) + return 0; + } + + // All characters are "valid" ASCII + ACE_UTF8_Encoding_Converter* converter = 0; + ACE_NEW_RETURN (converter, + ACE_UTF8_Encoding_Converter, + 0); + return converter; +} + +ACE_END_VERSIONED_NAMESPACE_DECL +#endif /* ACE_USES_WCHAR */ -- cgit v1.2.3