rj_schema 0.2.6 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rj_schema/rapidjson/CMakeLists.txt +23 -1
  3. data/ext/rj_schema/rapidjson/appveyor.yml +49 -1
  4. data/ext/rj_schema/rapidjson/bin/types/alotofkeys.json +502 -0
  5. data/ext/rj_schema/rapidjson/bin/unittestschema/address.json +139 -0
  6. data/ext/rj_schema/rapidjson/bin/unittestschema/allOf_address.json +7 -0
  7. data/ext/rj_schema/rapidjson/bin/unittestschema/anyOf_address.json +7 -0
  8. data/ext/rj_schema/rapidjson/bin/unittestschema/idandref.json +69 -0
  9. data/ext/rj_schema/rapidjson/bin/unittestschema/oneOf_address.json +7 -0
  10. data/ext/rj_schema/rapidjson/doc/stream.md +7 -7
  11. data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +1 -1
  12. data/ext/rj_schema/rapidjson/doc/tutorial.md +15 -15
  13. data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +120 -0
  14. data/ext/rj_schema/rapidjson/example/traverseaspointer.cpp +39 -0
  15. data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +464 -56
  16. data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +1 -1
  17. data/ext/rj_schema/rapidjson/include/rapidjson/document.h +367 -72
  18. data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +1 -1
  19. data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +1 -1
  20. data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +49 -1
  21. data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +56 -1
  22. data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +1 -1
  23. data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +1 -1
  24. data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +1 -1
  25. data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +1 -1
  26. data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +4 -4
  27. data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +1 -1
  28. data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +1 -1
  29. data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +1 -1
  30. data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +1 -1
  31. data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +1 -1
  32. data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +1 -1
  33. data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +1 -1
  34. data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +1 -1
  35. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +15 -1
  36. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +1 -1
  37. data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +1 -1
  38. data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +1 -1
  39. data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +1 -1
  40. data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +1 -1
  41. data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +1 -1
  42. data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +69 -2
  43. data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +1 -1
  44. data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +77 -12
  45. data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +17 -9
  46. data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +558 -259
  47. data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +1 -1
  48. data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +1 -1
  49. data/ext/rj_schema/rapidjson/include/rapidjson/uri.h +466 -0
  50. data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +3 -3
  51. data/ext/rj_schema/rapidjson/readme.md +3 -3
  52. data/ext/rj_schema/rapidjson/readme.zh-cn.md +2 -2
  53. data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +1 -1
  54. data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +1 -1
  55. data/ext/rj_schema/rapidjson/test/perftest/perftest.h +6 -5
  56. data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +1 -1
  57. data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +21 -3
  58. data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +3 -0
  59. data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +194 -2
  60. data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +1 -1
  61. data/ext/rj_schema/rapidjson/test/unittest/clzlltest.cpp +34 -0
  62. data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +1 -1
  63. data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +3 -1
  64. data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +1 -1
  65. data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +1 -1
  66. data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +1 -1
  67. data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +1 -1
  68. data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +1 -1
  69. data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +1 -1
  70. data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +1 -1
  71. data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +1 -1
  72. data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +1 -1
  73. data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +1 -1
  74. data/ext/rj_schema/rapidjson/test/unittest/platformtest.cpp +40 -0
  75. data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +95 -3
  76. data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +1 -1
  77. data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +4 -1
  78. data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +1 -1
  79. data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +961 -81
  80. data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +1 -1
  81. data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +1 -1
  82. data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +1 -1
  83. data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +1 -1
  84. data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +1 -1
  85. data/ext/rj_schema/rapidjson/test/unittest/unittest.h +1 -1
  86. data/ext/rj_schema/rapidjson/test/unittest/uritest.cpp +718 -0
  87. data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +13 -3
  88. data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +1 -1
  89. data/ext/rj_schema/rj_schema.cpp +161 -17
  90. data/lib/rj_schema.rb +1 -1
  91. 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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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. All rights reserved.
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_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
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
 
@@ -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. All rights reserved.
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. All rights reserved.
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
@@ -124,6 +124,19 @@
124
124
  #define RAPIDJSON_NAMESPACE_END }
125
125
  #endif
126
126
 
127
+ ///////////////////////////////////////////////////////////////////////////////
128
+ // __cplusplus macro
129
+
130
+ //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
131
+
132
+ #if defined(_MSC_VER)
133
+ #define RAPIDJSON_CPLUSPLUS _MSVC_LANG
134
+ #else
135
+ #define RAPIDJSON_CPLUSPLUS __cplusplus
136
+ #endif
137
+
138
+ //!@endcond
139
+
127
140
  ///////////////////////////////////////////////////////////////////////////////
128
141
  // RAPIDJSON_HAS_STDSTRING
129
142
 
@@ -149,6 +162,24 @@
149
162
  #include <string>
150
163
  #endif // RAPIDJSON_HAS_STDSTRING
151
164
 
165
+ ///////////////////////////////////////////////////////////////////////////////
166
+ // RAPIDJSON_USE_MEMBERSMAP
167
+
168
+ /*! \def RAPIDJSON_USE_MEMBERSMAP
169
+ \ingroup RAPIDJSON_CONFIG
170
+ \brief Enable RapidJSON support for object members handling in a \c std::multimap
171
+
172
+ By defining this preprocessor symbol to \c 1, \ref rapidjson::GenericValue object
173
+ members are stored in a \c std::multimap for faster lookup and deletion times, a
174
+ trade off with a slightly slower insertion time and a small object allocat(or)ed
175
+ memory overhead.
176
+
177
+ \hideinitializer
178
+ */
179
+ #ifndef RAPIDJSON_USE_MEMBERSMAP
180
+ #define RAPIDJSON_USE_MEMBERSMAP 0 // not by default
181
+ #endif
182
+
152
183
  ///////////////////////////////////////////////////////////////////////////////
