diff --git a/CMakeLists.txt b/CMakeLists.txt index a5061d42..f8927b49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) if(POLICY CMP0025) # detect Apple's Clang cmake_policy(SET CMP0025 NEW) diff --git a/bin/unittestschema/address.json b/bin/unittestschema/address.json index 85c46699..abec3ec5 100644 --- a/bin/unittestschema/address.json +++ b/bin/unittestschema/address.json @@ -130,6 +130,9 @@ "phone_type": { "pattern": "^[0-9]*-[0-9]*", "type": "string" + }, + "url_type": { + "type": "string" } } } \ No newline at end of file diff --git a/example/schemavalidator/schemavalidator.cpp b/example/schemavalidator/schemavalidator.cpp index 8c7e26c7..6ce3c39e 100644 --- a/example/schemavalidator/schemavalidator.cpp +++ b/example/schemavalidator/schemavalidator.cpp @@ -41,7 +41,8 @@ static std::string GetString(const ValueType& val) { s << "false"; else if (val.IsFloat()) s << val.GetFloat(); - return s.str();} + return s.str(); +} // Create the error message for a named error // The error object can either be empty or contain at least member properties: diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index 133df80c..05b1704d 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -57,10 +57,10 @@ static const SizeType kPointerInvalidIndex = ~SizeType(0); //!< Represents an i supplied tokens eliminates these. GenericPointer depends on GenericDocument and GenericValue. - + \tparam ValueType The value type of the DOM tree. E.g. GenericValue > \tparam Allocator The allocator type for allocating memory for internal representation. - + \note GenericPointer uses same encoding of ValueType. However, Allocator of GenericPointer is independent of Allocator of Value. */ @@ -72,7 +72,7 @@ public: typedef GenericUri UriType; - //! A token is the basic units of internal representation. + //! A token is the basic units of internal representation. /*! A JSON pointer string representation "/foo/123" is parsed to two tokens: "foo" and 123. 123 will be represented in both numeric form and string form. @@ -689,7 +689,7 @@ public: ValueType& GetWithDefault(GenericDocument& document, const Ch* defaultValue) const { return GetWithDefault(document, defaultValue, document.GetAllocator()); } - + #if RAPIDJSON_HAS_STDSTRING //! Query a value in a document with default std::basic_string. template @@ -983,7 +983,7 @@ private: } i++; - + // Escaping "~0" -> '~', "~1" -> '/' if (c == '~') { if (i < length) { diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index a4e89532..5ea69479 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.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. // // 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. #ifndef RAPIDJSON_RAPIDJSON_H_ @@ -17,7 +17,7 @@ /*!\file rapidjson.h \brief common definitions and configuration - + \see RAPIDJSON_CONFIG */ @@ -195,7 +195,7 @@ */ #ifndef RAPIDJSON_NO_INT64DEFINE //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013 +#if defined(_MSC_VER) && (_MSC_VER < 1800) // Visual Studio 2013 #include "msinttypes/stdint.h" #include "msinttypes/inttypes.h" #else @@ -277,7 +277,7 @@ # elif defined(RAPIDJSON_DOXYGEN_RUNNING) # define RAPIDJSON_ENDIAN # else -# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. +# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN. # endif #endif // RAPIDJSON_ENDIAN @@ -513,7 +513,7 @@ RAPIDJSON_NAMESPACE_END //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -#define RAPIDJSON_MULTILINEMACRO_BEGIN do { +#define RAPIDJSON_MULTILINEMACRO_BEGIN do { #define RAPIDJSON_MULTILINEMACRO_END \ } while((void)0, 0) @@ -731,7 +731,7 @@ enum Type { kFalseType = 1, //!< false kTrueType = 2, //!< true kObjectType = 3, //!< object - kArrayType = 4, //!< array + kArrayType = 4, //!< array kStringType = 5, //!< string kNumberType = 6 //!< number }; diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index c55e6a77..a57a727b 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -50,10 +50,6 @@ #define RAPIDJSON_SCHEMA_VERBOSE 0 #endif -#if RAPIDJSON_SCHEMA_VERBOSE -#include "stringbuffer.h" -#endif - RAPIDJSON_DIAG_PUSH #if defined(__GNUC__) @@ -1309,6 +1305,8 @@ private: else if (type == GetNumberString() ) type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType); } + // Creates parallel validators for allOf, anyOf, oneOf, not and schema dependencies, if required. + // Also creates a hasher for enums and array uniqueness, if required. bool CreateParallelValidator(Context& context) const { if (enum_ || context.arrayUniqueness) context.hasher = context.factory.CreateHasher(); diff --git a/test/unittest/ostreamwrappertest.cpp b/test/unittest/ostreamwrappertest.cpp index c9bc5f4b..be9e429c 100644 --- a/test/unittest/ostreamwrappertest.cpp +++ b/test/unittest/ostreamwrappertest.cpp @@ -77,7 +77,7 @@ static void TestFileStream() { } fp = fopen(filename, "r"); - ASSERT_TRUE( fp != NULL ); + ASSERT_TRUE( fp != NULL ); for (const char* p = s; *p; p++) EXPECT_EQ(*p, static_cast(fgetc(fp))); fclose(fp); diff --git a/test/unittest/pointertest.cpp b/test/unittest/pointertest.cpp index 2c90caee..c35fa8f5 100644 --- a/test/unittest/pointertest.cpp +++ b/test/unittest/pointertest.cpp @@ -475,7 +475,7 @@ TEST(Pointer, CopyConstructor) { EXPECT_EQ(1u, q.GetTokens()[1].length); EXPECT_STREQ("0", q.GetTokens()[1].name); EXPECT_EQ(0u, q.GetTokens()[1].index); - + // Copied pointer needs to have its own allocator EXPECT_NE(&p.GetAllocator(), &q.GetAllocator()); } @@ -1727,4 +1727,4 @@ TEST(Pointer, Issue1899) { EXPECT_TRUE(PointerType("/foo/1234") == q); q = q.Append(""); EXPECT_TRUE(PointerType("/foo/1234/") == q); -} \ No newline at end of file +} diff --git a/test/unittest/uritest.cpp b/test/unittest/uritest.cpp index 5506aa1e..d6c92a2d 100644 --- a/test/unittest/uritest.cpp +++ b/test/unittest/uritest.cpp @@ -191,7 +191,7 @@ TEST(Uri, Parse_UTF16) { #if RAPIDJSON_HAS_STDSTRING typedef std::basic_string String; String str = L"http://auth/path/xxx?query#frag"; - const UriType uri = UriType(str); + const UriType uri = UriType(str, &allocator); EXPECT_TRUE(UriType::GetScheme(uri) == L"http:"); EXPECT_TRUE(UriType::GetAuth(uri) == L"//auth"); EXPECT_TRUE(UriType::GetPath(uri) == L"/path/xxx"); diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index 9211419a..13ae1d40 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -1060,7 +1060,7 @@ static void TestArray(T& x, Allocator& allocator) { x.Clear(); for (unsigned i = 0; i < n; i++) x.PushBack(Value(kArrayType).PushBack(i, allocator).Move(), allocator); - + itr = x.Erase(x.Begin() + first, x.Begin() + last); if (last == n) EXPECT_EQ(x.End(), itr); @@ -1556,7 +1556,7 @@ TEST(Value, ObjectHelper) { EXPECT_STREQ("apple", y["a"].GetString()); EXPECT_TRUE(x.IsObject()); // Invariant } - + { Value x(kObjectType); x.AddMember("a", "apple", allocator); @@ -1674,7 +1674,7 @@ TEST(Value, BigNestedObject) { for (SizeType i = 0; i < n; i++) { char name1[10]; sprintf(name1, "%d", i); - + for (SizeType j = 0; j < n; j++) { char name2[10]; sprintf(name2, "%d", j); @@ -1689,8 +1689,8 @@ TEST(Value, BigNestedObject) { TEST(Value, RemoveLastElement) { rapidjson::Document doc; rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); - rapidjson::Value objVal(rapidjson::kObjectType); - objVal.AddMember("var1", 123, allocator); + rapidjson::Value objVal(rapidjson::kObjectType); + objVal.AddMember("var1", 123, allocator); objVal.AddMember("var2", "444", allocator); objVal.AddMember("var3", 555, allocator); EXPECT_TRUE(objVal.HasMember("var3")); @@ -1712,22 +1712,22 @@ TEST(Document, CrtAllocator) { static void TestShortStringOptimization(const char* str) { const rapidjson::SizeType len = static_cast(strlen(str)); - + rapidjson::Document doc; rapidjson::Value val; val.SetString(str, len, doc.GetAllocator()); - - EXPECT_EQ(val.GetStringLength(), len); - EXPECT_STREQ(val.GetString(), str); + + EXPECT_EQ(val.GetStringLength(), len); + EXPECT_STREQ(val.GetString(), str); } TEST(Value, AllocateShortString) { - TestShortStringOptimization(""); // edge case: empty string - TestShortStringOptimization("12345678"); // regular case for short strings: 8 chars - TestShortStringOptimization("12345678901"); // edge case: 11 chars in 32-bit mode (=> short string) - TestShortStringOptimization("123456789012"); // edge case: 12 chars in 32-bit mode (=> regular string) - TestShortStringOptimization("123456789012345"); // edge case: 15 chars in 64-bit mode (=> short string) - TestShortStringOptimization("1234567890123456"); // edge case: 16 chars in 64-bit mode (=> regular string) + TestShortStringOptimization(""); // edge case: empty string + TestShortStringOptimization("12345678"); // regular case for short strings: 8 chars + TestShortStringOptimization("12345678901"); // edge case: 11 chars in 32-bit mode (=> short string) + TestShortStringOptimization("123456789012"); // edge case: 12 chars in 32-bit mode (=> regular string) + TestShortStringOptimization("123456789012345"); // edge case: 15 chars in 64-bit mode (=> short string) + TestShortStringOptimization("1234567890123456"); // edge case: 16 chars in 64-bit mode (=> regular string) } template @@ -1802,7 +1802,7 @@ static void MergeDuplicateKey(Value& v, Value::AllocatorType& a) { // Convert all key:value into key:[value] for (Value::MemberIterator itr = v.MemberBegin(); itr != v.MemberEnd(); ++itr) itr->value = Value(kArrayType).Move().PushBack(itr->value, a); - + // Merge arrays if key is duplicated for (Value::MemberIterator itr = v.MemberBegin(); itr != v.MemberEnd();) { Value::MemberIterator itr2 = v.FindMember(itr->name);