UTF16_Encoding_Converter.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=========================================================================
00004 /**
00005  * @file UTF16_Encoding_Converter.h
00006  *
00007  * UTF16_Encoding_Converter.h,v 4.1 2006/01/09 15:18:53 elliott_c Exp
00008  *
00009  * This class contains declarations for methods that convert between
00010  * UTF-16 (both BE and LE) and UTF-8
00011  *
00012  * @author Chad Elliott <elliott_c@ociweb.com>
00013  */
00014 //=========================================================================
00015 
00016 #ifndef ACE_UTF16_ENCODING_CONVERTER_H
00017 #define ACE_UTF16_ENCODING_CONVERTER_H
00018 
00019 #include /**/ "ace/pre.h"
00020 
00021 #include "ace/Encoding_Converter.h"
00022 
00023 #if defined (ACE_USES_WCHAR)
00024 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 /** Convert from UTF-16 to UTF-8 and from UTF-8 to UTF-16.
00027  * This class implements the ACE_Encoding_Converter interface.
00028  */
00029 class ACE_UTF16_Encoding_Converter: public ACE_Encoding_Converter
00030 {
00031 public:
00032   /// The swap parameter determines whether we need to swap byte order on
00033   /// the stream as each word is pulled off when converting to UTF-8.
00034   ACE_UTF16_Encoding_Converter (bool swap = false);
00035 
00036   /// This is a do nothing destructor.
00037   virtual ~ACE_UTF16_Encoding_Converter (void);
00038 
00039   /// Convert the source from UTF-16 to UTF-8 and store it in the
00040   /// provided target buffer.
00041   virtual Result to_utf8 (const void* source,
00042                           size_t source_size,
00043                           ACE_Byte* target,
00044                           size_t target_size,
00045                           bool strict = true);
00046 
00047   /// Convert the UTF-8 source into a UTF-16 encoding and store it
00048   /// in the provided target buffer.
00049   virtual Result from_utf8 (const ACE_Byte* source,
00050                             size_t source_size,
00051                             void* target,
00052                             size_t target_size,
00053                             bool strict = true);
00054 
00055   /// This factory helper method determines if the source stream is UTF-16
00056   /// encoded.  If it is, allocate an ACE_UTF16_Encoding_Converter and
00057   /// return it.  The caller then owns the allocated object.
00058   static ACE_UTF16_Encoding_Converter* encoded (const ACE_Byte* source,
00059                                                 size_t source_size);
00060 
00061 protected:
00062   /// Determines if the source buffer is legal UTF-8
00063   bool is_legal_utf8 (const ACE_Byte* source,
00064                       size_t length) const;
00065 
00066   static ACE_UINT32 get_UNI_SUR_HIGH_START (void);
00067   static ACE_UINT32 get_UNI_SUR_LOW_END (void);
00068   static ACE_UINT32 get_UNI_REPLACEMENT_CHAR (void);
00069   static const ACE_Byte* get_first_byte_mark (void);
00070   static const ACE_Byte* get_trailing_bytes_for_utf8 (void);
00071   static const ACE_UINT32* get_offsets_from_utf8 (void);
00072 
00073   bool swap_;
00074 };
00075 
00076 ACE_END_VERSIONED_NAMESPACE_DECL
00077 
00078 #if defined (__ACE_INLINE__)
00079 #include "ace/UTF16_Encoding_Converter.inl"
00080 #endif /* __ACE_INLINE__ */
00081 
00082 #endif /* ACE_USES_WCHAR */
00083 
00084 #include /**/ "ace/post.h"
00085 
00086 #endif /* ACE_UTF16_ENCODING_CONVERTER_H */

Generated on Thu Nov 9 09:42:09 2006 for ACE by doxygen 1.3.6