15 #ifndef RAPIDJSON_ENCODEDSTREAM_H_
16 #define RAPIDJSON_ENCODEDSTREAM_H_
23 RAPIDJSON_DIAG_OFF(effc++)
28 RAPIDJSON_DIAG_OFF(padded)
38 template <
typename Encoding,
typename InputByteStream>
41 RAPIDJSON_STATIC_ASSERT(
sizeof(
typename InputByteStream::Ch) == 1);
44 typedef typename Encoding::Ch
Ch;
52 current_ = Encoding::Take(is_);
55 size_t Tell()
const {
return is_.Tell(); }
88 if(
static_cast<unsigned char>(is_.Peek()) == 0xEFu)
90 if(
static_cast<unsigned char>(is_.Peek()) == 0xBBu)
92 if(
static_cast<unsigned char>(is_.Peek()) == 0xBFu)
95 Ch Peek()
const {
return is_.Peek(); }
97 size_t Tell()
const {
return is_.Tell(); }
118 template <
typename Encoding,
typename OutputByteStream>
121 RAPIDJSON_STATIC_ASSERT(
sizeof(
typename OutputByteStream::Ch) == 1);
124 typedef typename Encoding::Ch
Ch;
129 Encoding::PutBOM(os_);
132 void Put(
Ch c) { Encoding::Put(os_, c); }
166 OutputByteStream& os_;
169 #define RAPIDJSON_ENCODINGS_FUNC(x) \
170 UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
177 template <
typename CharType,
typename InputByteStream>
180 RAPIDJSON_STATIC_ASSERT(
sizeof(
typename InputByteStream::Ch) == 1);
191 : is_(&is), type_(type), hasBOM_(false)
196 takeFunc_ = f[type_];
197 current_ = takeFunc_(*is_);
207 current_ = takeFunc_(*is_);
210 size_t Tell()
const {
return is_->Tell(); }
240 const unsigned char* c =
reinterpret_cast<const unsigned char*
>(is_->Peek4());
244 unsigned bom =
static_cast<unsigned>(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24));
246 if(bom == 0xFFFE0000)
255 else if(bom == 0x0000FEFF)
264 else if((bom & 0xFFFF) == 0xFFFE)
271 else if((bom & 0xFFFF) == 0xFEFF)
278 else if((bom & 0xFFFFFF) == 0xBFBBEF)
300 int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0);
307 case 0x0F: type_ =
kUTF8;
break;
320 typedef Ch (*TakeFunc)(InputByteStream& is);
321 InputByteStream* is_;
333 template <
typename CharType,
typename OutputByteStream>
336 RAPIDJSON_STATIC_ASSERT(
sizeof(
typename OutputByteStream::Ch) == 1);
367 void Put(
Ch c) { putFunc_(*os_, c); }
403 typedef void (*PutBOMFunc)(OutputByteStream&);
408 typedef void (*PutFunc)(OutputByteStream&,
Ch);
410 OutputByteStream* os_;
415 #undef RAPIDJSON_ENCODINGS_FUNC
Output stream wrapper with dynamically bound encoding and automatic encoding detection.
Definition: encodedstream.h:335
AutoUTFOutputStream(OutputByteStream &os, UTFType type, bool putBOM)
Constructor.
Definition: encodedstream.h:347
void Flush()
Definition: encodedstream.h:368
Ch * PutBegin()
Definition: encodedstream.h:386
Ch Take()
Definition: encodedstream.h:376
size_t PutEnd(Ch *)
Definition: encodedstream.h:391
UTFType GetType() const
Definition: encodedstream.h:365
size_t Tell() const
Definition: encodedstream.h:381
CharType Ch
Definition: encodedstream.h:339
void Put(Ch c)
Definition: encodedstream.h:367
Ch Peek() const
Definition: encodedstream.h:371
Output byte stream wrapper with statically bound encoding.
Definition: encodedstream.h:120
void Put(Ch c)
Definition: encodedstream.h:132
size_t Tell() const
Definition: encodedstream.h:146
Ch Peek() const
Definition: encodedstream.h:136
void Flush()
Definition: encodedstream.h:133
Ch * PutBegin()
Definition: encodedstream.h:151
size_t PutEnd(Ch *)
Definition: encodedstream.h:156
Ch Take()
Definition: encodedstream.h:141
Encoding::Ch Ch
Definition: encodedstream.h:124
EncodedOutputStream(OutputByteStream &os, bool putBOM=true)
Definition: encodedstream.h:126
#define RAPIDJSON_ENCODINGS_FUNC(x)
Definition: encodedstream.h:169
UTFType
Runtime-specified UTF encoding type of a stream.
Definition: encodings.h:757
@ kUTF32BE
UTF-32 big endian.
Definition: encodings.h:762
@ kUTF16BE
UTF-16 big endian.
Definition: encodings.h:760
@ kUTF8
UTF-8.
Definition: encodings.h:758
@ kUTF32LE
UTF-32 little endian.
Definition: encodings.h:761
@ kUTF16LE
UTF-16 little endian.
Definition: encodings.h:759
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:451
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
Represents an in-memory input byte stream.
Definition: memorystream.h:42
UTF-8 encoding.
Definition: encodings.h:98
CharType Ch
Definition: encodings.h:99