rj_schema 0.2.5 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rj_schema/rapidjson/CMakeLists.txt +23 -1
- data/ext/rj_schema/rapidjson/appveyor.yml +49 -1
- data/ext/rj_schema/rapidjson/bin/types/alotofkeys.json +502 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/address.json +139 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/allOf_address.json +7 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/anyOf_address.json +7 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/idandref.json +69 -0
- data/ext/rj_schema/rapidjson/bin/unittestschema/oneOf_address.json +7 -0
- data/ext/rj_schema/rapidjson/doc/stream.md +7 -7
- data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +1 -1
- data/ext/rj_schema/rapidjson/doc/tutorial.md +15 -15
- data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +120 -0
- data/ext/rj_schema/rapidjson/example/traverseaspointer.cpp +39 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +464 -56
- data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/document.h +367 -72
- data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +49 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +56 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +4 -4
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +15 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +69 -2
- data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +77 -12
- data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +17 -9
- data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +558 -259
- data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +1 -1
- data/ext/rj_schema/rapidjson/include/rapidjson/uri.h +466 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +3 -3
- data/ext/rj_schema/rapidjson/readme.md +3 -3
- data/ext/rj_schema/rapidjson/readme.zh-cn.md +2 -2
- data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/perftest.h +6 -5
- data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +21 -3
- data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +3 -0
- data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +194 -2
- data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/clzlltest.cpp +34 -0
- data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +3 -1
- data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/platformtest.cpp +40 -0
- data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +95 -3
- data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +4 -1
- data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +961 -81
- data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/unittest.h +1 -1
- data/ext/rj_schema/rapidjson/test/unittest/uritest.cpp +718 -0
- data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +13 -3
- data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +1 -1
- data/ext/rj_schema/rj_schema.cpp +162 -18
- data/lib/rj_schema.rb +1 -1
- metadata +14 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -65,6 +65,54 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro
|
|
65
65
|
}
|
66
66
|
}
|
67
67
|
|
68
|
+
//! Maps error code of validation into error message.
|
69
|
+
/*!
|
70
|
+
\ingroup RAPIDJSON_ERRORS
|
71
|
+
\param validateErrorCode Error code obtained from validator.
|
72
|
+
\return the error message.
|
73
|
+
\note User can make a copy of this function for localization.
|
74
|
+
Using switch-case is safer for future modification of error codes.
|
75
|
+
*/
|
76
|
+
inline const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En(ValidateErrorCode validateErrorCode) {
|
77
|
+
switch (validateErrorCode) {
|
78
|
+
case kValidateErrors: return RAPIDJSON_ERROR_STRING("One or more validation errors have occurred");
|
79
|
+
case kValidateErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
|
80
|
+
|
81
|
+
case kValidateErrorMultipleOf: return RAPIDJSON_ERROR_STRING("Number '%actual' is not a multiple of the 'multipleOf' value '%expected'.");
|
82
|
+
case kValidateErrorMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than the 'maximum' value '%expected'.");
|
83
|
+
case kValidateErrorExclusiveMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than or equal to the 'exclusiveMaximum' value '%expected'.");
|
84
|
+
case kValidateErrorMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than the 'minimum' value '%expected'.");
|
85
|
+
case kValidateErrorExclusiveMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than or equal to the 'exclusiveMinimum' value '%expected'.");
|
86
|
+
|
87
|
+
case kValidateErrorMaxLength: return RAPIDJSON_ERROR_STRING("String '%actual' is longer than the 'maxLength' value '%expected'.");
|
88
|
+
case kValidateErrorMinLength: return RAPIDJSON_ERROR_STRING("String '%actual' is shorter than the 'minLength' value '%expected'.");
|
89
|
+
case kValidateErrorPattern: return RAPIDJSON_ERROR_STRING("String '%actual' does not match the 'pattern' regular expression.");
|
90
|
+
|
91
|
+
case kValidateErrorMaxItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is longer than the 'maxItems' value '%expected'.");
|
92
|
+
case kValidateErrorMinItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is shorter than the 'minItems' value '%expected'.");
|
93
|
+
case kValidateErrorUniqueItems: return RAPIDJSON_ERROR_STRING("Array has duplicate items at indices '%duplicates' but 'uniqueItems' is true.");
|
94
|
+
case kValidateErrorAdditionalItems: return RAPIDJSON_ERROR_STRING("Array has an additional item at index '%disallowed' that is not allowed by the schema.");
|
95
|
+
|
96
|
+
case kValidateErrorMaxProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is more than 'maxProperties' value '%expected'.");
|
97
|
+
case kValidateErrorMinProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is less than 'minProperties' value '%expected'.");
|
98
|
+
case kValidateErrorRequired: return RAPIDJSON_ERROR_STRING("Object is missing the following members required by the schema: '%missing'.");
|
99
|
+
case kValidateErrorAdditionalProperties: return RAPIDJSON_ERROR_STRING("Object has an additional member '%disallowed' that is not allowed by the schema.");
|
100
|
+
case kValidateErrorPatternProperties: return RAPIDJSON_ERROR_STRING("Object has 'patternProperties' that are not allowed by the schema.");
|
101
|
+
case kValidateErrorDependencies: return RAPIDJSON_ERROR_STRING("Object has missing property or schema dependencies, refer to following errors.");
|
102
|
+
|
103
|
+
case kValidateErrorEnum: return RAPIDJSON_ERROR_STRING("Property has a value that is not one of its allowed enumerated values.");
|
104
|
+
case kValidateErrorType: return RAPIDJSON_ERROR_STRING("Property has a type '%actual' that is not in the following list: '%expected'.");
|
105
|
+
|
106
|
+
case kValidateErrorOneOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'oneOf', refer to following errors.");
|
107
|
+
case kValidateErrorOneOfMatch: return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf'.");
|
108
|
+
case kValidateErrorAllOf: return RAPIDJSON_ERROR_STRING("Property did not match all of the sub-schemas specified by 'allOf', refer to following errors.");
|
109
|
+
case kValidateErrorAnyOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'anyOf', refer to following errors.");
|
110
|
+
case kValidateErrorNot: return RAPIDJSON_ERROR_STRING("Property matched the sub-schema specified by 'not'.");
|
111
|
+
|
112
|
+
default: return RAPIDJSON_ERROR_STRING("Unknown error.");
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
68
116
|
RAPIDJSON_NAMESPACE_END
|
69
117
|
|
70
118
|
#ifdef __clang__
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -152,6 +152,61 @@ private:
|
|
152
152
|
*/
|
153
153
|
typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode);
|
154
154
|
|
155
|
+
///////////////////////////////////////////////////////////////////////////////
|
156
|
+
// ValidateErrorCode
|
157
|
+
|
158
|
+
//! Error codes when validating.
|
159
|
+
/*! \ingroup RAPIDJSON_ERRORS
|
160
|
+
\see GenericSchemaValidator
|
161
|
+
*/
|
162
|
+
enum ValidateErrorCode {
|
163
|
+
kValidateErrors = -1, //!< Top level error code when kValidateContinueOnErrorsFlag set.
|
164
|
+
kValidateErrorNone = 0, //!< No error.
|
165
|
+
|
166
|
+
kValidateErrorMultipleOf, //!< Number is not a multiple of the 'multipleOf' value.
|
167
|
+
kValidateErrorMaximum, //!< Number is greater than the 'maximum' value.
|
168
|
+
kValidateErrorExclusiveMaximum, //!< Number is greater than or equal to the 'maximum' value.
|
169
|
+
kValidateErrorMinimum, //!< Number is less than the 'minimum' value.
|
170
|
+
kValidateErrorExclusiveMinimum, //!< Number is less than or equal to the 'minimum' value.
|
171
|
+
|
172
|
+
kValidateErrorMaxLength, //!< String is longer than the 'maxLength' value.
|
173
|
+
kValidateErrorMinLength, //!< String is longer than the 'maxLength' value.
|
174
|
+
kValidateErrorPattern, //!< String does not match the 'pattern' regular expression.
|
175
|
+
|
176
|
+
kValidateErrorMaxItems, //!< Array is longer than the 'maxItems' value.
|
177
|
+
kValidateErrorMinItems, //!< Array is shorter than the 'minItems' value.
|
178
|
+
kValidateErrorUniqueItems, //!< Array has duplicate items but 'uniqueItems' is true.
|
179
|
+
kValidateErrorAdditionalItems, //!< Array has additional items that are not allowed by the schema.
|
180
|
+
|
181
|
+
kValidateErrorMaxProperties, //!< Object has more members than 'maxProperties' value.
|
182
|
+
kValidateErrorMinProperties, //!< Object has less members than 'minProperties' value.
|
183
|
+
kValidateErrorRequired, //!< Object is missing one or more members required by the schema.
|
184
|
+
kValidateErrorAdditionalProperties, //!< Object has additional members that are not allowed by the schema.
|
185
|
+
kValidateErrorPatternProperties, //!< See other errors.
|
186
|
+
kValidateErrorDependencies, //!< Object has missing property or schema dependencies.
|
187
|
+
|
188
|
+
kValidateErrorEnum, //!< Property has a value that is not one of its allowed enumerated values
|
189
|
+
kValidateErrorType, //!< Property has a type that is not allowed by the schema..
|
190
|
+
|
191
|
+
kValidateErrorOneOf, //!< Property did not match any of the sub-schemas specified by 'oneOf'.
|
192
|
+
kValidateErrorOneOfMatch, //!< Property matched more than one of the sub-schemas specified by 'oneOf'.
|
193
|
+
kValidateErrorAllOf, //!< Property did not match all of the sub-schemas specified by 'allOf'.
|
194
|
+
kValidateErrorAnyOf, //!< Property did not match any of the sub-schemas specified by 'anyOf'.
|
195
|
+
kValidateErrorNot //!< Property matched the sub-schema specified by 'not'.
|
196
|
+
};
|
197
|
+
|
198
|
+
//! Function pointer type of GetValidateError().
|
199
|
+
/*! \ingroup RAPIDJSON_ERRORS
|
200
|
+
|
201
|
+
This is the prototype for \c GetValidateError_X(), where \c X is a locale.
|
202
|
+
User can dynamically change locale in runtime, e.g.:
|
203
|
+
\code
|
204
|
+
GetValidateErrorFunc GetValidateError = GetValidateError_En; // or whatever
|
205
|
+
const RAPIDJSON_ERROR_CHARTYPE* s = GetValidateError(validator.GetInvalidSchemaCode());
|
206
|
+
\endcode
|
207
|
+
*/
|
208
|
+
typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetValidateErrorFunc)(ValidateErrorCode);
|
209
|
+
|
155
210
|
RAPIDJSON_NAMESPACE_END
|
156
211
|
|
157
212
|
#ifdef __clang__
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
#include "../rapidjson.h"
|
19
19
|
|
20
|
-
#if defined(_MSC_VER)
|
20
|
+
#if defined(_MSC_VER) && !defined(UNDER_CE)
|
21
21
|
#include <intrin.h>
|
22
22
|
#if defined(_WIN64)
|
23
23
|
#pragma intrinsic(_BitScanReverse64)
|
@@ -34,7 +34,7 @@ inline uint32_t clzll(uint64_t x) {
|
|
34
34
|
// infinite loop in the software implementation.
|
35
35
|
RAPIDJSON_ASSERT(x != 0);
|
36
36
|
|
37
|
-
#if defined(_MSC_VER)
|
37
|
+
#if defined(_MSC_VER) && !defined(UNDER_CE)
|
38
38
|
unsigned long r = 0;
|
39
39
|
#if defined(_WIN64)
|
40
40
|
_BitScanReverse64(&r, x);
|
@@ -53,7 +53,7 @@ inline uint32_t clzll(uint64_t x) {
|
|
53
53
|
return static_cast<uint32_t>(__builtin_clzll(x));
|
54
54
|
#else
|
55
55
|
// naive version
|
56
|
-
uint32_t r;
|
56
|
+
uint32_t r = 0;
|
57
57
|
while (!(x & (static_cast<uint64_t>(1) << 63))) {
|
58
58
|
x <<= 1;
|
59
59
|
++r;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -45,6 +45,20 @@ inline SizeType StrLen(const wchar_t* s) {
|
|
45
45
|
return SizeType(std::wcslen(s));
|
46
46
|
}
|
47
47
|
|
48
|
+
//! Custom strcmpn() which works on different character types.
|
49
|
+
/*! \tparam Ch Character type (e.g. char, wchar_t, short)
|
50
|
+
\param s1 Null-terminated input string.
|
51
|
+
\param s2 Null-terminated input string.
|
52
|
+
\return 0 if equal
|
53
|
+
*/
|
54
|
+
template<typename Ch>
|
55
|
+
inline int StrCmp(const Ch* s1, const Ch* s2) {
|
56
|
+
RAPIDJSON_ASSERT(s1 != 0);
|
57
|
+
RAPIDJSON_ASSERT(s2 != 0);
|
58
|
+
while(*s1 && (*s1 == *s2)) { s1++; s2++; }
|
59
|
+
return static_cast<unsigned>(*s1) < static_cast<unsigned>(*s2) ? -1 : static_cast<unsigned>(*s1) > static_cast<unsigned>(*s2);
|
60
|
+
}
|
61
|
+
|
48
62
|
//! Returns number of code points in a encoded string.
|
49
63
|
template<typename Encoding>
|
50
64
|
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
2
|
//
|
3
|
-
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
4
|
//
|
5
5
|
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
6
|
// in compliance with the License. You may obtain a copy of the License at
|
@@ -16,6 +16,7 @@
|
|
16
16
|
#define RAPIDJSON_POINTER_H_
|
17
17
|
|
18
18
|
#include "document.h"
|
19
|
+
#include "uri.h"
|
19
20
|
#include "internal/itoa.h"
|
20
21
|
|
21
22
|
#ifdef __clang__
|
@@ -80,6 +81,8 @@ class GenericPointer {
|
|
80
81
|
public:
|
81
82
|
typedef typename ValueType::EncodingType EncodingType; //!< Encoding type from Value
|
82
83
|
typedef typename ValueType::Ch Ch; //!< Character type from Value
|
84
|
+
typedef GenericUri<ValueType, Allocator> UriType;
|
85
|
+
|
83
86
|
|
84
87
|
//! A token is the basic units of internal representation.
|
85
88
|
/*!
|
@@ -163,7 +166,7 @@ public:
|
|
163
166
|
GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
|
164
167
|
|
165
168
|
//! Copy constructor.
|
166
|
-
GenericPointer(const GenericPointer& rhs) : allocator_(
|
169
|
+
GenericPointer(const GenericPointer& rhs) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
|
167
170
|
*this = rhs;
|
168
171
|
}
|
169
172
|
|
@@ -520,6 +523,70 @@ public:
|
|
520
523
|
|
521
524
|
//@}
|
522
525
|
|
526
|
+
//!@name Compute URI
|
527
|
+
//@{
|
528
|
+
|
529
|
+
//! Compute the in-scope URI for a subtree.
|
530
|
+
// For use with JSON pointers into JSON schema documents.
|
531
|
+
/*!
|
532
|
+
\param root Root value of a DOM sub-tree to be resolved. It can be any value other than document root.
|
533
|
+
\param rootUri Root URI
|
534
|
+
\param unresolvedTokenIndex If the pointer cannot resolve a token in the pointer, this parameter can obtain the index of unresolved token.
|
535
|
+
\param allocator Allocator for Uris
|
536
|
+
\return Uri if it can be resolved. Otherwise null.
|
537
|
+
|
538
|
+
\note
|
539
|
+
There are only 3 situations when a URI cannot be resolved:
|
540
|
+
1. A value in the path is not an array nor object.
|
541
|
+
2. An object value does not contain the token.
|
542
|
+
3. A token is out of range of an array value.
|
543
|
+
|
544
|
+
Use unresolvedTokenIndex to retrieve the token index.
|
545
|
+
*/
|
546
|
+
UriType GetUri(ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const {
|
547
|
+
static const Ch kIdString[] = { 'i', 'd', '\0' };
|
548
|
+
static const ValueType kIdValue(kIdString, 2);
|
549
|
+
UriType base = UriType(rootUri, allocator);
|
550
|
+
RAPIDJSON_ASSERT(IsValid());
|
551
|
+
ValueType* v = &root;
|
552
|
+
for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
553
|
+
switch (v->GetType()) {
|
554
|
+
case kObjectType:
|
555
|
+
{
|
556
|
+
// See if we have an id, and if so resolve with the current base
|
557
|
+
typename ValueType::MemberIterator m = v->FindMember(kIdValue);
|
558
|
+
if (m != v->MemberEnd() && (m->value).IsString()) {
|
559
|
+
UriType here = UriType(m->value, allocator).Resolve(base, allocator);
|
560
|
+
base = here;
|
561
|
+
}
|
562
|
+
m = v->FindMember(GenericValue<EncodingType>(GenericStringRef<Ch>(t->name, t->length)));
|
563
|
+
if (m == v->MemberEnd())
|
564
|
+
break;
|
565
|
+
v = &m->value;
|
566
|
+
}
|
567
|
+
continue;
|
568
|
+
case kArrayType:
|
569
|
+
if (t->index == kPointerInvalidIndex || t->index >= v->Size())
|
570
|
+
break;
|
571
|
+
v = &((*v)[t->index]);
|
572
|
+
continue;
|
573
|
+
default:
|
574
|
+
break;
|
575
|
+
}
|
576
|
+
|
577
|
+
// Error: unresolved token
|
578
|
+
if (unresolvedTokenIndex)
|
579
|
+
*unresolvedTokenIndex = static_cast<size_t>(t - tokens_);
|
580
|
+
return UriType(allocator);
|
581
|
+
}
|
582
|
+
return base;
|
583
|
+
}
|
584
|
+
|
585
|
+
UriType GetUri(const ValueType& root, const UriType& rootUri, size_t* unresolvedTokenIndex = 0, Allocator* allocator = 0) const {
|
586
|
+
return GetUri(const_cast<ValueType&>(root), rootUri, unresolvedTokenIndex, allocator);
|
587
|
+
}
|
588
|
+
|
589
|
+
|
523
590
|
//!@name Query value
|
524
591
|
//@{
|
525
592
|
|