Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Yip <miloyip@gmail.com>2016-02-15 15:21:36 +0300
committerMilo Yip <miloyip@gmail.com>2016-02-15 15:21:36 +0300
commit48378b751e55346fba28e29019a441e080246ed0 (patch)
treecbb3cea5c85da49ceda8ceb5e59afdcbb53c10c5 /include/rapidjson/encodedstream.h
parent9fe18f71c1177050ce2d25c4fbe74cca8a1c34a4 (diff)
Optimize the new Parse() interfaces
Diffstat (limited to 'include/rapidjson/encodedstream.h')
-rw-r--r--include/rapidjson/encodedstream.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h
index 87c90671..5d4e7799 100644
--- a/include/rapidjson/encodedstream.h
+++ b/include/rapidjson/encodedstream.h
@@ -16,6 +16,7 @@
#define RAPIDJSON_ENCODEDSTREAM_H_
#include "stream.h"
+#include "memorystream.h"
#ifdef __GNUC__
RAPIDJSON_DIAG_PUSH
@@ -62,6 +63,30 @@ private:
Ch current_;
};
+//! Specialized for UTF8 MemoryStream.
+template <>
+class EncodedInputStream<UTF8<>, MemoryStream> {
+public:
+ typedef typename UTF8<>::Ch Ch;
+
+ EncodedInputStream(MemoryStream& is) : is_(is) {
+ if (static_cast<unsigned char>(is_.Peek()) == 0xEFu) is_.Take();
+ if (static_cast<unsigned char>(is_.Peek()) == 0xBBu) is_.Take();
+ if (static_cast<unsigned char>(is_.Peek()) == 0xBFu) is_.Take();
+ }
+ Ch Peek() const { return is_.Peek(); }
+ Ch Take() { return is_.Take(); }
+ size_t Tell() const { return is_.Tell(); }
+
+ // Not implemented
+ void Put(Ch) {}
+ void Flush() {}
+ Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
+ size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
+
+ MemoryStream& is_;
+};
+
//! Output byte stream wrapper with statically bound encoding.
/*!
\tparam Encoding The interpretation of encoding of the stream. Either UTF8, UTF16LE, UTF16BE, UTF32LE, UTF32BE.