Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / UTF8_Encoding_Converter.cpp
blobf515f3f1bfd75d83e4bf8c3023dcf482fc5d5574
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 ()
12 : native_ (0)
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))
19 case 4:
20 ACE_NEW(this->native_, ACE_UTF32_Encoding_Converter);
21 break;
22 case 2:
23 ACE_NEW(this->native_, ACE_UTF16_Encoding_Converter);
24 break;
28 ACE_UTF8_Encoding_Converter::~ACE_UTF8_Encoding_Converter ()
30 delete native_;
33 ACE_UTF8_Encoding_Converter::Result
34 ACE_UTF8_Encoding_Converter::to_utf8 (const void* source,
35 size_t source_size,
36 ACE_Byte* target,
37 size_t target_size,
38 bool /*strict*/)
40 if (target_size >= source_size)
42 ACE_OS::memcpy (target, source, source_size);
43 return CONVERSION_OK;
46 return TARGET_EXHAUSTED;
49 ACE_UTF8_Encoding_Converter::Result
50 ACE_UTF8_Encoding_Converter::from_utf8 (const ACE_Byte* source,
51 size_t source_size,
52 void* target,
53 size_t target_size,
54 bool strict)
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)),
66 source_size);
67 targetStart[source_size] = 0;
68 return CONVERSION_OK;
71 ACE_UTF8_Encoding_Converter*
72 ACE_UTF8_Encoding_Converter::encoded (const ACE_Byte* source,
73 size_t source_size)
75 for(size_t i = 0; i < source_size; i++)
77 if (source[i] < 0x01 || source[i] > 0x7f)
78 return 0;
81 // All characters are "valid" ASCII
82 ACE_UTF8_Encoding_Converter* converter = 0;
83 ACE_NEW_RETURN (converter,
84 ACE_UTF8_Encoding_Converter,
85 0);
86 return converter;
89 ACE_END_VERSIONED_NAMESPACE_DECL
90 #endif /* ACE_USES_WCHAR */