21 #ifndef RAPIDJSON_ENCODEDSTREAM_H_ 22 #define RAPIDJSON_ENCODEDSTREAM_H_ 28 RAPIDJSON_DIAG_OFF(effc++)
38 template <
typename Encoding,
typename InputByteStream>
40 RAPIDJSON_STATIC_ASSERT(
sizeof(
typename InputByteStream::Ch) == 1);
42 typedef typename Encoding::Ch Ch;
45 current_ = Encoding::TakeBOM(is_);
48 Ch Peek()
const {
return current_; }
49 Ch Take() { Ch c = current_; current_ = Encoding::Take(is_);
return c; }
50 size_t Tell()
const {
return is_.Tell(); }
71 template <
typename Encoding,
typename OutputByteStream>
75 typedef typename Encoding::Ch Ch;
79 Encoding::PutBOM(os_);
82 void Put(Ch c) { Encoding::Put(os_, c); }
83 void Flush() { os_.Flush(); }
96 OutputByteStream& os_;
99 #define RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x 106 template <
typename CharType,
typename InputByteStream>
119 static const TakeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Take) };
120 takeFunc_ = f[type_];
121 current_ = takeFunc_(*is_);
124 UTFType GetType()
const {
return type_; }
125 bool HasBOM()
const {
return hasBOM_; }
127 Ch Peek()
const {
return current_; }
128 Ch Take() { Ch c = current_; current_ = takeFunc_(*is_);
return c; }
129 size_t Tell()
const {
return is_->Tell(); }
150 const unsigned char* c = (
const unsigned char *)is_->Peek4();
154 unsigned bom = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
156 if (bom == 0xFFFE0000) { type_ =
kUTF32BE; hasBOM_ =
true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
157 else if (bom == 0x0000FEFF) { type_ =
kUTF32LE; hasBOM_ =
true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
158 else if ((bom & 0xFFFF) == 0xFFFE) { type_ =
kUTF16BE; hasBOM_ =
true; is_->Take(); is_->Take(); }
159 else if ((bom & 0xFFFF) == 0xFEFF) { type_ =
kUTF16LE; hasBOM_ =
true; is_->Take(); is_->Take(); }
160 else if ((bom & 0xFFFFFF) == 0xBFBBEF) { type_ =
kUTF8; hasBOM_ =
true; is_->Take(); is_->Take(); is_->Take(); }
174 unsigned pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0);
180 case 0x0F: type_ =
kUTF8;
break;
203 typedef Ch (*TakeFunc)(InputByteStream& is);
204 InputByteStream* is_;
216 template <
typename CharType,
typename OutputByteStream>
246 static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) };
253 UTFType GetType()
const {
return type_; }
255 void Put(Ch c) { putFunc_(*os_, c); }
256 void Flush() { os_->Flush(); }
270 typedef void (*PutBOMFunc)(OutputByteStream&);
271 static const PutBOMFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(PutBOM) };
275 typedef void (*PutFunc)(OutputByteStream&, Ch);
277 OutputByteStream* os_;
282 #undef RAPIDJSON_ENCODINGS_FUNC 290 #endif // RAPIDJSON_FILESTREAM_H_ UTF-16 little endian.
Definition: encodings.h:545
AutoUTFOutputStream(OutputByteStream &os, UTFType type, bool putBOM)
Constructor.
Definition: encodedstream.h:228
UTF-32 little endian.
Definition: encodings.h:547
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition: rapidjson.h:301
Output byte stream wrapper with statically bound encoding.
Definition: encodedstream.h:72
UTF-8.
Definition: encodings.h:544
main RapidJSON namespace
Definition: rapidjson.h:241
UTF-16 big endian.
Definition: encodings.h:546
common definitions and configuration
Output stream wrapper with dynamically bound encoding and automatic encoding detection.
Definition: encodedstream.h:217
UTF-32 big endian.
Definition: encodings.h:548
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:269
UTFType
Runtime-specified UTF encoding type of a stream.
Definition: encodings.h:543