Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / UTF16_Encoding_Converter.h
blob36826cd1f2f1c056bf53e1b162c48b1c931bcd44
1 // -*- C++ -*-
3 //=========================================================================
4 /**
5 * @file UTF16_Encoding_Converter.h
7 * This class contains declarations for methods that convert between
8 * UTF-16 (both BE and LE) and UTF-8
10 * @author Chad Elliott <elliott_c@ociweb.com>
12 //=========================================================================
14 #ifndef ACE_UTF16_ENCODING_CONVERTER_H
15 #define ACE_UTF16_ENCODING_CONVERTER_H
17 #include /**/ "ace/pre.h"
19 #include "ace/Encoding_Converter.h"
21 #if defined (ACE_USES_WCHAR)
22 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
24 /** Convert from UTF-16 to UTF-8 and from UTF-8 to UTF-16.
25 * This class implements the ACE_Encoding_Converter interface.
27 class ACE_UTF16_Encoding_Converter: public ACE_Encoding_Converter
29 public:
30 /// The swap parameter determines whether we need to swap byte order on
31 /// the stream as each word is pulled off when converting to UTF-8.
32 ACE_UTF16_Encoding_Converter (bool swap = false);
34 /// This is a do nothing destructor.
35 virtual ~ACE_UTF16_Encoding_Converter ();
37 /// Convert the source from UTF-16 to UTF-8 and store it in the
38 /// provided target buffer.
39 virtual Result to_utf8 (const void* source,
40 size_t source_size,
41 ACE_Byte* target,
42 size_t target_size,
43 bool strict = true);
45 /// Convert the UTF-8 source into a UTF-16 encoding and store it
46 /// in the provided target buffer.
47 virtual Result from_utf8 (const ACE_Byte* source,
48 size_t source_size,
49 void* target,
50 size_t target_size,
51 bool strict = true);
53 /// This factory helper method determines if the source stream is UTF-16
54 /// encoded. If it is, allocate an ACE_UTF16_Encoding_Converter and
55 /// return it. The caller then owns the allocated object.
56 static ACE_UTF16_Encoding_Converter* encoded (const ACE_Byte* source,
57 size_t source_size);
59 protected:
60 /// Determines if the source buffer is legal UTF-8
61 bool is_legal_utf8 (const ACE_Byte* source,
62 size_t length) const;
64 static ACE_UINT32 get_UNI_SUR_HIGH_START ();
65 static ACE_UINT32 get_UNI_SUR_LOW_END ();
66 static ACE_UINT32 get_UNI_REPLACEMENT_CHAR ();
67 static const ACE_Byte* get_first_byte_mark ();
68 static const ACE_Byte* get_trailing_bytes_for_utf8 ();
69 static const ACE_UINT32* get_offsets_from_utf8 ();
71 bool swap_;
74 ACE_END_VERSIONED_NAMESPACE_DECL
76 #if defined (__ACE_INLINE__)
77 #include "ace/UTF16_Encoding_Converter.inl"
78 #endif /* __ACE_INLINE__ */
80 #endif /* ACE_USES_WCHAR */
82 #include /**/ "ace/post.h"
84 #endif /* ACE_UTF16_ENCODING_CONVERTER_H */