mirror of
				https://github.com/Tencent/rapidjson.git
				synced 2025-10-28 19:52:02 +01:00 
			
		
		
		
	fix for Reader::ParseString() implementation plus some minor code cleanups and additions
				
					
				
			This commit is contained in:
		| @@ -14,7 +14,7 @@ | ||||
| using namespace rapidjson; | ||||
|  | ||||
| template<typename OutputHandler> | ||||
| struct CapitalizeFilter { | ||||
| struct CapitalizeFilter : public BaseReaderHandler<UTF8<>, OutputHandler> { | ||||
|     CapitalizeFilter(OutputHandler& out) : out_(out), buffer_() {} | ||||
|  | ||||
|     bool Null() { return out_.Null(); } | ||||
| @@ -31,7 +31,6 @@ struct CapitalizeFilter { | ||||
|         return out_.String(&buffer_.front(), length, true); // true = output handler need to copy the string | ||||
|     } | ||||
|     bool StartObject() { return out_.StartObject(); } | ||||
|     bool Key(const char* str, SizeType length, bool copy) { return String(str, length, copy); } | ||||
|     bool EndObject(SizeType memberCount) { return out_.EndObject(memberCount); } | ||||
|     bool StartArray() { return out_.StartArray(); } | ||||
|     bool EndArray(SizeType elementCount) { return out_.EndArray(elementCount); } | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
| using namespace rapidjson; | ||||
| using namespace std; | ||||
|  | ||||
| struct MyHandler { | ||||
| struct MyHandler : public BaseReaderHandler<UTF8<>, MyHandler> { | ||||
|     bool Null() { cout << "Null()" << endl; return true; } | ||||
|     bool Bool(bool b) { cout << "Bool(" << boolalpha << b << ")" << endl; return true; } | ||||
|     bool Int(int i) { cout << "Int(" << i << ")" << endl; return true; } | ||||
| @@ -17,7 +17,10 @@ struct MyHandler { | ||||
|         return true; | ||||
|     } | ||||
|     bool StartObject() { cout << "StartObject()" << endl; return true; } | ||||
|     bool Key(const char* str, SizeType length, bool copy) { return String(str, length, copy); } | ||||
|     bool Key(const char* str, SizeType length, bool copy) { | ||||
|         cout << "Key(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl; | ||||
|         return true; | ||||
|     } | ||||
|     bool EndObject(SizeType memberCount) { cout << "EndObject(" << memberCount << ")" << endl; return true; } | ||||
|     bool StartArray() { cout << "StartArray()" << endl; return true; } | ||||
|     bool EndArray(SizeType elementCount) { cout << "EndArray(" << elementCount << ")" << endl; return true; } | ||||
|   | ||||
| @@ -137,6 +137,7 @@ public: | ||||
|  | ||||
|     //! Simpler but slower overload. | ||||
|     bool String(const Ch* str) { return String(str, internal::StrLen(str)); } | ||||
|     bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); } | ||||
|  | ||||
|     //@} | ||||
| protected: | ||||
|   | ||||
| @@ -623,27 +623,25 @@ private: | ||||
|         internal::StreamLocalCopy<InputStream> copy(is); | ||||
|         InputStream& s(copy.s); | ||||
|  | ||||
|         const typename TargetEncoding::Ch* str = NULL; | ||||
|         SizeType len = 0; | ||||
|  | ||||
|         bool success = false; | ||||
|         if (parseFlags & kParseInsituFlag) { | ||||
|             typename InputStream::Ch *head = s.PutBegin(); | ||||
|             ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(s, s); | ||||
|             RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; | ||||
|             size_t length = s.PutEnd(head) - 1; | ||||
|             RAPIDJSON_ASSERT(length <= 0xFFFFFFFF); | ||||
|             str = (const typename TargetEncoding::Ch*)head; | ||||
|             len = SizeType(length); | ||||
|             const typename TargetEncoding::Ch* const str = (const typename TargetEncoding::Ch*)head; | ||||
|             success = (isKey ? handler.Key(str, SizeType(length), false) : handler.String(str, SizeType(length), false)); | ||||
|         } | ||||
|         else { | ||||
|             StackStream stackStream(stack_); | ||||
|             ParseStringToStream<parseFlags, SourceEncoding, TargetEncoding>(s, stackStream); | ||||
|             RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; | ||||
|             str = stack_.template Pop<typename TargetEncoding::Ch>(stackStream.length_); | ||||
|             len = stackStream.length_ - 1; | ||||
|             const typename TargetEncoding::Ch* const str = stack_.template Pop<typename TargetEncoding::Ch>(stackStream.length_); | ||||
|             success = (isKey ? handler.Key(str, stackStream.length_ - 1, false) : handler.String(str, stackStream.length_ - 1, false)); | ||||
|         } | ||||
|  | ||||
|         if(!(isKey ? handler.Key(str, len, false) : handler.String(str, len, false))) | ||||
|         if(!success) | ||||
|             RAPIDJSON_PARSE_ERROR(kParseErrorTermination, s.Tell()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -167,6 +167,7 @@ public: | ||||
|  | ||||
|     //! Simpler but slower overload. | ||||
|     bool String(const Ch* str) { return String(str, internal::StrLen(str)); } | ||||
|     bool Key(const Ch* str) { return Key(str, internal::StrLen(str)); } | ||||
|  | ||||
|     //@} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kosta
					Kosta