From b16ff281f854564e2669b2c3f4871793ddc51fc3 Mon Sep 17 00:00:00 2001 From: KaitoHH Date: Tue, 26 Sep 2017 15:39:06 +0800 Subject: [PATCH 1/7] Add feature of locating line and column number of error --- include/rapidjson/document.h | 11 ++++++++- include/rapidjson/error/error.h | 8 +++++++ include/rapidjson/stream.h | 42 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 93b091f..de65740 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -2219,14 +2219,17 @@ public: \return The document itself for fluent API. */ template - GenericDocument& ParseStream(InputStream& is) { + GenericDocument& ParseStream(InputStream& is_) { GenericReader reader( stack_.HasAllocator() ? &stack_.GetAllocator() : 0); ClearStackOnExit scope(*this); + GenericStreamWrapper is(is_); parseResult_ = reader.template Parse(is, *this); if (parseResult_) { RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object ValueType::operator=(*stack_.template Pop(1));// Move value from stack to document + } else { + parseResult_.SetPos(is.line_, is.col_); } return *this; } @@ -2355,6 +2358,12 @@ public: //! Get the position of last parsing error in input, 0 otherwise. size_t GetErrorOffset() const { return parseResult_.Offset(); } + + //! Get the position of last parsing error in input, 0 otherwise. + size_t GetErrorLine() const { return parseResult_.Line(); } + + //! Get the position of last parsing error in input, 0 otherwise. + size_t GetErrorColumn() const { return parseResult_.Col(); } //! Implicit conversion to get the last parse result #ifndef __clang // -Wdocumentation diff --git a/include/rapidjson/error/error.h b/include/rapidjson/error/error.h index 9311d2f..be80579 100644 --- a/include/rapidjson/error/error.h +++ b/include/rapidjson/error/error.h @@ -116,6 +116,10 @@ public: ParseErrorCode Code() const { return code_; } //! Get the error offset, if \ref IsError(), 0 otherwise. size_t Offset() const { return offset_; } + //! Get the position of line number if error exists. + size_t Line() const { return line_; } + //! Get the position of column number if error exists. + size_t Col() const { return col_; } //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } @@ -134,10 +138,14 @@ public: void Clear() { Set(kParseErrorNone); } //! Update error code and offset. void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } + //! Update line number and column number of the error position + void SetPos(size_t line, size_t col) { line_ = line; col_ = col; } private: ParseErrorCode code_; size_t offset_; + size_t line_; + size_t col_; }; //! Function pointer type of GetParseError(). diff --git a/include/rapidjson/stream.h b/include/rapidjson/stream.h index fef82c2..4e4ba80 100644 --- a/include/rapidjson/stream.h +++ b/include/rapidjson/stream.h @@ -100,6 +100,48 @@ inline void PutN(Stream& stream, Ch c, size_t n) { PutUnsafe(stream, c); } +/////////////////////////////////////////////////////////////////////////////// +// GenericStreamWrapper + +//! A Stream Wrapper +/*! \tThis string stream is designed for counting line and column number + \tof the error (if exists) position, while just forwarding any received + \tmessage to the origin stream. + \note implements Stream concept +*/ +template +class GenericStreamWrapper { +public: + typedef typename Encoding::Ch Ch; + size_t line_; + size_t col_; + GenericStreamWrapper(InputStream& is): is_(is), line_(1), col_(0) {} + + Ch Peek() const { return is_.Peek(); } + + // counting line and column number + Ch Take() { + Ch ch = is_.Take(); + if(ch == '\n') { + line_ ++; + col_ = 0; + } else { + col_ ++; + } + return ch; + } + size_t Tell() { return is_.Tell(); } + + Ch* PutBegin() { return is_.PutBegin(); } + void Put(Ch ch) { return is_.Put(ch); } + void Flush() { return is_.Flush(); } + size_t PutEnd(Ch* ch) { is_.PutEnd(ch); } + + const Ch* Peek4() const { is_.Peek4(); } +private: + InputStream& is_; +}; + /////////////////////////////////////////////////////////////////////////////// // StringStream From 79d9c71f98b0f1cfea5fae2fe33595efcbf79028 Mon Sep 17 00:00:00 2001 From: KaitoHH Date: Tue, 26 Sep 2017 16:03:09 +0800 Subject: [PATCH 2/7] fix stream wrapper initializer fix initialization warning add special wrapper for AutoUTFInputStream --- include/rapidjson/error/error.h | 4 ++-- include/rapidjson/stream.h | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/rapidjson/error/error.h b/include/rapidjson/error/error.h index be80579..618a6cf 100644 --- a/include/rapidjson/error/error.h +++ b/include/rapidjson/error/error.h @@ -108,9 +108,9 @@ struct ParseResult { typedef bool (ParseResult::*BooleanType)() const; public: //! Default constructor, no error. - ParseResult() : code_(kParseErrorNone), offset_(0) {} + ParseResult() : code_(kParseErrorNone), offset_(0), line_(0), col_(0) {} //! Constructor to set an error. - ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} + ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset), line_(0), col_(0) {} //! Get the error code. ParseErrorCode Code() const { return code_; } diff --git a/include/rapidjson/stream.h b/include/rapidjson/stream.h index 4e4ba80..a315d3f 100644 --- a/include/rapidjson/stream.h +++ b/include/rapidjson/stream.h @@ -115,7 +115,7 @@ public: typedef typename Encoding::Ch Ch; size_t line_; size_t col_; - GenericStreamWrapper(InputStream& is): is_(is), line_(1), col_(0) {} + GenericStreamWrapper(InputStream& is): line_(1), col_(0), is_(is) {} Ch Peek() const { return is_.Peek(); } @@ -133,11 +133,17 @@ public: size_t Tell() { return is_.Tell(); } Ch* PutBegin() { return is_.PutBegin(); } - void Put(Ch ch) { return is_.Put(ch); } - void Flush() { return is_.Flush(); } - size_t PutEnd(Ch* ch) { is_.PutEnd(ch); } + void Put(Ch ch) { is_.Put(ch); } + void Flush() { is_.Flush(); } + size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } - const Ch* Peek4() const { is_.Peek4(); } + // wrapper for MemoryStream + const Ch* Peek4() const { return is_.Peek4(); } + + // wrapper for AutoUTFInputStream + UTFType GetType() const { return is_.GetType(); } + bool HasBOM() const { return is_.HasBOM(); } + private: InputStream& is_; }; From 143641c75abaf6f111c79152b76996324ed3ad19 Mon Sep 17 00:00:00 2001 From: KaitoHH Date: Wed, 27 Sep 2017 13:58:16 +0800 Subject: [PATCH 3/7] suppress C4512, C4702 warning --- include/rapidjson/stream.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/stream.h b/include/rapidjson/stream.h index a315d3f..556c30a 100644 --- a/include/rapidjson/stream.h +++ b/include/rapidjson/stream.h @@ -109,6 +109,12 @@ inline void PutN(Stream& stream, Ch c, size_t n) { \tmessage to the origin stream. \note implements Stream concept */ + +#if defined(_MSC_VER) && _MSC_VER <= 1700 +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4702) // disable unreachable code +#endif + template class GenericStreamWrapper { public: @@ -135,7 +141,7 @@ public: Ch* PutBegin() { return is_.PutBegin(); } void Put(Ch ch) { is_.Put(ch); } void Flush() { is_.Flush(); } - size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } + size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } // wrapper for MemoryStream const Ch* Peek4() const { return is_.Peek4(); } @@ -146,8 +152,17 @@ public: private: InputStream& is_; + + // elimante vs2010-2013 C4512 warning by + // prohibiting copy constructor & assignment operator. + GenericStreamWrapper& operator=(const GenericStreamWrapper &); + GenericStreamWrapper(const GenericStreamWrapper&); }; +#if defined(_MSC_VER) && _MSC_VER <= 1700 +RAPIDJSON_DIAG_POP +#endif + /////////////////////////////////////////////////////////////////////////////// // StringStream From 799fdea9fc05aa74c2ebfb49340943195ac2e1dc Mon Sep 17 00:00:00 2001 From: KaitoHH Date: Thu, 28 Sep 2017 16:57:52 +0800 Subject: [PATCH 4/7] add cursor wrapper --- include/rapidjson/cursorstreamwrapper.h | 59 +++++++++++++++++++++++++ include/rapidjson/document.h | 11 +---- include/rapidjson/error/error.h | 12 +---- include/rapidjson/stream.h | 37 +++++----------- 4 files changed, 72 insertions(+), 47 deletions(-) create mode 100644 include/rapidjson/cursorstreamwrapper.h diff --git a/include/rapidjson/cursorstreamwrapper.h b/include/rapidjson/cursorstreamwrapper.h new file mode 100644 index 0000000..5c752af --- /dev/null +++ b/include/rapidjson/cursorstreamwrapper.h @@ -0,0 +1,59 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_ +#define RAPIDJSON_CURSORSTREAMWRAPPER_H_ + +#include "stream.h" + +RAPIDJSON_NAMESPACE_BEGIN + + +//! Cursor stream wrapper for counting line and column number if error exists. +/*! + \tparam InputStream Any stream that implements Stream Concept +*/ +template > +class CursorStreamWrapper : public GenericStreamWrapper { +public: + typedef typename Encoding::Ch Ch; + + CursorStreamWrapper(InputStream& is): + GenericStreamWrapper(is), line_(1), col_(0) {} + + // counting line and column number + Ch Take() { + Ch ch = this->is_.Take(); + if(ch == '\n') { + line_ ++; + col_ = 0; + } else { + col_ ++; + } + return ch; + } + + //! Get the error line number, if error exists. + size_t GetLine() const { return line_; } + //! Get the error column number, if error exists. + size_t GetColumn() const { return col_; } + +private: + size_t line_; //!< Current Line + size_t col_; //!< Current Column +}; + +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index de65740..93b091f 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -2219,17 +2219,14 @@ public: \return The document itself for fluent API. */ template - GenericDocument& ParseStream(InputStream& is_) { + GenericDocument& ParseStream(InputStream& is) { GenericReader reader( stack_.HasAllocator() ? &stack_.GetAllocator() : 0); ClearStackOnExit scope(*this); - GenericStreamWrapper is(is_); parseResult_ = reader.template Parse(is, *this); if (parseResult_) { RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object ValueType::operator=(*stack_.template Pop(1));// Move value from stack to document - } else { - parseResult_.SetPos(is.line_, is.col_); } return *this; } @@ -2358,12 +2355,6 @@ public: //! Get the position of last parsing error in input, 0 otherwise. size_t GetErrorOffset() const { return parseResult_.Offset(); } - - //! Get the position of last parsing error in input, 0 otherwise. - size_t GetErrorLine() const { return parseResult_.Line(); } - - //! Get the position of last parsing error in input, 0 otherwise. - size_t GetErrorColumn() const { return parseResult_.Col(); } //! Implicit conversion to get the last parse result #ifndef __clang // -Wdocumentation diff --git a/include/rapidjson/error/error.h b/include/rapidjson/error/error.h index 618a6cf..9311d2f 100644 --- a/include/rapidjson/error/error.h +++ b/include/rapidjson/error/error.h @@ -108,18 +108,14 @@ struct ParseResult { typedef bool (ParseResult::*BooleanType)() const; public: //! Default constructor, no error. - ParseResult() : code_(kParseErrorNone), offset_(0), line_(0), col_(0) {} + ParseResult() : code_(kParseErrorNone), offset_(0) {} //! Constructor to set an error. - ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset), line_(0), col_(0) {} + ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} //! Get the error code. ParseErrorCode Code() const { return code_; } //! Get the error offset, if \ref IsError(), 0 otherwise. size_t Offset() const { return offset_; } - //! Get the position of line number if error exists. - size_t Line() const { return line_; } - //! Get the position of column number if error exists. - size_t Col() const { return col_; } //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } @@ -138,14 +134,10 @@ public: void Clear() { Set(kParseErrorNone); } //! Update error code and offset. void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } - //! Update line number and column number of the error position - void SetPos(size_t line, size_t col) { line_ = line; col_ = col; } private: ParseErrorCode code_; size_t offset_; - size_t line_; - size_t col_; }; //! Function pointer type of GetParseError(). diff --git a/include/rapidjson/stream.h b/include/rapidjson/stream.h index 556c30a..f492797 100644 --- a/include/rapidjson/stream.h +++ b/include/rapidjson/stream.h @@ -104,40 +104,28 @@ inline void PutN(Stream& stream, Ch c, size_t n) { // GenericStreamWrapper //! A Stream Wrapper -/*! \tThis string stream is designed for counting line and column number - \tof the error (if exists) position, while just forwarding any received - \tmessage to the origin stream. +/*! \tThis string stream is a wrapper for any stream by just forwarding any + \treceived message to the origin stream. \note implements Stream concept */ -#if defined(_MSC_VER) && _MSC_VER <= 1700 +#if defined(_MSC_VER) && _MSC_VER <= 1800 RAPIDJSON_DIAG_PUSH -RAPIDJSON_DIAG_OFF(4702) // disable unreachable code +RAPIDJSON_DIAG_OFF(4702) // unreachable code +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated #endif -template +template > class GenericStreamWrapper { public: typedef typename Encoding::Ch Ch; size_t line_; size_t col_; - GenericStreamWrapper(InputStream& is): line_(1), col_(0), is_(is) {} + GenericStreamWrapper(InputStream& is): is_(is) {} Ch Peek() const { return is_.Peek(); } - - // counting line and column number - Ch Take() { - Ch ch = is_.Take(); - if(ch == '\n') { - line_ ++; - col_ = 0; - } else { - col_ ++; - } - return ch; - } + Ch Take() { return is_.Take(); } size_t Tell() { return is_.Tell(); } - Ch* PutBegin() { return is_.PutBegin(); } void Put(Ch ch) { is_.Put(ch); } void Flush() { is_.Flush(); } @@ -150,16 +138,11 @@ public: UTFType GetType() const { return is_.GetType(); } bool HasBOM() const { return is_.HasBOM(); } -private: +protected: InputStream& is_; - - // elimante vs2010-2013 C4512 warning by - // prohibiting copy constructor & assignment operator. - GenericStreamWrapper& operator=(const GenericStreamWrapper &); - GenericStreamWrapper(const GenericStreamWrapper&); }; -#if defined(_MSC_VER) && _MSC_VER <= 1700 +#if defined(_MSC_VER) && _MSC_VER <= 1800 RAPIDJSON_DIAG_POP #endif From 66541b8926c349cea4bee16630a3d38693da4588 Mon Sep 17 00:00:00 2001 From: KaitoHH Date: Fri, 29 Sep 2017 17:24:07 +0800 Subject: [PATCH 5/7] add unit test for cursorstreamwrapper --- test/unittest/CMakeLists.txt | 1 + test/unittest/cursorstreamwrappertest.cpp | 115 ++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 test/unittest/cursorstreamwrappertest.cpp diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index fdf0ad0..072b7b1 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -3,6 +3,7 @@ include(CheckCXXCompilerFlag) set(UNITTEST_SOURCES allocatorstest.cpp bigintegertest.cpp + cursorstreamwrappertest.cpp documenttest.cpp dtoatest.cpp encodedstreamtest.cpp diff --git a/test/unittest/cursorstreamwrappertest.cpp b/test/unittest/cursorstreamwrappertest.cpp new file mode 100644 index 0000000..a116248 --- /dev/null +++ b/test/unittest/cursorstreamwrappertest.cpp @@ -0,0 +1,115 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#include "unittest.h" +#include "rapidjson/document.h" +#include "rapidjson/cursorstreamwrapper.h" + +using namespace rapidjson; + +// static const char json[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}"; + +bool testJson(const char *json, size_t &line, size_t &col) { + StringStream ss(json); + CursorStreamWrapper csw(ss); + Document document; + document.ParseStream(csw); + bool ret = document.HasParseError(); + if (ret) { + col = csw.GetColumn(); + line = csw.GetLine(); + } + return ret; +} + +TEST(CursorStreamWrapper, MissingFirstBracket) { + const char json[] = "\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}"; + size_t col, line; + bool ret = testJson(json, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 3); + EXPECT_EQ(col, 0); +} + +TEST(CursorStreamWrapper, MissingQuotes) { + const char json[] = "{\"string\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}"; + size_t col, line; + bool ret = testJson(json, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 1); + EXPECT_EQ(col, 8); +} + +TEST(CursorStreamWrapper, MissingColon) { + const char json[] = "{\"string\"\n\n\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}"; + size_t col, line; + bool ret = testJson(json, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 3); + EXPECT_EQ(col, 0); +} + +TEST(CursorStreamWrapper, MissingSecondQuotes) { + const char json[] = "{\"string\"\n\n:my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}"; + size_t col, line; + bool ret = testJson(json, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 3); + EXPECT_EQ(col, 1); +} + +TEST(CursorStreamWrapper, MissingComma) { + const char json[] = "{\"string\"\n\n:\"my string\"\"array\"\n:[\"1\", \"2\", \"3\"]}"; + size_t col, line; + bool ret = testJson(json, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 3); + EXPECT_EQ(col, 12); +} + +TEST(CursorStreamWrapper, MissingArrayBracket) { + const char json[] = "{\"string\"\n\n:\"my string\",\"array\"\n:\"1\", \"2\", \"3\"]}"; + size_t col, line; + bool ret = testJson(json, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 4); + EXPECT_EQ(col, 9); +} + +TEST(CursorStreamWrapper, MissingArrayComma) { + const char json[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\" \"2\", \"3\"]}"; + size_t col, line; + bool ret = testJson(json, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 4); + EXPECT_EQ(col, 6); +} + +TEST(CursorStreamWrapper, MissingLastArrayBracket) { + const char json8[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"}"; + size_t col, line; + bool ret = testJson(json8, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 4); + EXPECT_EQ(col, 15); +} + +TEST(CursorStreamWrapper, MissingLastBracket) { + const char json9[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]"; + size_t col, line; + bool ret = testJson(json9, line, col); + EXPECT_TRUE(ret); + EXPECT_EQ(line, 4); + EXPECT_EQ(col, 16); +} From 9394b84440fcbf4c2db80049e46c36a78bda04b8 Mon Sep 17 00:00:00 2001 From: KaitoHH Date: Fri, 29 Sep 2017 18:19:41 +0800 Subject: [PATCH 6/7] remove unnecessary code --- include/rapidjson/stream.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/rapidjson/stream.h b/include/rapidjson/stream.h index f492797..7f2643e 100644 --- a/include/rapidjson/stream.h +++ b/include/rapidjson/stream.h @@ -1,5 +1,5 @@ // Tencent is pleased to support the open source community by making RapidJSON available. -// +// // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. // // Licensed under the MIT License (the "License"); you may not use this file except @@ -7,9 +7,9 @@ // // http://opensource.org/licenses/MIT // -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. #include "rapidjson.h" @@ -104,7 +104,7 @@ inline void PutN(Stream& stream, Ch c, size_t n) { // GenericStreamWrapper //! A Stream Wrapper -/*! \tThis string stream is a wrapper for any stream by just forwarding any +/*! \tThis string stream is a wrapper for any stream by just forwarding any \treceived message to the origin stream. \note implements Stream concept */ @@ -119,10 +119,8 @@ template > class GenericStreamWrapper { public: typedef typename Encoding::Ch Ch; - size_t line_; - size_t col_; GenericStreamWrapper(InputStream& is): is_(is) {} - + Ch Peek() const { return is_.Peek(); } Ch Take() { return is_.Take(); } size_t Tell() { return is_.Tell(); } @@ -130,10 +128,10 @@ public: void Put(Ch ch) { is_.Put(ch); } void Flush() { is_.Flush(); } size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } - + // wrapper for MemoryStream const Ch* Peek4() const { return is_.Peek4(); } - + // wrapper for AutoUTFInputStream UTFType GetType() const { return is_.GetType(); } bool HasBOM() const { return is_.HasBOM(); } From 473553bd5ae255217d4176666bff604faa464826 Mon Sep 17 00:00:00 2001 From: KaitoHH Date: Fri, 29 Sep 2017 19:13:29 +0800 Subject: [PATCH 7/7] fix gcc & cl warning --- include/rapidjson/cursorstreamwrapper.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/cursorstreamwrapper.h b/include/rapidjson/cursorstreamwrapper.h index 5c752af..52c11a7 100644 --- a/include/rapidjson/cursorstreamwrapper.h +++ b/include/rapidjson/cursorstreamwrapper.h @@ -17,6 +17,17 @@ #include "stream.h" +#if defined(__GNUC__) +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(effc++) +#endif + +#if defined(_MSC_VER) && _MSC_VER <= 1800 +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(4702) // unreachable code +RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated +#endif + RAPIDJSON_NAMESPACE_BEGIN @@ -29,9 +40,9 @@ class CursorStreamWrapper : public GenericStreamWrapper { public: typedef typename Encoding::Ch Ch; - CursorStreamWrapper(InputStream& is): + CursorStreamWrapper(InputStream& is): GenericStreamWrapper(is), line_(1), col_(0) {} - + // counting line and column number Ch Take() { Ch ch = this->is_.Take(); @@ -54,6 +65,14 @@ private: size_t col_; //!< Current Column }; +#if defined(_MSC_VER) && _MSC_VER <= 1800 +RAPIDJSON_DIAG_POP +#endif + +#if defined(__GNUC__) +RAPIDJSON_DIAG_POP +#endif + RAPIDJSON_NAMESPACE_END #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_