1 #include "ace/UTF8_Encoding_Converter.h"
3 #if defined (ACE_USES_WCHAR)
4 #include "ace/UTF16_Encoding_Converter.h"
5 #include "ace/UTF32_Encoding_Converter.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_Memory.h"
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_UTF8_Encoding_Converter::ACE_UTF8_Encoding_Converter ()
14 // Choose a converter for the ASCII or UTF-8 string to a wide character
15 // string which we will use in from_utf8. We have to make an
16 // assumption here about the encoding based on the size of ACE_TCHAR.
17 switch (sizeof (ACE_TCHAR
))
20 ACE_NEW(this->native_
, ACE_UTF32_Encoding_Converter
);
23 ACE_NEW(this->native_
, ACE_UTF16_Encoding_Converter
);
28 ACE_UTF8_Encoding_Converter::~ACE_UTF8_Encoding_Converter ()
33 ACE_UTF8_Encoding_Converter::Result
34 ACE_UTF8_Encoding_Converter::to_utf8 (const void* source
,
40 if (target_size
>= source_size
)
42 ACE_OS::memcpy (target
, source
, source_size
);
46 return TARGET_EXHAUSTED
;
49 ACE_UTF8_Encoding_Converter::Result
50 ACE_UTF8_Encoding_Converter::from_utf8 (const ACE_Byte
* source
,
56 if (this->native_
!= 0)
58 return this->native_
->from_utf8(source
, source_size
,
59 target
, target_size
, strict
);
62 ACE_TCHAR
* targetStart
= static_cast<ACE_TCHAR
*> (target
);
63 ACE_OS::strncpy (targetStart
,
64 ACE_TEXT_CHAR_TO_TCHAR (
65 reinterpret_cast<const char*> (source
)),
67 targetStart
[source_size
] = 0;
71 ACE_UTF8_Encoding_Converter
*
72 ACE_UTF8_Encoding_Converter::encoded (const ACE_Byte
* source
,
75 for(size_t i
= 0; i
< source_size
; i
++)
77 if (source
[i
] < 0x01 || source
[i
] > 0x7f)
81 // All characters are "valid" ASCII
82 ACE_UTF8_Encoding_Converter
* converter
= 0;
83 ACE_NEW_RETURN (converter
,
84 ACE_UTF8_Encoding_Converter
,
89 ACE_END_VERSIONED_NAMESPACE_DECL
90 #endif /* ACE_USES_WCHAR */