IN2OSM  1.0.1
UTF16LE< CharType >

UTF-16 little endian encoding. More...

#include <encodings.h>

Inheritance diagram for UTF16LE< CharType >:
Inheritance graph
Collaboration diagram for UTF16LE< CharType >:
Collaboration graph

Public Types

enum  { supportUnicode = 1 }
 
typedef CharType Ch
 

Public Member Functions

 RAPIDJSON_STATIC_ASSERT (sizeof(Ch) >=2)
 

Static Public Member Functions

template<typename InputByteStream >
static CharType TakeBOM (InputByteStream &is)
 
template<typename InputByteStream >
static CharType Take (InputByteStream &is)
 
template<typename OutputByteStream >
static void PutBOM (OutputByteStream &os)
 
template<typename OutputByteStream >
static void Put (OutputByteStream &os, CharType c)
 
template<typename OutputStream >
static void Encode (OutputStream &os, unsigned codepoint)
 
template<typename OutputStream >
static void EncodeUnsafe (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 UTF16LE< CharType >

UTF-16 little endian encoding.

Definition at line 342 of file encodings.h.

Member Typedef Documentation

◆ Ch

typedef CharType Ch
inherited

Definition at line 270 of file encodings.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
supportUnicode 

Definition at line 273 of file encodings.h.

Member Function Documentation

◆ Decode()

static bool Decode ( InputStream &  is,
unsigned *  codepoint 
)
inlinestaticinherited

Definition at line 307 of file encodings.h.

307  {
308  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
309  typename InputStream::Ch c = is.Take();
310  if (c < 0xD800 || c > 0xDFFF) {
311  *codepoint = static_cast<unsigned>(c);
312  return true;
313  }
314  else if (c <= 0xDBFF) {
315  *codepoint = (static_cast<unsigned>(c) & 0x3FF) << 10;
316  c = is.Take();
317  *codepoint |= (static_cast<unsigned>(c) & 0x3FF);
318  *codepoint += 0x10000;
319  return c >= 0xDC00 && c <= 0xDFFF;
320  }
321  return false;
322  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)

◆ Encode()

static void Encode ( OutputStream &  os,
unsigned  codepoint 
)
inlinestaticinherited

Definition at line 276 of file encodings.h.

276  {
277  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
278  if (codepoint <= 0xFFFF) {
279  RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
280  os.Put(static_cast<typename OutputStream::Ch>(codepoint));
281  }
282  else {
283  RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
284  unsigned v = codepoint - 0x10000;
285  os.Put(static_cast<typename OutputStream::Ch>((v >> 10) | 0xD800));
286  os.Put(static_cast<typename OutputStream::Ch>((v & 0x3FF) | 0xDC00));
287  }
288  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406

◆ EncodeUnsafe()

static void EncodeUnsafe ( OutputStream &  os,
unsigned  codepoint 
)
inlinestaticinherited

Definition at line 292 of file encodings.h.

292  {
293  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
294  if (codepoint <= 0xFFFF) {
295  RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
296  PutUnsafe(os, static_cast<typename OutputStream::Ch>(codepoint));
297  }
298  else {
299  RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
300  unsigned v = codepoint - 0x10000;
301  PutUnsafe(os, static_cast<typename OutputStream::Ch>((v >> 10) | 0xD800));
302  PutUnsafe(os, static_cast<typename OutputStream::Ch>((v & 0x3FF) | 0xDC00));
303  }
304  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

◆ Put()

static void Put ( OutputByteStream &  os,
CharType  c 
)
inlinestatic

Definition at line 366 of file encodings.h.

366  {
367  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
368  os.Put(static_cast<typename OutputByteStream::Ch>(static_cast<unsigned>(c) & 0xFFu));
369  os.Put(static_cast<typename OutputByteStream::Ch>((static_cast<unsigned>(c) >> 8) & 0xFFu));
370  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)

◆ PutBOM()

static void PutBOM ( OutputByteStream &  os)
inlinestatic

Definition at line 359 of file encodings.h.

359  {
360  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
361  os.Put(static_cast<typename OutputByteStream::Ch>(0xFFu));
362  os.Put(static_cast<typename OutputByteStream::Ch>(0xFEu));
363  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)

◆ RAPIDJSON_STATIC_ASSERT()

RAPIDJSON_STATIC_ASSERT ( sizeof(Ch) >=  2)
inherited

◆ Take()

static CharType Take ( InputByteStream &  is)
inlinestatic

Definition at line 351 of file encodings.h.

351  {
352  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
353  unsigned c = static_cast<uint8_t>(is.Take());
354  c |= static_cast<unsigned>(static_cast<uint8_t>(is.Take())) << 8;
355  return static_cast<CharType>(c);
356  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)
unsigned char uint8_t
Definition: stdint.h:124

◆ TakeBOM()

static CharType TakeBOM ( InputByteStream &  is)
inlinestatic

Definition at line 344 of file encodings.h.

344  {
345  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
346  CharType c = Take(is);
347  return static_cast<uint16_t>(c) == 0xFEFFu ? Take(is) : c;
348  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)
unsigned short uint16_t
Definition: stdint.h:125
static CharType Take(InputByteStream &is)
Definition: encodings.h:351
Here is the call graph for this function:

◆ Validate()

static bool Validate ( InputStream &  is,
OutputStream &  os 
)
inlinestaticinherited

Definition at line 325 of file encodings.h.

325  {
326  RAPIDJSON_STATIC_ASSERT(sizeof(typename InputStream::Ch) >= 2);
327  RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
328  typename InputStream::Ch c;
329  os.Put(static_cast<typename OutputStream::Ch>(c = is.Take()));
330  if (c < 0xD800 || c > 0xDFFF)
331  return true;
332  else if (c <= 0xDBFF) {
333  os.Put(c = is.Take());
334  return c >= 0xDC00 && c <= 0xDFFF;
335  }
336  return false;
337  }
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >=2)

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