TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
UTF16< CharType > Struct Template Reference

UTF-16 encoding. More...

#include <encodings.h>

Public Types

enum  { supportUnicode = 1 }
 
typedef CharType Ch
 

Public Member Functions

 RAPIDJSON_STATIC_ASSERT (sizeof(Ch) >=2)
 

Static Public Member Functions

template<typename OutputStream >
static void Encode (OutputStream &os, unsigned codepoint)
 
template<typename InputStream >
static bool Decode (InputStream &is, unsigned *codepoint)
 
template<typename InputStream , typename OutputStream >
static bool Validate (InputStream &is, OutputStream &os)
 

Detailed Description

template<typename CharType = wchar_t>
struct UTF16< CharType >

UTF-16 encoding.

http://en.wikipedia.org/wiki/UTF-16 http://tools.ietf.org/html/rfc2781

Template Parameters
CharTypeType for storing 16-bit UTF-16 data. Default is wchar_t. C++11 may use char16_t instead.
Note
implements Encoding concept
For in-memory access, no need to concern endianness. The code units and code points are represented by CPU's endianness. For streaming, use UTF16LE and UTF16BE, which handle endianness.

Member Typedef Documentation

template<typename CharType = wchar_t>
typedef CharType UTF16< CharType >::Ch

Member Enumeration Documentation

template<typename CharType = wchar_t>
anonymous enum
Enumerator
supportUnicode 
245 { supportUnicode = 1 };
Definition: encodings.h:245

Member Function Documentation

template<typename CharType = wchar_t>
template<typename InputStream >
static bool UTF16< CharType >::Decode ( InputStream &  is,
unsigned *  codepoint 
)
inlinestatic
263  {
264  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
265  Ch c = is.Take();
266  if (c < 0xD800 || c > 0xDFFF) {
267  *codepoint = c;
268  return true;
269  }
270  else if (c <= 0xDBFF) {
271  *codepoint = (c & 0x3FF) << 10;
272  c = is.Take();
273  *codepoint |= (c & 0x3FF);
274  *codepoint += 0x10000;
275  return c >= 0xDC00 && c <= 0xDFFF;
276  }
277  return false;
278  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)
CharType Ch
Definition: encodings.h:242

+ Here is the call graph for this function:

template<typename CharType = wchar_t>
template<typename OutputStream >
static void UTF16< CharType >::Encode ( OutputStream &  os,
unsigned  codepoint 
)
inlinestatic
248  {
249  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
250  if (codepoint <= 0xFFFF) {
251  RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
252  os.Put(static_cast<typename OutputStream::Ch>(codepoint));
253  }
254  else {
255  RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
256  unsigned v = codepoint - 0x10000;
257  os.Put(static_cast<typename OutputStream::Ch>((v >> 10) | 0xD800));
258  os.Put((v & 0x3FF) | 0xDC00);
259  }
260  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344

+ Here is the call graph for this function:

template<typename CharType = wchar_t>
UTF16< CharType >::RAPIDJSON_STATIC_ASSERT ( sizeof(Ch) >=  2)

+ Here is the caller graph for this function:

template<typename CharType = wchar_t>
template<typename InputStream , typename OutputStream >
static bool UTF16< CharType >::Validate ( InputStream &  is,
OutputStream &  os 
)
inlinestatic
281  {
282  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
283  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
284  Ch c;
285  os.Put(c = is.Take());
286  if (c < 0xD800 || c > 0xDFFF)
287  return true;
288  else if (c <= 0xDBFF) {
289  os.Put(c = is.Take());
290  return c >= 0xDC00 && c <= 0xDFFF;
291  }
292  return false;
293  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)
CharType Ch
Definition: encodings.h:242

+ Here is the call graph for this function:


The documentation for this struct was generated from the following file: