Skip to content

Commit

Permalink
tidy up after merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Hanson authored and miloyip committed Nov 30, 2022
1 parent 794248e commit 7cad78e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions bin/unittestschema/address.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
"phone_type": {
"pattern": "^[0-9]*-[0-9]*",
"type": "string"
},
"url_type": {
"type": "string"
}
}
}
3 changes: 2 additions & 1 deletion example/schemavalidator/schemavalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions include/rapidjson/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<UTF8<> >
\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.
*/
Expand All @@ -72,7 +72,7 @@ class GenericPointer {
typedef GenericUri<ValueType, Allocator> 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.
Expand Down Expand Up @@ -689,7 +689,7 @@ class GenericPointer {
ValueType& GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& 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 <typename stackAllocator>
Expand Down Expand Up @@ -983,7 +983,7 @@ class GenericPointer {
}

i++;

// Escaping "~0" -> '~', "~1" -> '/'
if (c == '~') {
if (i < length) {
Expand Down
18 changes: 9 additions & 9 deletions include/rapidjson/rapidjson.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// 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
// 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
// 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_
#define RAPIDJSON_RAPIDJSON_H_

/*!\file rapidjson.h
\brief common definitions and configuration
\see RAPIDJSON_CONFIG
*/

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
};
Expand Down
6 changes: 2 additions & 4 deletions include/rapidjson/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@
#define RAPIDJSON_SCHEMA_VERBOSE 0
#endif

#if RAPIDJSON_SCHEMA_VERBOSE
#include "stringbuffer.h"
#endif

RAPIDJSON_DIAG_PUSH

#if defined(__GNUC__)
Expand Down Expand Up @@ -1309,6 +1305,8 @@ class Schema {
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();
Expand Down
2 changes: 1 addition & 1 deletion test/unittest/ostreamwrappertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>(fgetc(fp)));
fclose(fp);
Expand Down
4 changes: 2 additions & 2 deletions test/unittest/pointertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -1727,4 +1727,4 @@ TEST(Pointer, Issue1899) {
EXPECT_TRUE(PointerType("/foo/1234") == q);
q = q.Append("");
EXPECT_TRUE(PointerType("/foo/1234/") == q);
}
}
2 changes: 1 addition & 1 deletion test/unittest/uritest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST(Uri, Parse_UTF16) {
#if RAPIDJSON_HAS_STDSTRING
typedef std::basic_string<Value16::Ch> 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");
Expand Down
32 changes: 16 additions & 16 deletions test/unittest/valuetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
Expand All @@ -1712,22 +1712,22 @@ TEST(Document, CrtAllocator) {

static void TestShortStringOptimization(const char* str) {
const rapidjson::SizeType len = static_cast<rapidjson::SizeType>(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 <int e>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7cad78e

Please sign in to comment.