rapidjson 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +20 -0
- data/ext/rapidjson/buffer.hh +66 -0
- data/ext/rapidjson/cext.cc +77 -0
- data/ext/rapidjson/cext.hh +20 -0
- data/ext/rapidjson/encoder.hh +150 -0
- data/ext/rapidjson/extconf.rb +19 -0
- data/ext/rapidjson/parser.hh +149 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/allocators.h +692 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/document.h +3027 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/encodedstream.h +299 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/encodings.h +716 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/error/en.h +122 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/error/error.h +216 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/filereadstream.h +99 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/filewritestream.h +104 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/fwd.h +151 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/biginteger.h +297 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/clzll.h +71 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/diyfp.h +261 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/dtoa.h +249 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/itoa.h +308 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/meta.h +186 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/pow10.h +55 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/regex.h +739 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/stack.h +232 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/strfunc.h +83 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/strtod.h +293 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/swap.h +46 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/istreamwrapper.h +128 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/memorybuffer.h +70 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/memorystream.h +71 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/pointer.h +1482 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/prettywriter.h +277 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/rapidjson.h +741 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/reader.h +2246 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/schema.h +2795 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/stream.h +223 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/stringbuffer.h +121 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/uri.h +481 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/writer.h +710 -0
- data/lib/rapidjson/json_gem.rb +36 -0
- data/lib/rapidjson/version.rb +5 -0
- data/lib/rapidjson.rb +9 -0
- metadata +98 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#ifndef RAPIDJSON_ERROR_EN_H_
|
16
|
+
#define RAPIDJSON_ERROR_EN_H_
|
17
|
+
|
18
|
+
#include "error.h"
|
19
|
+
|
20
|
+
#ifdef __clang__
|
21
|
+
RAPIDJSON_DIAG_PUSH
|
22
|
+
RAPIDJSON_DIAG_OFF(switch-enum)
|
23
|
+
RAPIDJSON_DIAG_OFF(covered-switch-default)
|
24
|
+
#endif
|
25
|
+
|
26
|
+
RAPIDJSON_NAMESPACE_BEGIN
|
27
|
+
|
28
|
+
//! Maps error code of parsing into error message.
|
29
|
+
/*!
|
30
|
+
\ingroup RAPIDJSON_ERRORS
|
31
|
+
\param parseErrorCode Error code obtained in parsing.
|
32
|
+
\return the error message.
|
33
|
+
\note User can make a copy of this function for localization.
|
34
|
+
Using switch-case is safer for future modification of error codes.
|
35
|
+
*/
|
36
|
+
inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) {
|
37
|
+
switch (parseErrorCode) {
|
38
|
+
case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
|
39
|
+
|
40
|
+
case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty.");
|
41
|
+
case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values.");
|
42
|
+
|
43
|
+
case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value.");
|
44
|
+
|
45
|
+
case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
|
46
|
+
case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member.");
|
47
|
+
case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member.");
|
48
|
+
|
49
|
+
case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element.");
|
50
|
+
|
51
|
+
case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string.");
|
52
|
+
case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
|
53
|
+
case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
|
54
|
+
case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
|
55
|
+
case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
|
56
|
+
|
57
|
+
case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
|
58
|
+
case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
|
59
|
+
case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
|
60
|
+
|
61
|
+
case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
|
62
|
+
case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
|
63
|
+
|
64
|
+
default: return RAPIDJSON_ERROR_STRING("Unknown error.");
|
65
|
+
}
|
66
|
+
}
|
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
|
+
|
116
|
+
RAPIDJSON_NAMESPACE_END
|
117
|
+
|
118
|
+
#ifdef __clang__
|
119
|
+
RAPIDJSON_DIAG_POP
|
120
|
+
#endif
|
121
|
+
|
122
|
+
#endif // RAPIDJSON_ERROR_EN_H_
|
@@ -0,0 +1,216 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#ifndef RAPIDJSON_ERROR_ERROR_H_
|
16
|
+
#define RAPIDJSON_ERROR_ERROR_H_
|
17
|
+
|
18
|
+
#include "../rapidjson.h"
|
19
|
+
|
20
|
+
#ifdef __clang__
|
21
|
+
RAPIDJSON_DIAG_PUSH
|
22
|
+
RAPIDJSON_DIAG_OFF(padded)
|
23
|
+
#endif
|
24
|
+
|
25
|
+
/*! \file error.h */
|
26
|
+
|
27
|
+
/*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */
|
28
|
+
|
29
|
+
///////////////////////////////////////////////////////////////////////////////
|
30
|
+
// RAPIDJSON_ERROR_CHARTYPE
|
31
|
+
|
32
|
+
//! Character type of error messages.
|
33
|
+
/*! \ingroup RAPIDJSON_ERRORS
|
34
|
+
The default character type is \c char.
|
35
|
+
On Windows, user can define this macro as \c TCHAR for supporting both
|
36
|
+
unicode/non-unicode settings.
|
37
|
+
*/
|
38
|
+
#ifndef RAPIDJSON_ERROR_CHARTYPE
|
39
|
+
#define RAPIDJSON_ERROR_CHARTYPE char
|
40
|
+
#endif
|
41
|
+
|
42
|
+
///////////////////////////////////////////////////////////////////////////////
|
43
|
+
// RAPIDJSON_ERROR_STRING
|
44
|
+
|
45
|
+
//! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[].
|
46
|
+
/*! \ingroup RAPIDJSON_ERRORS
|
47
|
+
By default this conversion macro does nothing.
|
48
|
+
On Windows, user can define this macro as \c _T(x) for supporting both
|
49
|
+
unicode/non-unicode settings.
|
50
|
+
*/
|
51
|
+
#ifndef RAPIDJSON_ERROR_STRING
|
52
|
+
#define RAPIDJSON_ERROR_STRING(x) x
|
53
|
+
#endif
|
54
|
+
|
55
|
+
RAPIDJSON_NAMESPACE_BEGIN
|
56
|
+
|
57
|
+
///////////////////////////////////////////////////////////////////////////////
|
58
|
+
// ParseErrorCode
|
59
|
+
|
60
|
+
//! Error code of parsing.
|
61
|
+
/*! \ingroup RAPIDJSON_ERRORS
|
62
|
+
\see GenericReader::Parse, GenericReader::GetParseErrorCode
|
63
|
+
*/
|
64
|
+
enum ParseErrorCode {
|
65
|
+
kParseErrorNone = 0, //!< No error.
|
66
|
+
|
67
|
+
kParseErrorDocumentEmpty, //!< The document is empty.
|
68
|
+
kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values.
|
69
|
+
|
70
|
+
kParseErrorValueInvalid, //!< Invalid value.
|
71
|
+
|
72
|
+
kParseErrorObjectMissName, //!< Missing a name for object member.
|
73
|
+
kParseErrorObjectMissColon, //!< Missing a colon after a name of object member.
|
74
|
+
kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member.
|
75
|
+
|
76
|
+
kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element.
|
77
|
+
|
78
|
+
kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string.
|
79
|
+
kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid.
|
80
|
+
kParseErrorStringEscapeInvalid, //!< Invalid escape character in string.
|
81
|
+
kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string.
|
82
|
+
kParseErrorStringInvalidEncoding, //!< Invalid encoding in string.
|
83
|
+
|
84
|
+
kParseErrorNumberTooBig, //!< Number too big to be stored in double.
|
85
|
+
kParseErrorNumberMissFraction, //!< Miss fraction part in number.
|
86
|
+
kParseErrorNumberMissExponent, //!< Miss exponent in number.
|
87
|
+
|
88
|
+
kParseErrorTermination, //!< Parsing was terminated.
|
89
|
+
kParseErrorUnspecificSyntaxError //!< Unspecific syntax error.
|
90
|
+
};
|
91
|
+
|
92
|
+
//! Result of parsing (wraps ParseErrorCode)
|
93
|
+
/*!
|
94
|
+
\ingroup RAPIDJSON_ERRORS
|
95
|
+
\code
|
96
|
+
Document doc;
|
97
|
+
ParseResult ok = doc.Parse("[42]");
|
98
|
+
if (!ok) {
|
99
|
+
fprintf(stderr, "JSON parse error: %s (%u)",
|
100
|
+
GetParseError_En(ok.Code()), ok.Offset());
|
101
|
+
exit(EXIT_FAILURE);
|
102
|
+
}
|
103
|
+
\endcode
|
104
|
+
\see GenericReader::Parse, GenericDocument::Parse
|
105
|
+
*/
|
106
|
+
struct ParseResult {
|
107
|
+
//!! Unspecified boolean type
|
108
|
+
typedef bool (ParseResult::*BooleanType)() const;
|
109
|
+
public:
|
110
|
+
//! Default constructor, no error.
|
111
|
+
ParseResult() : code_(kParseErrorNone), offset_(0) {}
|
112
|
+
//! Constructor to set an error.
|
113
|
+
ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {}
|
114
|
+
|
115
|
+
//! Get the error code.
|
116
|
+
ParseErrorCode Code() const { return code_; }
|
117
|
+
//! Get the error offset, if \ref IsError(), 0 otherwise.
|
118
|
+
size_t Offset() const { return offset_; }
|
119
|
+
|
120
|
+
//! Explicit conversion to \c bool, returns \c true, iff !\ref IsError().
|
121
|
+
operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; }
|
122
|
+
//! Whether the result is an error.
|
123
|
+
bool IsError() const { return code_ != kParseErrorNone; }
|
124
|
+
|
125
|
+
bool operator==(const ParseResult& that) const { return code_ == that.code_; }
|
126
|
+
bool operator==(ParseErrorCode code) const { return code_ == code; }
|
127
|
+
friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; }
|
128
|
+
|
129
|
+
bool operator!=(const ParseResult& that) const { return !(*this == that); }
|
130
|
+
bool operator!=(ParseErrorCode code) const { return !(*this == code); }
|
131
|
+
friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; }
|
132
|
+
|
133
|
+
//! Reset error code.
|
134
|
+
void Clear() { Set(kParseErrorNone); }
|
135
|
+
//! Update error code and offset.
|
136
|
+
void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; }
|
137
|
+
|
138
|
+
private:
|
139
|
+
ParseErrorCode code_;
|
140
|
+
size_t offset_;
|
141
|
+
};
|
142
|
+
|
143
|
+
//! Function pointer type of GetParseError().
|
144
|
+
/*! \ingroup RAPIDJSON_ERRORS
|
145
|
+
|
146
|
+
This is the prototype for \c GetParseError_X(), where \c X is a locale.
|
147
|
+
User can dynamically change locale in runtime, e.g.:
|
148
|
+
\code
|
149
|
+
GetParseErrorFunc GetParseError = GetParseError_En; // or whatever
|
150
|
+
const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());
|
151
|
+
\endcode
|
152
|
+
*/
|
153
|
+
typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode);
|
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
|
+
|
210
|
+
RAPIDJSON_NAMESPACE_END
|
211
|
+
|
212
|
+
#ifdef __clang__
|
213
|
+
RAPIDJSON_DIAG_POP
|
214
|
+
#endif
|
215
|
+
|
216
|
+
#endif // RAPIDJSON_ERROR_ERROR_H_
|
@@ -0,0 +1,99 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#ifndef RAPIDJSON_FILEREADSTREAM_H_
|
16
|
+
#define RAPIDJSON_FILEREADSTREAM_H_
|
17
|
+
|
18
|
+
#include "stream.h"
|
19
|
+
#include <cstdio>
|
20
|
+
|
21
|
+
#ifdef __clang__
|
22
|
+
RAPIDJSON_DIAG_PUSH
|
23
|
+
RAPIDJSON_DIAG_OFF(padded)
|
24
|
+
RAPIDJSON_DIAG_OFF(unreachable-code)
|
25
|
+
RAPIDJSON_DIAG_OFF(missing-noreturn)
|
26
|
+
#endif
|
27
|
+
|
28
|
+
RAPIDJSON_NAMESPACE_BEGIN
|
29
|
+
|
30
|
+
//! File byte stream for input using fread().
|
31
|
+
/*!
|
32
|
+
\note implements Stream concept
|
33
|
+
*/
|
34
|
+
class FileReadStream {
|
35
|
+
public:
|
36
|
+
typedef char Ch; //!< Character type (byte).
|
37
|
+
|
38
|
+
//! Constructor.
|
39
|
+
/*!
|
40
|
+
\param fp File pointer opened for read.
|
41
|
+
\param buffer user-supplied buffer.
|
42
|
+
\param bufferSize size of buffer in bytes. Must >=4 bytes.
|
43
|
+
*/
|
44
|
+
FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
|
45
|
+
RAPIDJSON_ASSERT(fp_ != 0);
|
46
|
+
RAPIDJSON_ASSERT(bufferSize >= 4);
|
47
|
+
Read();
|
48
|
+
}
|
49
|
+
|
50
|
+
Ch Peek() const { return *current_; }
|
51
|
+
Ch Take() { Ch c = *current_; Read(); return c; }
|
52
|
+
size_t Tell() const { return count_ + static_cast<size_t>(current_ - buffer_); }
|
53
|
+
|
54
|
+
// Not implemented
|
55
|
+
void Put(Ch) { RAPIDJSON_ASSERT(false); }
|
56
|
+
void Flush() { RAPIDJSON_ASSERT(false); }
|
57
|
+
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
58
|
+
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
59
|
+
|
60
|
+
// For encoding detection only.
|
61
|
+
const Ch* Peek4() const {
|
62
|
+
return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0;
|
63
|
+
}
|
64
|
+
|
65
|
+
private:
|
66
|
+
void Read() {
|
67
|
+
if (current_ < bufferLast_)
|
68
|
+
++current_;
|
69
|
+
else if (!eof_) {
|
70
|
+
count_ += readCount_;
|
71
|
+
readCount_ = std::fread(buffer_, 1, bufferSize_, fp_);
|
72
|
+
bufferLast_ = buffer_ + readCount_ - 1;
|
73
|
+
current_ = buffer_;
|
74
|
+
|
75
|
+
if (readCount_ < bufferSize_) {
|
76
|
+
buffer_[readCount_] = '\0';
|
77
|
+
++bufferLast_;
|
78
|
+
eof_ = true;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
std::FILE* fp_;
|
84
|
+
Ch *buffer_;
|
85
|
+
size_t bufferSize_;
|
86
|
+
Ch *bufferLast_;
|
87
|
+
Ch *current_;
|
88
|
+
size_t readCount_;
|
89
|
+
size_t count_; //!< Number of characters read
|
90
|
+
bool eof_;
|
91
|
+
};
|
92
|
+
|
93
|
+
RAPIDJSON_NAMESPACE_END
|
94
|
+
|
95
|
+
#ifdef __clang__
|
96
|
+
RAPIDJSON_DIAG_POP
|
97
|
+
#endif
|
98
|
+
|
99
|
+
#endif // RAPIDJSON_FILESTREAM_H_
|
@@ -0,0 +1,104 @@
|
|
1
|
+
// Tencent is pleased to support the open source community by making RapidJSON available.
|
2
|
+
//
|
3
|
+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
|
4
|
+
//
|
5
|
+
// Licensed under the MIT License (the "License"); you may not use this file except
|
6
|
+
// in compliance with the License. You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://opensource.org/licenses/MIT
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
// specific language governing permissions and limitations under the License.
|
14
|
+
|
15
|
+
#ifndef RAPIDJSON_FILEWRITESTREAM_H_
|
16
|
+
#define RAPIDJSON_FILEWRITESTREAM_H_
|
17
|
+
|
18
|
+
#include "stream.h"
|
19
|
+
#include <cstdio>
|
20
|
+
|
21
|
+
#ifdef __clang__
|
22
|
+
RAPIDJSON_DIAG_PUSH
|
23
|
+
RAPIDJSON_DIAG_OFF(unreachable-code)
|
24
|
+
#endif
|
25
|
+
|
26
|
+
RAPIDJSON_NAMESPACE_BEGIN
|
27
|
+
|
28
|
+
//! Wrapper of C file stream for output using fwrite().
|
29
|
+
/*!
|
30
|
+
\note implements Stream concept
|
31
|
+
*/
|
32
|
+
class FileWriteStream {
|
33
|
+
public:
|
34
|
+
typedef char Ch; //!< Character type. Only support char.
|
35
|
+
|
36
|
+
FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
|
37
|
+
RAPIDJSON_ASSERT(fp_ != 0);
|
38
|
+
}
|
39
|
+
|
40
|
+
void Put(char c) {
|
41
|
+
if (current_ >= bufferEnd_)
|
42
|
+
Flush();
|
43
|
+
|
44
|
+
*current_++ = c;
|
45
|
+
}
|
46
|
+
|
47
|
+
void PutN(char c, size_t n) {
|
48
|
+
size_t avail = static_cast<size_t>(bufferEnd_ - current_);
|
49
|
+
while (n > avail) {
|
50
|
+
std::memset(current_, c, avail);
|
51
|
+
current_ += avail;
|
52
|
+
Flush();
|
53
|
+
n -= avail;
|
54
|
+
avail = static_cast<size_t>(bufferEnd_ - current_);
|
55
|
+
}
|
56
|
+
|
57
|
+
if (n > 0) {
|
58
|
+
std::memset(current_, c, n);
|
59
|
+
current_ += n;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
void Flush() {
|
64
|
+
if (current_ != buffer_) {
|
65
|
+
size_t result = std::fwrite(buffer_, 1, static_cast<size_t>(current_ - buffer_), fp_);
|
66
|
+
if (result < static_cast<size_t>(current_ - buffer_)) {
|
67
|
+
// failure deliberately ignored at this time
|
68
|
+
// added to avoid warn_unused_result build errors
|
69
|
+
}
|
70
|
+
current_ = buffer_;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
// Not implemented
|
75
|
+
char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
|
76
|
+
char Take() { RAPIDJSON_ASSERT(false); return 0; }
|
77
|
+
size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
|
78
|
+
char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
79
|
+
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
|
80
|
+
|
81
|
+
private:
|
82
|
+
// Prohibit copy constructor & assignment operator.
|
83
|
+
FileWriteStream(const FileWriteStream&);
|
84
|
+
FileWriteStream& operator=(const FileWriteStream&);
|
85
|
+
|
86
|
+
std::FILE* fp_;
|
87
|
+
char *buffer_;
|
88
|
+
char *bufferEnd_;
|
89
|
+
char *current_;
|
90
|
+
};
|
91
|
+
|
92
|
+
//! Implement specialized version of PutN() with memset() for better performance.
|
93
|
+
template<>
|
94
|
+
inline void PutN(FileWriteStream& stream, char c, size_t n) {
|
95
|
+
stream.PutN(c, n);
|
96
|
+
}
|
97
|
+
|
98
|
+
RAPIDJSON_NAMESPACE_END
|
99
|
+
|
100
|
+
#ifdef __clang__
|
101
|
+
RAPIDJSON_DIAG_POP
|
102
|
+
#endif
|
103
|
+
|
104
|
+
#endif // RAPIDJSON_FILESTREAM_H_
|