153
184
  // RAPIDJSON_NO_INT64DEFINE
154
185
 
@@ -411,7 +442,7 @@ RAPIDJSON_NAMESPACE_END
411
442
 
412
443
  // Prefer C++11 static_assert, if available
413
444
  #ifndef RAPIDJSON_STATIC_ASSERT
414
- #if __cplusplus >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
445
+ #if RAPIDJSON_CPLUSPLUS >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
415
446
  #define RAPIDJSON_STATIC_ASSERT(x) \
416
447
  static_assert(x, RAPIDJSON_STRINGIFY(x))
417
448
  #endif // C++11
@@ -541,8 +572,14 @@ RAPIDJSON_NAMESPACE_END
541
572
  ///////////////////////////////////////////////////////////////////////////////
542
573
  // C++11 features
543
574
 
575
+ #ifndef RAPIDJSON_HAS_CXX11
576
+ #define RAPIDJSON_HAS_CXX11 (RAPIDJSON_CPLUSPLUS >= 201103L)
577
+ #endif
578
+
544
579
  #ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
545
- #if defined(__clang__)
580
+ #if RAPIDJSON_HAS_CXX11
581
+ #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
582
+ #elif defined(__clang__)
546
583
  #if __has_feature(cxx_rvalue_references) && \
547
584
  (defined(_MSC_VER) || defined(_LIBCPP_VERSION) || defined(__GLIBCXX__) && __GLIBCXX__ >= 20080306)
548
585
  #define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
@@ -559,8 +596,14 @@ RAPIDJSON_NAMESPACE_END
559
596
  #endif
560
597
  #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
561
598
 
599
+ #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
600
+ #include <utility> // std::move
601
+ #endif
602
+
562
603
  #ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
563
- #if defined(__clang__)
604
+ #if RAPIDJSON_HAS_CXX11
605
+ #define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
606
+ #elif defined(__clang__)
564
607
  #define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
565
608
  #elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
566
609
  (defined(_MSC_VER) && _MSC_VER >= 1900) || \
@@ -570,11 +613,13 @@ RAPIDJSON_NAMESPACE_END
570
613
  #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
571
614
  #endif
572
615
  #endif
616
+ #ifndef RAPIDJSON_NOEXCEPT
573
617
  #if RAPIDJSON_HAS_CXX11_NOEXCEPT
574
618
  #define RAPIDJSON_NOEXCEPT noexcept
575
619
  #else
576
- #define RAPIDJSON_NOEXCEPT /* noexcept */
620
+ #define RAPIDJSON_NOEXCEPT throw()
577
621
  #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
622
+ #endif
578
623
 
579
624
  // no automatic detection, yet
580
625
  #ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
@@ -600,9 +645,17 @@ RAPIDJSON_NAMESPACE_END
600
645
  ///////////////////////////////////////////////////////////////////////////////
601
646
  // C++17 features
602
647
 
603
- #if defined(__has_cpp_attribute)
604
- # if __has_cpp_attribute(fallthrough)
605
- # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
648
+ #ifndef RAPIDJSON_HAS_CXX17
649
+ #define RAPIDJSON_HAS_CXX17 (RAPIDJSON_CPLUSPLUS >= 201703L)
650
+ #endif
651
+
652
+ #if RAPIDJSON_HAS_CXX17
653
+ # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
654
+ #elif defined(__has_cpp_attribute)
655
+ # if __has_cpp_attribute(clang::fallthrough)
656
+ # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
657
+ # elif __has_cpp_attribute(fallthrough)
658
+ # define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
606
659
  # else
607
660
  # define RAPIDJSON_DELIBERATE_FALLTHROUGH
608
661
  # endif
@@ -628,17 +681,29 @@ RAPIDJSON_NAMESPACE_END
628
681
 
629
682
  #ifndef RAPIDJSON_NOEXCEPT_ASSERT
630
683
  #ifdef RAPIDJSON_ASSERT_THROWS
631
- #if RAPIDJSON_HAS_CXX11_NOEXCEPT
632
- #define RAPIDJSON_NOEXCEPT_ASSERT(x)
633
- #else
634
684
  #include <cassert>
635
685
  #define RAPIDJSON_NOEXCEPT_ASSERT(x) assert(x)
636
- #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
637
686
  #else
638
687
  #define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
639
688
  #endif // RAPIDJSON_ASSERT_THROWS
640
689
  #endif // RAPIDJSON_NOEXCEPT_ASSERT
641
690
 
691
+ ///////////////////////////////////////////////////////////////////////////////
692
+ // malloc/realloc/free
693
+
694
+ #ifndef RAPIDJSON_MALLOC
695
+ ///! customization point for global \c malloc
696
+ #define RAPIDJSON_MALLOC(size) std::malloc(size)
697
+ #endif
698
+ #ifndef RAPIDJSON_REALLOC
699
+ ///! customization point for global \c realloc
700
+ #define RAPIDJSON_REALLOC(ptr, new_size) std::realloc(ptr, new_size)
701
+ #endif
702
+ #ifndef RAPIDJSON_FREE
703
+ ///! customization point for global \c free
704
+ #define RAPIDJSON_FREE(ptr) std::free(ptr)
705
+ #endif
706
+
642
707
  ///////////////////////////////////////////////////////////////////////////////
643
708
  // new/delete
644
709