15#ifndef RAPIDJSON_ENCODEDSTREAM_H_
16#define RAPIDJSON_ENCODEDSTREAM_H_
23RAPIDJSON_DIAG_OFF(effc++)
28RAPIDJSON_DIAG_OFF(padded)
38template <
typename Encoding,
typename InputByteStream>
42 typedef typename Encoding::Ch
Ch;
45 current_ = Encoding::TakeBOM(is_);
49 Ch Take() {
Ch c = current_; current_ = Encoding::Take(is_);
return c; }
50 size_t Tell()
const {
return is_.Tell(); }
73 if (
static_cast<unsigned char>(is_.Peek()) == 0xEFu) is_.Take();
74 if (
static_cast<unsigned char>(is_.Peek()) == 0xBBu) is_.Take();
75 if (
static_cast<unsigned char>(is_.Peek()) == 0xBFu) is_.Take();
77 Ch Peek()
const {
return is_.Peek(); }
79 size_t Tell()
const {
return is_.Tell(); }
99template <
typename Encoding,
typename OutputByteStream>
103 typedef typename Encoding::Ch
Ch;
107 Encoding::PutBOM(os_);
110 void Put(
Ch c) { Encoding::Put(os_, c); }
124 OutputByteStream& os_;
127#define RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
134template <
typename CharType,
typename InputByteStream>
149 takeFunc_ =
f[type_];
150 current_ = takeFunc_(*is_);
157 Ch Take() {
Ch c = current_; current_ = takeFunc_(*is_);
return c; }
158 size_t Tell()
const {
return is_->Tell(); }
179 const unsigned char* c =
reinterpret_cast<const unsigned char *
>(is_->Peek4());
183 unsigned bom =
static_cast<unsigned>(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24));
185 if (bom == 0xFFFE0000) { type_ =
kUTF32BE; hasBOM_ =
true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
186 else if (bom == 0x0000FEFF) { type_ =
kUTF32LE; hasBOM_ =
true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
187 else if ((bom & 0xFFFF) == 0xFFFE) { type_ =
kUTF16BE; hasBOM_ =
true; is_->Take(); is_->Take(); }
188 else if ((bom & 0xFFFF) == 0xFEFF) { type_ =
kUTF16LE; hasBOM_ =
true; is_->Take(); is_->Take(); }
189 else if ((bom & 0xFFFFFF) == 0xBFBBEF) { type_ =
kUTF8; hasBOM_ =
true; is_->Take(); is_->Take(); is_->Take(); }
203 int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0);
209 case 0x0F: type_ =
kUTF8;
break;
219 typedef Ch (*TakeFunc)(InputByteStream& is);
220 InputByteStream* is_;
232template <
typename CharType,
typename OutputByteStream>
260 void Put(
Ch c) { putFunc_(*os_, c); }
275 typedef void (*PutBOMFunc)(OutputByteStream&);
280 typedef void (*PutFunc)(OutputByteStream&,
Ch);
282 OutputByteStream* os_;
287#undef RAPIDJSON_ENCODINGS_FUNC
Output stream wrapper with dynamically bound encoding and automatic encoding detection.
AutoUTFOutputStream(OutputByteStream &os, UTFType type, bool putBOM)
Constructor.
Output byte stream wrapper with statically bound encoding.
EncodedOutputStream(OutputByteStream &os, bool putBOM=true)
#define RAPIDJSON_ENCODINGS_FUNC(x)
UTFType
Runtime-specified UTF encoding type of a stream.
@ kUTF32BE
UTF-32 big endian.
@ kUTF16BE
UTF-16 big endian.
@ kUTF32LE
UTF-32 little endian.
@ kUTF16LE
UTF-16 little endian.
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Represents an in-memory input byte stream.