mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-13 10:22:55 +01:00
Enabled PointerBindsToType in clang-format options.
This commit is contained in:
parent
30b07c0275
commit
11086dd6a7
@ -27,7 +27,7 @@ PenaltyBreakString: 1000
|
|||||||
PenaltyBreakFirstLessLess: 120
|
PenaltyBreakFirstLessLess: 120
|
||||||
PenaltyExcessCharacter: 1000000
|
PenaltyExcessCharacter: 1000000
|
||||||
PenaltyReturnTypeOnItsOwnLine: 60
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
PointerBindsToType: false
|
PointerBindsToType: true
|
||||||
SpacesBeforeTrailingComments: 1
|
SpacesBeforeTrailingComments: 1
|
||||||
Cpp11BracedListStyle: false
|
Cpp11BracedListStyle: false
|
||||||
Standard: Cpp03
|
Standard: Cpp03
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
// afterward in order to tell the compiler that this macro doesn't return.
|
// afterward in order to tell the compiler that this macro doesn't return.
|
||||||
#define JSON_FAIL_MESSAGE(message) \
|
#define JSON_FAIL_MESSAGE(message) \
|
||||||
{ \
|
{ \
|
||||||
assert(false &&message); \
|
assert(false&& message); \
|
||||||
strcpy(reinterpret_cast<char *>(666), message); \
|
strcpy(reinterpret_cast<char*>(666), message); \
|
||||||
exit(123); \
|
exit(123); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ namespace Json {
|
|||||||
class JSON_API Reader {
|
class JSON_API Reader {
|
||||||
public:
|
public:
|
||||||
typedef char Char;
|
typedef char Char;
|
||||||
typedef const Char *Location;
|
typedef const Char* Location;
|
||||||
|
|
||||||
/** \brief An error tagged with where in the JSON text it was encountered.
|
/** \brief An error tagged with where in the JSON text it was encountered.
|
||||||
*
|
*
|
||||||
@ -53,7 +53,7 @@ public:
|
|||||||
/** \brief Constructs a Reader allowing the specified feature set
|
/** \brief Constructs a Reader allowing the specified feature set
|
||||||
* for parsing.
|
* for parsing.
|
||||||
*/
|
*/
|
||||||
Reader(const Features &features);
|
Reader(const Features& features);
|
||||||
|
|
||||||
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
|
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
|
||||||
* document.
|
* document.
|
||||||
@ -70,7 +70,7 @@ public:
|
|||||||
* error occurred.
|
* error occurred.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
parse(const std::string &document, Value &root, bool collectComments = true);
|
parse(const std::string& document, Value& root, bool collectComments = true);
|
||||||
|
|
||||||
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
|
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
|
||||||
document.
|
document.
|
||||||
@ -90,14 +90,14 @@ public:
|
|||||||
* \return \c true if the document was successfully parsed, \c false if an
|
* \return \c true if the document was successfully parsed, \c false if an
|
||||||
error occurred.
|
error occurred.
|
||||||
*/
|
*/
|
||||||
bool parse(const char *beginDoc,
|
bool parse(const char* beginDoc,
|
||||||
const char *endDoc,
|
const char* endDoc,
|
||||||
Value &root,
|
Value& root,
|
||||||
bool collectComments = true);
|
bool collectComments = true);
|
||||||
|
|
||||||
/// \brief Parse from input stream.
|
/// \brief Parse from input stream.
|
||||||
/// \see Json::operator>>(std::istream&, Json::Value&).
|
/// \see Json::operator>>(std::istream&, Json::Value&).
|
||||||
bool parse(std::istream &is, Value &root, bool collectComments = true);
|
bool parse(std::istream& is, Value& root, bool collectComments = true);
|
||||||
|
|
||||||
/** \brief Returns a user friendly string that list errors in the parsed
|
/** \brief Returns a user friendly string that list errors in the parsed
|
||||||
* document.
|
* document.
|
||||||
@ -164,8 +164,8 @@ private:
|
|||||||
|
|
||||||
typedef std::deque<ErrorInfo> Errors;
|
typedef std::deque<ErrorInfo> Errors;
|
||||||
|
|
||||||
bool expectToken(TokenType type, Token &token, const char *message);
|
bool expectToken(TokenType type, Token& token, const char* message);
|
||||||
bool readToken(Token &token);
|
bool readToken(Token& token);
|
||||||
void skipSpaces();
|
void skipSpaces();
|
||||||
bool match(Location pattern, int patternLength);
|
bool match(Location pattern, int patternLength);
|
||||||
bool readComment();
|
bool readComment();
|
||||||
@ -174,37 +174,37 @@ private:
|
|||||||
bool readString();
|
bool readString();
|
||||||
void readNumber();
|
void readNumber();
|
||||||
bool readValue();
|
bool readValue();
|
||||||
bool readObject(Token &token);
|
bool readObject(Token& token);
|
||||||
bool readArray(Token &token);
|
bool readArray(Token& token);
|
||||||
bool decodeNumber(Token &token);
|
bool decodeNumber(Token& token);
|
||||||
bool decodeNumber(Token &token, Value &decoded);
|
bool decodeNumber(Token& token, Value& decoded);
|
||||||
bool decodeString(Token &token);
|
bool decodeString(Token& token);
|
||||||
bool decodeString(Token &token, std::string &decoded);
|
bool decodeString(Token& token, std::string& decoded);
|
||||||
bool decodeDouble(Token &token);
|
bool decodeDouble(Token& token);
|
||||||
bool decodeDouble(Token &token, Value &decoded);
|
bool decodeDouble(Token& token, Value& decoded);
|
||||||
bool decodeUnicodeCodePoint(Token &token,
|
bool decodeUnicodeCodePoint(Token& token,
|
||||||
Location ¤t,
|
Location& current,
|
||||||
Location end,
|
Location end,
|
||||||
unsigned int &unicode);
|
unsigned int& unicode);
|
||||||
bool decodeUnicodeEscapeSequence(Token &token,
|
bool decodeUnicodeEscapeSequence(Token& token,
|
||||||
Location ¤t,
|
Location& current,
|
||||||
Location end,
|
Location end,
|
||||||
unsigned int &unicode);
|
unsigned int& unicode);
|
||||||
bool addError(const std::string &message, Token &token, Location extra = 0);
|
bool addError(const std::string& message, Token& token, Location extra = 0);
|
||||||
bool recoverFromError(TokenType skipUntilToken);
|
bool recoverFromError(TokenType skipUntilToken);
|
||||||
bool addErrorAndRecover(const std::string &message,
|
bool addErrorAndRecover(const std::string& message,
|
||||||
Token &token,
|
Token& token,
|
||||||
TokenType skipUntilToken);
|
TokenType skipUntilToken);
|
||||||
void skipUntilSpace();
|
void skipUntilSpace();
|
||||||
Value ¤tValue();
|
Value& currentValue();
|
||||||
Char getNextChar();
|
Char getNextChar();
|
||||||
void
|
void
|
||||||
getLocationLineAndColumn(Location location, int &line, int &column) const;
|
getLocationLineAndColumn(Location location, int& line, int& column) const;
|
||||||
std::string getLocationLineAndColumn(Location location) const;
|
std::string getLocationLineAndColumn(Location location) const;
|
||||||
void addComment(Location begin, Location end, CommentPlacement placement);
|
void addComment(Location begin, Location end, CommentPlacement placement);
|
||||||
void skipCommentTokens(Token &token);
|
void skipCommentTokens(Token& token);
|
||||||
|
|
||||||
typedef std::stack<Value *> Nodes;
|
typedef std::stack<Value*> Nodes;
|
||||||
Nodes nodes_;
|
Nodes nodes_;
|
||||||
Errors errors_;
|
Errors errors_;
|
||||||
std::string document_;
|
std::string document_;
|
||||||
@ -212,7 +212,7 @@ private:
|
|||||||
Location end_;
|
Location end_;
|
||||||
Location current_;
|
Location current_;
|
||||||
Location lastValueEnd_;
|
Location lastValueEnd_;
|
||||||
Value *lastValue_;
|
Value* lastValue_;
|
||||||
std::string commentsBefore_;
|
std::string commentsBefore_;
|
||||||
Features features_;
|
Features features_;
|
||||||
bool collectComments_;
|
bool collectComments_;
|
||||||
@ -242,7 +242,7 @@ private:
|
|||||||
\throw std::exception on parse error.
|
\throw std::exception on parse error.
|
||||||
\see Json::operator<<()
|
\see Json::operator<<()
|
||||||
*/
|
*/
|
||||||
JSON_API std::istream &operator>>(std::istream &, Value &);
|
JSON_API std::istream& operator>>(std::istream&, Value&);
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
|
@ -74,14 +74,14 @@ enum CommentPlacement {
|
|||||||
*/
|
*/
|
||||||
class JSON_API StaticString {
|
class JSON_API StaticString {
|
||||||
public:
|
public:
|
||||||
explicit StaticString(const char *czstring) : str_(czstring) {}
|
explicit StaticString(const char* czstring) : str_(czstring) {}
|
||||||
|
|
||||||
operator const char *() const { return str_; }
|
operator const char*() const { return str_; }
|
||||||
|
|
||||||
const char *c_str() const { return str_; }
|
const char* c_str() const { return str_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *str_;
|
const char* str_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
|
/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
|
||||||
@ -133,7 +133,7 @@ public:
|
|||||||
typedef Json::LargestUInt LargestUInt;
|
typedef Json::LargestUInt LargestUInt;
|
||||||
typedef Json::ArrayIndex ArrayIndex;
|
typedef Json::ArrayIndex ArrayIndex;
|
||||||
|
|
||||||
static const Value &null;
|
static const Value& null;
|
||||||
/// Minimum signed integer value that can be stored in a Json::Value.
|
/// Minimum signed integer value that can be stored in a Json::Value.
|
||||||
static const LargestInt minLargestInt;
|
static const LargestInt minLargestInt;
|
||||||
/// Maximum signed integer value that can be stored in a Json::Value.
|
/// Maximum signed integer value that can be stored in a Json::Value.
|
||||||
@ -168,19 +168,19 @@ private:
|
|||||||
duplicateOnCopy
|
duplicateOnCopy
|
||||||
};
|
};
|
||||||
CZString(ArrayIndex index);
|
CZString(ArrayIndex index);
|
||||||
CZString(const char *cstr, DuplicationPolicy allocate);
|
CZString(const char* cstr, DuplicationPolicy allocate);
|
||||||
CZString(const CZString &other);
|
CZString(const CZString& other);
|
||||||
~CZString();
|
~CZString();
|
||||||
CZString &operator=(CZString other);
|
CZString& operator=(CZString other);
|
||||||
bool operator<(const CZString &other) const;
|
bool operator<(const CZString& other) const;
|
||||||
bool operator==(const CZString &other) const;
|
bool operator==(const CZString& other) const;
|
||||||
ArrayIndex index() const;
|
ArrayIndex index() const;
|
||||||
const char *c_str() const;
|
const char* c_str() const;
|
||||||
bool isStaticString() const;
|
bool isStaticString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void swap(CZString &other);
|
void swap(CZString& other);
|
||||||
const char *cstr_;
|
const char* cstr_;
|
||||||
ArrayIndex index_;
|
ArrayIndex index_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -217,8 +217,8 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
Value(UInt64 value);
|
Value(UInt64 value);
|
||||||
#endif // if defined(JSON_HAS_INT64)
|
#endif // if defined(JSON_HAS_INT64)
|
||||||
Value(double value);
|
Value(double value);
|
||||||
Value(const char *value);
|
Value(const char* value);
|
||||||
Value(const char *beginValue, const char *endValue);
|
Value(const char* beginValue, const char* endValue);
|
||||||
/** \brief Constructs a value from a static string.
|
/** \brief Constructs a value from a static string.
|
||||||
|
|
||||||
* Like other value string constructor but do not duplicate the string for
|
* Like other value string constructor but do not duplicate the string for
|
||||||
@ -229,34 +229,34 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
* Json::Value aValue( StaticString("some text") );
|
* Json::Value aValue( StaticString("some text") );
|
||||||
* \endcode
|
* \endcode
|
||||||
*/
|
*/
|
||||||
Value(const StaticString &value);
|
Value(const StaticString& value);
|
||||||
Value(const std::string &value);
|
Value(const std::string& value);
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
Value(const CppTL::ConstString &value);
|
Value(const CppTL::ConstString& value);
|
||||||
#endif
|
#endif
|
||||||
Value(bool value);
|
Value(bool value);
|
||||||
Value(const Value &other);
|
Value(const Value& other);
|
||||||
~Value();
|
~Value();
|
||||||
|
|
||||||
Value &operator=(Value other);
|
Value& operator=(Value other);
|
||||||
/// Swap values.
|
/// Swap values.
|
||||||
/// \note Currently, comments are intentionally not swapped, for
|
/// \note Currently, comments are intentionally not swapped, for
|
||||||
/// both logic and efficiency.
|
/// both logic and efficiency.
|
||||||
void swap(Value &other);
|
void swap(Value& other);
|
||||||
|
|
||||||
ValueType type() const;
|
ValueType type() const;
|
||||||
|
|
||||||
bool operator<(const Value &other) const;
|
bool operator<(const Value& other) const;
|
||||||
bool operator<=(const Value &other) const;
|
bool operator<=(const Value& other) const;
|
||||||
bool operator>=(const Value &other) const;
|
bool operator>=(const Value& other) const;
|
||||||
bool operator>(const Value &other) const;
|
bool operator>(const Value& other) const;
|
||||||
|
|
||||||
bool operator==(const Value &other) const;
|
bool operator==(const Value& other) const;
|
||||||
bool operator!=(const Value &other) const;
|
bool operator!=(const Value& other) const;
|
||||||
|
|
||||||
int compare(const Value &other) const;
|
int compare(const Value& other) const;
|
||||||
|
|
||||||
const char *asCString() const;
|
const char* asCString() const;
|
||||||
std::string asString() const;
|
std::string asString() const;
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
CppTL::ConstString asConstString() const;
|
CppTL::ConstString asConstString() const;
|
||||||
@ -316,7 +316,7 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
/// in the array so that its size is index+1.
|
/// in the array so that its size is index+1.
|
||||||
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
||||||
/// this from the operator[] which takes a string.)
|
/// this from the operator[] which takes a string.)
|
||||||
Value &operator[](ArrayIndex index);
|
Value& operator[](ArrayIndex index);
|
||||||
|
|
||||||
/// Access an array element (zero based index ).
|
/// Access an array element (zero based index ).
|
||||||
/// If the array contains less than index element, then null value are
|
/// If the array contains less than index element, then null value are
|
||||||
@ -324,39 +324,39 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
/// in the array so that its size is index+1.
|
/// in the array so that its size is index+1.
|
||||||
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
||||||
/// this from the operator[] which takes a string.)
|
/// this from the operator[] which takes a string.)
|
||||||
Value &operator[](int index);
|
Value& operator[](int index);
|
||||||
|
|
||||||
/// Access an array element (zero based index )
|
/// Access an array element (zero based index )
|
||||||
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
||||||
/// this from the operator[] which takes a string.)
|
/// this from the operator[] which takes a string.)
|
||||||
const Value &operator[](ArrayIndex index) const;
|
const Value& operator[](ArrayIndex index) const;
|
||||||
|
|
||||||
/// Access an array element (zero based index )
|
/// Access an array element (zero based index )
|
||||||
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
/// (You may need to say 'value[0u]' to get your compiler to distinguish
|
||||||
/// this from the operator[] which takes a string.)
|
/// this from the operator[] which takes a string.)
|
||||||
const Value &operator[](int index) const;
|
const Value& operator[](int index) const;
|
||||||
|
|
||||||
/// If the array contains at least index+1 elements, returns the element
|
/// If the array contains at least index+1 elements, returns the element
|
||||||
/// value,
|
/// value,
|
||||||
/// otherwise returns defaultValue.
|
/// otherwise returns defaultValue.
|
||||||
Value get(ArrayIndex index, const Value &defaultValue) const;
|
Value get(ArrayIndex index, const Value& defaultValue) const;
|
||||||
/// Return true if index < size().
|
/// Return true if index < size().
|
||||||
bool isValidIndex(ArrayIndex index) const;
|
bool isValidIndex(ArrayIndex index) const;
|
||||||
/// \brief Append value to array at the end.
|
/// \brief Append value to array at the end.
|
||||||
///
|
///
|
||||||
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
|
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
|
||||||
Value &append(const Value &value);
|
Value& append(const Value& value);
|
||||||
|
|
||||||
/// Access an object value by name, create a null member if it does not exist.
|
/// Access an object value by name, create a null member if it does not exist.
|
||||||
Value &operator[](const char *key);
|
Value& operator[](const char* key);
|
||||||
/// Access an object value by name, returns null if there is no member with
|
/// Access an object value by name, returns null if there is no member with
|
||||||
/// that name.
|
/// that name.
|
||||||
const Value &operator[](const char *key) const;
|
const Value& operator[](const char* key) const;
|
||||||
/// Access an object value by name, create a null member if it does not exist.
|
/// Access an object value by name, create a null member if it does not exist.
|
||||||
Value &operator[](const std::string &key);
|
Value& operator[](const std::string& key);
|
||||||
/// Access an object value by name, returns null if there is no member with
|
/// Access an object value by name, returns null if there is no member with
|
||||||
/// that name.
|
/// that name.
|
||||||
const Value &operator[](const std::string &key) const;
|
const Value& operator[](const std::string& key) const;
|
||||||
/** \brief Access an object value by name, create a null member if it does not
|
/** \brief Access an object value by name, create a null member if it does not
|
||||||
exist.
|
exist.
|
||||||
|
|
||||||
@ -369,21 +369,21 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
* object[code] = 1234;
|
* object[code] = 1234;
|
||||||
* \endcode
|
* \endcode
|
||||||
*/
|
*/
|
||||||
Value &operator[](const StaticString &key);
|
Value& operator[](const StaticString& key);
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
/// Access an object value by name, create a null member if it does not exist.
|
/// Access an object value by name, create a null member if it does not exist.
|
||||||
Value &operator[](const CppTL::ConstString &key);
|
Value& operator[](const CppTL::ConstString& key);
|
||||||
/// Access an object value by name, returns null if there is no member with
|
/// Access an object value by name, returns null if there is no member with
|
||||||
/// that name.
|
/// that name.
|
||||||
const Value &operator[](const CppTL::ConstString &key) const;
|
const Value& operator[](const CppTL::ConstString& key) const;
|
||||||
#endif
|
#endif
|
||||||
/// Return the member named key if it exist, defaultValue otherwise.
|
/// Return the member named key if it exist, defaultValue otherwise.
|
||||||
Value get(const char *key, const Value &defaultValue) const;
|
Value get(const char* key, const Value& defaultValue) const;
|
||||||
/// Return the member named key if it exist, defaultValue otherwise.
|
/// Return the member named key if it exist, defaultValue otherwise.
|
||||||
Value get(const std::string &key, const Value &defaultValue) const;
|
Value get(const std::string& key, const Value& defaultValue) const;
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
/// Return the member named key if it exist, defaultValue otherwise.
|
/// Return the member named key if it exist, defaultValue otherwise.
|
||||||
Value get(const CppTL::ConstString &key, const Value &defaultValue) const;
|
Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
|
||||||
#endif
|
#endif
|
||||||
/// \brief Remove and return the named member.
|
/// \brief Remove and return the named member.
|
||||||
///
|
///
|
||||||
@ -391,17 +391,17 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
/// \return the removed Value, or null.
|
/// \return the removed Value, or null.
|
||||||
/// \pre type() is objectValue or nullValue
|
/// \pre type() is objectValue or nullValue
|
||||||
/// \post type() is unchanged
|
/// \post type() is unchanged
|
||||||
Value removeMember(const char *key);
|
Value removeMember(const char* key);
|
||||||
/// Same as removeMember(const char*)
|
/// Same as removeMember(const char*)
|
||||||
Value removeMember(const std::string &key);
|
Value removeMember(const std::string& key);
|
||||||
|
|
||||||
/// Return true if the object has a member named key.
|
/// Return true if the object has a member named key.
|
||||||
bool isMember(const char *key) const;
|
bool isMember(const char* key) const;
|
||||||
/// Return true if the object has a member named key.
|
/// Return true if the object has a member named key.
|
||||||
bool isMember(const std::string &key) const;
|
bool isMember(const std::string& key) const;
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
/// Return true if the object has a member named key.
|
/// Return true if the object has a member named key.
|
||||||
bool isMember(const CppTL::ConstString &key) const;
|
bool isMember(const CppTL::ConstString& key) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// \brief Return a list of the member names.
|
/// \brief Return a list of the member names.
|
||||||
@ -417,9 +417,9 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
//# endif
|
//# endif
|
||||||
|
|
||||||
/// Comments must be //... or /* ... */
|
/// Comments must be //... or /* ... */
|
||||||
void setComment(const char *comment, CommentPlacement placement);
|
void setComment(const char* comment, CommentPlacement placement);
|
||||||
/// Comments must be //... or /* ... */
|
/// Comments must be //... or /* ... */
|
||||||
void setComment(const std::string &comment, CommentPlacement placement);
|
void setComment(const std::string& comment, CommentPlacement placement);
|
||||||
bool hasComment(CommentPlacement placement) const;
|
bool hasComment(CommentPlacement placement) const;
|
||||||
/// Include delimiters and embedded newlines.
|
/// Include delimiters and embedded newlines.
|
||||||
std::string getComment(CommentPlacement placement) const;
|
std::string getComment(CommentPlacement placement) const;
|
||||||
@ -440,7 +440,7 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
size_t getOffsetLimit() const;
|
size_t getOffsetLimit() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Value &resolveReference(const char *key, bool isStatic);
|
Value& resolveReference(const char* key, bool isStatic);
|
||||||
|
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
inline bool isItemAvailable() const { return itemIsUsed_ == 0; }
|
inline bool isItemAvailable() const { return itemIsUsed_ == 0; }
|
||||||
@ -459,9 +459,9 @@ private:
|
|||||||
CommentInfo();
|
CommentInfo();
|
||||||
~CommentInfo();
|
~CommentInfo();
|
||||||
|
|
||||||
void setComment(const char *text);
|
void setComment(const char* text);
|
||||||
|
|
||||||
char *comment_;
|
char* comment_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// struct MemberNamesTransform
|
// struct MemberNamesTransform
|
||||||
@ -478,12 +478,12 @@ private:
|
|||||||
LargestUInt uint_;
|
LargestUInt uint_;
|
||||||
double real_;
|
double real_;
|
||||||
bool bool_;
|
bool bool_;
|
||||||
char *string_;
|
char* string_;
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
ValueInternalArray *array_;
|
ValueInternalArray* array_;
|
||||||
ValueInternalMap *map_;
|
ValueInternalMap* map_;
|
||||||
#else
|
#else
|
||||||
ObjectValues *map_;
|
ObjectValues* map_;
|
||||||
#endif
|
#endif
|
||||||
} value_;
|
} value_;
|
||||||
ValueType type_ : 8;
|
ValueType type_ : 8;
|
||||||
@ -492,7 +492,7 @@ private:
|
|||||||
unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
|
unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
|
||||||
int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
|
int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
|
||||||
#endif
|
#endif
|
||||||
CommentInfo *comments_;
|
CommentInfo* comments_;
|
||||||
|
|
||||||
// [start, limit) byte offsets in the source JSON text from which this Value
|
// [start, limit) byte offsets in the source JSON text from which this Value
|
||||||
// was extracted.
|
// was extracted.
|
||||||
@ -509,8 +509,8 @@ public:
|
|||||||
|
|
||||||
PathArgument();
|
PathArgument();
|
||||||
PathArgument(ArrayIndex index);
|
PathArgument(ArrayIndex index);
|
||||||
PathArgument(const char *key);
|
PathArgument(const char* key);
|
||||||
PathArgument(const std::string &key);
|
PathArgument(const std::string& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Kind {
|
enum Kind {
|
||||||
@ -536,29 +536,29 @@ private:
|
|||||||
*/
|
*/
|
||||||
class JSON_API Path {
|
class JSON_API Path {
|
||||||
public:
|
public:
|
||||||
Path(const std::string &path,
|
Path(const std::string& path,
|
||||||
const PathArgument &a1 = PathArgument(),
|
const PathArgument& a1 = PathArgument(),
|
||||||
const PathArgument &a2 = PathArgument(),
|
const PathArgument& a2 = PathArgument(),
|
||||||
const PathArgument &a3 = PathArgument(),
|
const PathArgument& a3 = PathArgument(),
|
||||||
const PathArgument &a4 = PathArgument(),
|
const PathArgument& a4 = PathArgument(),
|
||||||
const PathArgument &a5 = PathArgument());
|
const PathArgument& a5 = PathArgument());
|
||||||
|
|
||||||
const Value &resolve(const Value &root) const;
|
const Value& resolve(const Value& root) const;
|
||||||
Value resolve(const Value &root, const Value &defaultValue) const;
|
Value resolve(const Value& root, const Value& defaultValue) const;
|
||||||
/// Creates the "path" to access the specified node and returns a reference on
|
/// Creates the "path" to access the specified node and returns a reference on
|
||||||
/// the node.
|
/// the node.
|
||||||
Value &make(Value &root) const;
|
Value& make(Value& root) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<const PathArgument *> InArgs;
|
typedef std::vector<const PathArgument*> InArgs;
|
||||||
typedef std::vector<PathArgument> Args;
|
typedef std::vector<PathArgument> Args;
|
||||||
|
|
||||||
void makePath(const std::string &path, const InArgs &in);
|
void makePath(const std::string& path, const InArgs& in);
|
||||||
void addPathInArg(const std::string &path,
|
void addPathInArg(const std::string& path,
|
||||||
const InArgs &in,
|
const InArgs& in,
|
||||||
InArgs::const_iterator &itInArg,
|
InArgs::const_iterator& itInArg,
|
||||||
PathArgument::Kind kind);
|
PathArgument::Kind kind);
|
||||||
void invalidPath(const std::string &path, int location);
|
void invalidPath(const std::string& path, int location);
|
||||||
|
|
||||||
Args args_;
|
Args args_;
|
||||||
};
|
};
|
||||||
@ -612,13 +612,13 @@ private:
|
|||||||
class JSON_API ValueMapAllocator {
|
class JSON_API ValueMapAllocator {
|
||||||
public:
|
public:
|
||||||
virtual ~ValueMapAllocator();
|
virtual ~ValueMapAllocator();
|
||||||
virtual ValueInternalMap *newMap() = 0;
|
virtual ValueInternalMap* newMap() = 0;
|
||||||
virtual ValueInternalMap *newMapCopy(const ValueInternalMap &other) = 0;
|
virtual ValueInternalMap* newMapCopy(const ValueInternalMap& other) = 0;
|
||||||
virtual void destructMap(ValueInternalMap *map) = 0;
|
virtual void destructMap(ValueInternalMap* map) = 0;
|
||||||
virtual ValueInternalLink *allocateMapBuckets(unsigned int size) = 0;
|
virtual ValueInternalLink* allocateMapBuckets(unsigned int size) = 0;
|
||||||
virtual void releaseMapBuckets(ValueInternalLink *links) = 0;
|
virtual void releaseMapBuckets(ValueInternalLink* links) = 0;
|
||||||
virtual ValueInternalLink *allocateMapLink() = 0;
|
virtual ValueInternalLink* allocateMapLink() = 0;
|
||||||
virtual void releaseMapLink(ValueInternalLink *link) = 0;
|
virtual void releaseMapLink(ValueInternalLink* link) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief ValueInternalMap hash-map bucket chain link (for internal use only).
|
/** \brief ValueInternalMap hash-map bucket chain link (for internal use only).
|
||||||
@ -639,9 +639,9 @@ public:
|
|||||||
~ValueInternalLink();
|
~ValueInternalLink();
|
||||||
|
|
||||||
Value items_[itemPerLink];
|
Value items_[itemPerLink];
|
||||||
char *keys_[itemPerLink];
|
char* keys_[itemPerLink];
|
||||||
ValueInternalLink *previous_;
|
ValueInternalLink* previous_;
|
||||||
ValueInternalLink *next_;
|
ValueInternalLink* next_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief A linked page based hash-table implementation used internally by
|
/** \brief A linked page based hash-table implementation used internally by
|
||||||
@ -672,19 +672,19 @@ public:
|
|||||||
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
||||||
struct IteratorState {
|
struct IteratorState {
|
||||||
IteratorState() : map_(0), link_(0), itemIndex_(0), bucketIndex_(0) {}
|
IteratorState() : map_(0), link_(0), itemIndex_(0), bucketIndex_(0) {}
|
||||||
ValueInternalMap *map_;
|
ValueInternalMap* map_;
|
||||||
ValueInternalLink *link_;
|
ValueInternalLink* link_;
|
||||||
BucketIndex itemIndex_;
|
BucketIndex itemIndex_;
|
||||||
BucketIndex bucketIndex_;
|
BucketIndex bucketIndex_;
|
||||||
};
|
};
|
||||||
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
||||||
|
|
||||||
ValueInternalMap();
|
ValueInternalMap();
|
||||||
ValueInternalMap(const ValueInternalMap &other);
|
ValueInternalMap(const ValueInternalMap& other);
|
||||||
ValueInternalMap &operator=(ValueInternalMap other);
|
ValueInternalMap& operator=(ValueInternalMap other);
|
||||||
~ValueInternalMap();
|
~ValueInternalMap();
|
||||||
|
|
||||||
void swap(ValueInternalMap &other);
|
void swap(ValueInternalMap& other);
|
||||||
|
|
||||||
BucketIndex size() const;
|
BucketIndex size() const;
|
||||||
|
|
||||||
@ -694,46 +694,46 @@ public:
|
|||||||
|
|
||||||
bool reserve(BucketIndex newItemCount);
|
bool reserve(BucketIndex newItemCount);
|
||||||
|
|
||||||
const Value *find(const char *key) const;
|
const Value* find(const char* key) const;
|
||||||
|
|
||||||
Value *find(const char *key);
|
Value* find(const char* key);
|
||||||
|
|
||||||
Value &resolveReference(const char *key, bool isStatic);
|
Value& resolveReference(const char* key, bool isStatic);
|
||||||
|
|
||||||
void remove(const char *key);
|
void remove(const char* key);
|
||||||
|
|
||||||
void doActualRemove(ValueInternalLink *link,
|
void doActualRemove(ValueInternalLink* link,
|
||||||
BucketIndex index,
|
BucketIndex index,
|
||||||
BucketIndex bucketIndex);
|
BucketIndex bucketIndex);
|
||||||
|
|
||||||
ValueInternalLink *&getLastLinkInBucket(BucketIndex bucketIndex);
|
ValueInternalLink*& getLastLinkInBucket(BucketIndex bucketIndex);
|
||||||
|
|
||||||
Value &setNewItem(const char *key,
|
Value& setNewItem(const char* key,
|
||||||
bool isStatic,
|
bool isStatic,
|
||||||
ValueInternalLink *link,
|
ValueInternalLink* link,
|
||||||
BucketIndex index);
|
BucketIndex index);
|
||||||
|
|
||||||
Value &unsafeAdd(const char *key, bool isStatic, HashKey hashedKey);
|
Value& unsafeAdd(const char* key, bool isStatic, HashKey hashedKey);
|
||||||
|
|
||||||
HashKey hash(const char *key) const;
|
HashKey hash(const char* key) const;
|
||||||
|
|
||||||
int compare(const ValueInternalMap &other) const;
|
int compare(const ValueInternalMap& other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void makeBeginIterator(IteratorState &it) const;
|
void makeBeginIterator(IteratorState& it) const;
|
||||||
void makeEndIterator(IteratorState &it) const;
|
void makeEndIterator(IteratorState& it) const;
|
||||||
static bool equals(const IteratorState &x, const IteratorState &other);
|
static bool equals(const IteratorState& x, const IteratorState& other);
|
||||||
static void increment(IteratorState &iterator);
|
static void increment(IteratorState& iterator);
|
||||||
static void incrementBucket(IteratorState &iterator);
|
static void incrementBucket(IteratorState& iterator);
|
||||||
static void decrement(IteratorState &iterator);
|
static void decrement(IteratorState& iterator);
|
||||||
static const char *key(const IteratorState &iterator);
|
static const char* key(const IteratorState& iterator);
|
||||||
static const char *key(const IteratorState &iterator, bool &isStatic);
|
static const char* key(const IteratorState& iterator, bool& isStatic);
|
||||||
static Value &value(const IteratorState &iterator);
|
static Value& value(const IteratorState& iterator);
|
||||||
static int distance(const IteratorState &x, const IteratorState &y);
|
static int distance(const IteratorState& x, const IteratorState& y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueInternalLink *buckets_;
|
ValueInternalLink* buckets_;
|
||||||
ValueInternalLink *tailLink_;
|
ValueInternalLink* tailLink_;
|
||||||
BucketIndex bucketsSize_;
|
BucketIndex bucketsSize_;
|
||||||
BucketIndex itemCount_;
|
BucketIndex itemCount_;
|
||||||
};
|
};
|
||||||
@ -767,44 +767,44 @@ public:
|
|||||||
struct IteratorState // Must be a POD
|
struct IteratorState // Must be a POD
|
||||||
{
|
{
|
||||||
IteratorState() : array_(0), currentPageIndex_(0), currentItemIndex_(0) {}
|
IteratorState() : array_(0), currentPageIndex_(0), currentItemIndex_(0) {}
|
||||||
ValueInternalArray *array_;
|
ValueInternalArray* array_;
|
||||||
Value **currentPageIndex_;
|
Value** currentPageIndex_;
|
||||||
unsigned int currentItemIndex_;
|
unsigned int currentItemIndex_;
|
||||||
};
|
};
|
||||||
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
|
||||||
|
|
||||||
ValueInternalArray();
|
ValueInternalArray();
|
||||||
ValueInternalArray(const ValueInternalArray &other);
|
ValueInternalArray(const ValueInternalArray& other);
|
||||||
ValueInternalArray &operator=(ValueInternalArray other);
|
ValueInternalArray& operator=(ValueInternalArray other);
|
||||||
~ValueInternalArray();
|
~ValueInternalArray();
|
||||||
void swap(ValueInternalArray &other);
|
void swap(ValueInternalArray& other);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void resize(ArrayIndex newSize);
|
void resize(ArrayIndex newSize);
|
||||||
|
|
||||||
Value &resolveReference(ArrayIndex index);
|
Value& resolveReference(ArrayIndex index);
|
||||||
|
|
||||||
Value *find(ArrayIndex index) const;
|
Value* find(ArrayIndex index) const;
|
||||||
|
|
||||||
ArrayIndex size() const;
|
ArrayIndex size() const;
|
||||||
|
|
||||||
int compare(const ValueInternalArray &other) const;
|
int compare(const ValueInternalArray& other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool equals(const IteratorState &x, const IteratorState &other);
|
static bool equals(const IteratorState& x, const IteratorState& other);
|
||||||
static void increment(IteratorState &iterator);
|
static void increment(IteratorState& iterator);
|
||||||
static void decrement(IteratorState &iterator);
|
static void decrement(IteratorState& iterator);
|
||||||
static Value &dereference(const IteratorState &iterator);
|
static Value& dereference(const IteratorState& iterator);
|
||||||
static Value &unsafeDereference(const IteratorState &iterator);
|
static Value& unsafeDereference(const IteratorState& iterator);
|
||||||
static int distance(const IteratorState &x, const IteratorState &y);
|
static int distance(const IteratorState& x, const IteratorState& y);
|
||||||
static ArrayIndex indexOf(const IteratorState &iterator);
|
static ArrayIndex indexOf(const IteratorState& iterator);
|
||||||
void makeBeginIterator(IteratorState &it) const;
|
void makeBeginIterator(IteratorState& it) const;
|
||||||
void makeEndIterator(IteratorState &it) const;
|
void makeEndIterator(IteratorState& it) const;
|
||||||
void makeIterator(IteratorState &it, ArrayIndex index) const;
|
void makeIterator(IteratorState& it, ArrayIndex index) const;
|
||||||
|
|
||||||
void makeIndexValid(ArrayIndex index);
|
void makeIndexValid(ArrayIndex index);
|
||||||
|
|
||||||
Value **pages_;
|
Value** pages_;
|
||||||
ArrayIndex size_;
|
ArrayIndex size_;
|
||||||
PageIndex pageCount_;
|
PageIndex pageCount_;
|
||||||
};
|
};
|
||||||
@ -875,9 +875,9 @@ virtual void releaseArrayPage( Value *value )
|
|||||||
class JSON_API ValueArrayAllocator {
|
class JSON_API ValueArrayAllocator {
|
||||||
public:
|
public:
|
||||||
virtual ~ValueArrayAllocator();
|
virtual ~ValueArrayAllocator();
|
||||||
virtual ValueInternalArray *newArray() = 0;
|
virtual ValueInternalArray* newArray() = 0;
|
||||||
virtual ValueInternalArray *newArrayCopy(const ValueInternalArray &other) = 0;
|
virtual ValueInternalArray* newArrayCopy(const ValueInternalArray& other) = 0;
|
||||||
virtual void destructArray(ValueInternalArray *array) = 0;
|
virtual void destructArray(ValueInternalArray* array) = 0;
|
||||||
/** \brief Reallocate array page index.
|
/** \brief Reallocate array page index.
|
||||||
* Reallocates an array of pointer on each page.
|
* Reallocates an array of pointer on each page.
|
||||||
* \param indexes [input] pointer on the current index. May be \c NULL.
|
* \param indexes [input] pointer on the current index. May be \c NULL.
|
||||||
@ -891,14 +891,14 @@ public:
|
|||||||
* handle.
|
* handle.
|
||||||
*/
|
*/
|
||||||
virtual void
|
virtual void
|
||||||
reallocateArrayPageIndex(Value **&indexes,
|
reallocateArrayPageIndex(Value**& indexes,
|
||||||
ValueInternalArray::PageIndex &indexCount,
|
ValueInternalArray::PageIndex& indexCount,
|
||||||
ValueInternalArray::PageIndex minNewIndexCount) = 0;
|
ValueInternalArray::PageIndex minNewIndexCount) = 0;
|
||||||
virtual void
|
virtual void
|
||||||
releaseArrayPageIndex(Value **indexes,
|
releaseArrayPageIndex(Value** indexes,
|
||||||
ValueInternalArray::PageIndex indexCount) = 0;
|
ValueInternalArray::PageIndex indexCount) = 0;
|
||||||
virtual Value *allocateArrayPage() = 0;
|
virtual Value* allocateArrayPage() = 0;
|
||||||
virtual void releaseArrayPage(Value *value) = 0;
|
virtual void releaseArrayPage(Value* value) = 0;
|
||||||
};
|
};
|
||||||
#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
|
|
||||||
@ -914,17 +914,17 @@ public:
|
|||||||
|
|
||||||
ValueIteratorBase();
|
ValueIteratorBase();
|
||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
explicit ValueIteratorBase(const Value::ObjectValues::iterator ¤t);
|
explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
|
||||||
#else
|
#else
|
||||||
ValueIteratorBase(const ValueInternalArray::IteratorState &state);
|
ValueIteratorBase(const ValueInternalArray::IteratorState& state);
|
||||||
ValueIteratorBase(const ValueInternalMap::IteratorState &state);
|
ValueIteratorBase(const ValueInternalMap::IteratorState& state);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool operator==(const SelfType &other) const { return isEqual(other); }
|
bool operator==(const SelfType& other) const { return isEqual(other); }
|
||||||
|
|
||||||
bool operator!=(const SelfType &other) const { return !isEqual(other); }
|
bool operator!=(const SelfType& other) const { return !isEqual(other); }
|
||||||
|
|
||||||
difference_type operator-(const SelfType &other) const {
|
difference_type operator-(const SelfType& other) const {
|
||||||
return computeDistance(other);
|
return computeDistance(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -937,20 +937,20 @@ public:
|
|||||||
|
|
||||||
/// Return the member name of the referenced Value. "" if it is not an
|
/// Return the member name of the referenced Value. "" if it is not an
|
||||||
/// objectValue.
|
/// objectValue.
|
||||||
const char *memberName() const;
|
const char* memberName() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Value &deref() const;
|
Value& deref() const;
|
||||||
|
|
||||||
void increment();
|
void increment();
|
||||||
|
|
||||||
void decrement();
|
void decrement();
|
||||||
|
|
||||||
difference_type computeDistance(const SelfType &other) const;
|
difference_type computeDistance(const SelfType& other) const;
|
||||||
|
|
||||||
bool isEqual(const SelfType &other) const;
|
bool isEqual(const SelfType& other) const;
|
||||||
|
|
||||||
void copy(const SelfType &other);
|
void copy(const SelfType& other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
@ -976,8 +976,8 @@ public:
|
|||||||
typedef const Value value_type;
|
typedef const Value value_type;
|
||||||
typedef unsigned int size_t;
|
typedef unsigned int size_t;
|
||||||
typedef int difference_type;
|
typedef int difference_type;
|
||||||
typedef const Value &reference;
|
typedef const Value& reference;
|
||||||
typedef const Value *pointer;
|
typedef const Value* pointer;
|
||||||
typedef ValueConstIterator SelfType;
|
typedef ValueConstIterator SelfType;
|
||||||
|
|
||||||
ValueConstIterator();
|
ValueConstIterator();
|
||||||
@ -986,13 +986,13 @@ private:
|
|||||||
/*! \internal Use by Value to create an iterator.
|
/*! \internal Use by Value to create an iterator.
|
||||||
*/
|
*/
|
||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
explicit ValueConstIterator(const Value::ObjectValues::iterator ¤t);
|
explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
|
||||||
#else
|
#else
|
||||||
ValueConstIterator(const ValueInternalArray::IteratorState &state);
|
ValueConstIterator(const ValueInternalArray::IteratorState& state);
|
||||||
ValueConstIterator(const ValueInternalMap::IteratorState &state);
|
ValueConstIterator(const ValueInternalMap::IteratorState& state);
|
||||||
#endif
|
#endif
|
||||||
public:
|
public:
|
||||||
SelfType &operator=(const ValueIteratorBase &other);
|
SelfType& operator=(const ValueIteratorBase& other);
|
||||||
|
|
||||||
SelfType operator++(int) {
|
SelfType operator++(int) {
|
||||||
SelfType temp(*this);
|
SelfType temp(*this);
|
||||||
@ -1006,12 +1006,12 @@ public:
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelfType &operator--() {
|
SelfType& operator--() {
|
||||||
decrement();
|
decrement();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelfType &operator++() {
|
SelfType& operator++() {
|
||||||
increment();
|
increment();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -1030,25 +1030,25 @@ public:
|
|||||||
typedef Value value_type;
|
typedef Value value_type;
|
||||||
typedef unsigned int size_t;
|
typedef unsigned int size_t;
|
||||||
typedef int difference_type;
|
typedef int difference_type;
|
||||||
typedef Value &reference;
|
typedef Value& reference;
|
||||||
typedef Value *pointer;
|
typedef Value* pointer;
|
||||||
typedef ValueIterator SelfType;
|
typedef ValueIterator SelfType;
|
||||||
|
|
||||||
ValueIterator();
|
ValueIterator();
|
||||||
ValueIterator(const ValueConstIterator &other);
|
ValueIterator(const ValueConstIterator& other);
|
||||||
ValueIterator(const ValueIterator &other);
|
ValueIterator(const ValueIterator& other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*! \internal Use by Value to create an iterator.
|
/*! \internal Use by Value to create an iterator.
|
||||||
*/
|
*/
|
||||||
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
#ifndef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
explicit ValueIterator(const Value::ObjectValues::iterator ¤t);
|
explicit ValueIterator(const Value::ObjectValues::iterator& current);
|
||||||
#else
|
#else
|
||||||
ValueIterator(const ValueInternalArray::IteratorState &state);
|
ValueIterator(const ValueInternalArray::IteratorState& state);
|
||||||
ValueIterator(const ValueInternalMap::IteratorState &state);
|
ValueIterator(const ValueInternalMap::IteratorState& state);
|
||||||
#endif
|
#endif
|
||||||
public:
|
public:
|
||||||
SelfType &operator=(const SelfType &other);
|
SelfType& operator=(const SelfType& other);
|
||||||
|
|
||||||
SelfType operator++(int) {
|
SelfType operator++(int) {
|
||||||
SelfType temp(*this);
|
SelfType temp(*this);
|
||||||
@ -1062,12 +1062,12 @@ public:
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelfType &operator--() {
|
SelfType& operator--() {
|
||||||
decrement();
|
decrement();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelfType &operator++() {
|
SelfType& operator++() {
|
||||||
increment();
|
increment();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class JSON_API Writer {
|
|||||||
public:
|
public:
|
||||||
virtual ~Writer();
|
virtual ~Writer();
|
||||||
|
|
||||||
virtual std::string write(const Value &root) = 0;
|
virtual std::string write(const Value& root) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format
|
/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format
|
||||||
@ -57,10 +57,10 @@ public:
|
|||||||
void omitEndingLineFeed();
|
void omitEndingLineFeed();
|
||||||
|
|
||||||
public: // overridden from Writer
|
public: // overridden from Writer
|
||||||
virtual std::string write(const Value &root);
|
virtual std::string write(const Value& root);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue(const Value &value);
|
void writeValue(const Value& value);
|
||||||
|
|
||||||
std::string document_;
|
std::string document_;
|
||||||
bool yamlCompatiblityEnabled_;
|
bool yamlCompatiblityEnabled_;
|
||||||
@ -101,21 +101,21 @@ public: // overridden from Writer
|
|||||||
* \param root Value to serialize.
|
* \param root Value to serialize.
|
||||||
* \return String containing the JSON document that represents the root value.
|
* \return String containing the JSON document that represents the root value.
|
||||||
*/
|
*/
|
||||||
virtual std::string write(const Value &root);
|
virtual std::string write(const Value& root);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue(const Value &value);
|
void writeValue(const Value& value);
|
||||||
void writeArrayValue(const Value &value);
|
void writeArrayValue(const Value& value);
|
||||||
bool isMultineArray(const Value &value);
|
bool isMultineArray(const Value& value);
|
||||||
void pushValue(const std::string &value);
|
void pushValue(const std::string& value);
|
||||||
void writeIndent();
|
void writeIndent();
|
||||||
void writeWithIndent(const std::string &value);
|
void writeWithIndent(const std::string& value);
|
||||||
void indent();
|
void indent();
|
||||||
void unindent();
|
void unindent();
|
||||||
void writeCommentBeforeValue(const Value &root);
|
void writeCommentBeforeValue(const Value& root);
|
||||||
void writeCommentAfterValueOnSameLine(const Value &root);
|
void writeCommentAfterValueOnSameLine(const Value& root);
|
||||||
bool hasCommentForValue(const Value &value);
|
bool hasCommentForValue(const Value& value);
|
||||||
static std::string normalizeEOL(const std::string &text);
|
static std::string normalizeEOL(const std::string& text);
|
||||||
|
|
||||||
typedef std::vector<std::string> ChildValues;
|
typedef std::vector<std::string> ChildValues;
|
||||||
|
|
||||||
@ -164,26 +164,26 @@ public:
|
|||||||
* \note There is no point in deriving from Writer, since write() should not
|
* \note There is no point in deriving from Writer, since write() should not
|
||||||
* return a value.
|
* return a value.
|
||||||
*/
|
*/
|
||||||
void write(std::ostream &out, const Value &root);
|
void write(std::ostream& out, const Value& root);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue(const Value &value);
|
void writeValue(const Value& value);
|
||||||
void writeArrayValue(const Value &value);
|
void writeArrayValue(const Value& value);
|
||||||
bool isMultineArray(const Value &value);
|
bool isMultineArray(const Value& value);
|
||||||
void pushValue(const std::string &value);
|
void pushValue(const std::string& value);
|
||||||
void writeIndent();
|
void writeIndent();
|
||||||
void writeWithIndent(const std::string &value);
|
void writeWithIndent(const std::string& value);
|
||||||
void indent();
|
void indent();
|
||||||
void unindent();
|
void unindent();
|
||||||
void writeCommentBeforeValue(const Value &root);
|
void writeCommentBeforeValue(const Value& root);
|
||||||
void writeCommentAfterValueOnSameLine(const Value &root);
|
void writeCommentAfterValueOnSameLine(const Value& root);
|
||||||
bool hasCommentForValue(const Value &value);
|
bool hasCommentForValue(const Value& value);
|
||||||
static std::string normalizeEOL(const std::string &text);
|
static std::string normalizeEOL(const std::string& text);
|
||||||
|
|
||||||
typedef std::vector<std::string> ChildValues;
|
typedef std::vector<std::string> ChildValues;
|
||||||
|
|
||||||
ChildValues childValues_;
|
ChildValues childValues_;
|
||||||
std::ostream *document_;
|
std::ostream* document_;
|
||||||
std::string indentString_;
|
std::string indentString_;
|
||||||
int rightMargin_;
|
int rightMargin_;
|
||||||
std::string indentation_;
|
std::string indentation_;
|
||||||
@ -198,11 +198,11 @@ std::string JSON_API valueToString(LargestInt value);
|
|||||||
std::string JSON_API valueToString(LargestUInt value);
|
std::string JSON_API valueToString(LargestUInt value);
|
||||||
std::string JSON_API valueToString(double value);
|
std::string JSON_API valueToString(double value);
|
||||||
std::string JSON_API valueToString(bool value);
|
std::string JSON_API valueToString(bool value);
|
||||||
std::string JSON_API valueToQuotedString(const char *value);
|
std::string JSON_API valueToQuotedString(const char* value);
|
||||||
|
|
||||||
/// \brief Output using the StyledStreamWriter.
|
/// \brief Output using the StyledStreamWriter.
|
||||||
/// \see Json::operator>>()
|
/// \see Json::operator>>()
|
||||||
JSON_API std::ostream &operator<<(std::ostream &, const Value &root);
|
JSON_API std::ostream& operator<<(std::ostream&, const Value& root);
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
|
@ -42,15 +42,15 @@ static std::string normalizeFloatingPointStr(double value) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string readInputTestFile(const char *path) {
|
static std::string readInputTestFile(const char* path) {
|
||||||
FILE *file = fopen(path, "rb");
|
FILE* file = fopen(path, "rb");
|
||||||
if (!file)
|
if (!file)
|
||||||
return std::string("");
|
return std::string("");
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
long size = ftell(file);
|
long size = ftell(file);
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
std::string text;
|
std::string text;
|
||||||
char *buffer = new char[size + 1];
|
char* buffer = new char[size + 1];
|
||||||
buffer[size] = 0;
|
buffer[size] = 0;
|
||||||
if (fread(buffer, 1, size, file) == (unsigned long)size)
|
if (fread(buffer, 1, size, file) == (unsigned long)size)
|
||||||
text = buffer;
|
text = buffer;
|
||||||
@ -60,7 +60,7 @@ static std::string readInputTestFile(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
printValueTree(FILE *fout, Json::Value &value, const std::string &path = ".") {
|
printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
|
||||||
switch (value.type()) {
|
switch (value.type()) {
|
||||||
case Json::nullValue:
|
case Json::nullValue:
|
||||||
fprintf(fout, "%s=null\n", path.c_str());
|
fprintf(fout, "%s=null\n", path.c_str());
|
||||||
@ -110,7 +110,7 @@ printValueTree(FILE *fout, Json::Value &value, const std::string &path = ".") {
|
|||||||
for (Json::Value::Members::iterator it = members.begin();
|
for (Json::Value::Members::iterator it = members.begin();
|
||||||
it != members.end();
|
it != members.end();
|
||||||
++it) {
|
++it) {
|
||||||
const std::string &name = *it;
|
const std::string& name = *it;
|
||||||
printValueTree(fout, value[name], path + suffix + name);
|
printValueTree(fout, value[name], path + suffix + name);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -119,11 +119,11 @@ printValueTree(FILE *fout, Json::Value &value, const std::string &path = ".") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parseAndSaveValueTree(const std::string &input,
|
static int parseAndSaveValueTree(const std::string& input,
|
||||||
const std::string &actual,
|
const std::string& actual,
|
||||||
const std::string &kind,
|
const std::string& kind,
|
||||||
Json::Value &root,
|
Json::Value& root,
|
||||||
const Json::Features &features,
|
const Json::Features& features,
|
||||||
bool parseOnly) {
|
bool parseOnly) {
|
||||||
Json::Reader reader(features);
|
Json::Reader reader(features);
|
||||||
bool parsingSuccessful = reader.parse(input, root);
|
bool parsingSuccessful = reader.parse(input, root);
|
||||||
@ -135,7 +135,7 @@ static int parseAndSaveValueTree(const std::string &input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!parseOnly) {
|
if (!parseOnly) {
|
||||||
FILE *factual = fopen(actual.c_str(), "wt");
|
FILE* factual = fopen(actual.c_str(), "wt");
|
||||||
if (!factual) {
|
if (!factual) {
|
||||||
printf("Failed to create %s actual file.\n", kind.c_str());
|
printf("Failed to create %s actual file.\n", kind.c_str());
|
||||||
return 2;
|
return 2;
|
||||||
@ -146,14 +146,14 @@ static int parseAndSaveValueTree(const std::string &input,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rewriteValueTree(const std::string &rewritePath,
|
static int rewriteValueTree(const std::string& rewritePath,
|
||||||
const Json::Value &root,
|
const Json::Value& root,
|
||||||
std::string &rewrite) {
|
std::string& rewrite) {
|
||||||
// Json::FastWriter writer;
|
// Json::FastWriter writer;
|
||||||
// writer.enableYAMLCompatibility();
|
// writer.enableYAMLCompatibility();
|
||||||
Json::StyledWriter writer;
|
Json::StyledWriter writer;
|
||||||
rewrite = writer.write(root);
|
rewrite = writer.write(root);
|
||||||
FILE *fout = fopen(rewritePath.c_str(), "wt");
|
FILE* fout = fopen(rewritePath.c_str(), "wt");
|
||||||
if (!fout) {
|
if (!fout) {
|
||||||
printf("Failed to create rewrite file: %s\n", rewritePath.c_str());
|
printf("Failed to create rewrite file: %s\n", rewritePath.c_str());
|
||||||
return 2;
|
return 2;
|
||||||
@ -163,8 +163,8 @@ static int rewriteValueTree(const std::string &rewritePath,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string removeSuffix(const std::string &path,
|
static std::string removeSuffix(const std::string& path,
|
||||||
const std::string &extension) {
|
const std::string& extension) {
|
||||||
if (extension.length() >= path.length())
|
if (extension.length() >= path.length())
|
||||||
return std::string("");
|
return std::string("");
|
||||||
std::string suffix = path.substr(path.length() - extension.length());
|
std::string suffix = path.substr(path.length() - extension.length());
|
||||||
@ -182,16 +182,16 @@ static void printConfig() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int printUsage(const char *argv[]) {
|
static int printUsage(const char* argv[]) {
|
||||||
printf("Usage: %s [--strict] input-json-file", argv[0]);
|
printf("Usage: %s [--strict] input-json-file", argv[0]);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parseCommandLine(int argc,
|
int parseCommandLine(int argc,
|
||||||
const char *argv[],
|
const char* argv[],
|
||||||
Json::Features &features,
|
Json::Features& features,
|
||||||
std::string &path,
|
std::string& path,
|
||||||
bool &parseOnly) {
|
bool& parseOnly) {
|
||||||
parseOnly = false;
|
parseOnly = false;
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
return printUsage(argv);
|
return printUsage(argv);
|
||||||
@ -217,7 +217,7 @@ int parseCommandLine(int argc,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
std::string path;
|
std::string path;
|
||||||
Json::Features features;
|
Json::Features features;
|
||||||
bool parseOnly;
|
bool parseOnly;
|
||||||
@ -261,7 +261,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception &e) {
|
catch (const std::exception& e) {
|
||||||
printf("Unhandled exception:\n%s\n", e.what());
|
printf("Unhandled exception:\n%s\n", e.what());
|
||||||
exitCode = 1;
|
exitCode = 1;
|
||||||
}
|
}
|
||||||
|
@ -33,16 +33,16 @@ public:
|
|||||||
// printf( "Size: %d => %s\n", sizeof(AllocatedType),
|
// printf( "Size: %d => %s\n", sizeof(AllocatedType),
|
||||||
// typeid(AllocatedType).name() );
|
// typeid(AllocatedType).name() );
|
||||||
assert(sizeof(AllocatedType) * objectPerAllocation >=
|
assert(sizeof(AllocatedType) * objectPerAllocation >=
|
||||||
sizeof(AllocatedType *)); // We must be able to store a slist in the
|
sizeof(AllocatedType*)); // We must be able to store a slist in the
|
||||||
// object free space.
|
// object free space.
|
||||||
assert(objectsPerPage >= 16);
|
assert(objectsPerPage >= 16);
|
||||||
batches_ = allocateBatch(0); // allocated a dummy page
|
batches_ = allocateBatch(0); // allocated a dummy page
|
||||||
currentBatch_ = batches_;
|
currentBatch_ = batches_;
|
||||||
}
|
}
|
||||||
|
|
||||||
~BatchAllocator() {
|
~BatchAllocator() {
|
||||||
for (BatchInfo *batch = batches_; batch;) {
|
for (BatchInfo* batch = batches_; batch;) {
|
||||||
BatchInfo *nextBatch = batch->next_;
|
BatchInfo* nextBatch = batch->next_;
|
||||||
free(batch);
|
free(batch);
|
||||||
batch = nextBatch;
|
batch = nextBatch;
|
||||||
}
|
}
|
||||||
@ -51,11 +51,11 @@ public:
|
|||||||
/// allocate space for an array of objectPerAllocation object.
|
/// allocate space for an array of objectPerAllocation object.
|
||||||
/// @warning it is the responsability of the caller to call objects
|
/// @warning it is the responsability of the caller to call objects
|
||||||
/// constructors.
|
/// constructors.
|
||||||
AllocatedType *allocate() {
|
AllocatedType* allocate() {
|
||||||
if (freeHead_) // returns node from free list.
|
if (freeHead_) // returns node from free list.
|
||||||
{
|
{
|
||||||
AllocatedType *object = freeHead_;
|
AllocatedType* object = freeHead_;
|
||||||
freeHead_ = *(AllocatedType **)object;
|
freeHead_ = *(AllocatedType**)object;
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
if (currentBatch_->used_ == currentBatch_->end_) {
|
if (currentBatch_->used_ == currentBatch_->end_) {
|
||||||
@ -70,7 +70,7 @@ public:
|
|||||||
batches_ = currentBatch_;
|
batches_ = currentBatch_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AllocatedType *allocated = currentBatch_->used_;
|
AllocatedType* allocated = currentBatch_->used_;
|
||||||
currentBatch_->used_ += objectPerAllocation;
|
currentBatch_->used_ += objectPerAllocation;
|
||||||
return allocated;
|
return allocated;
|
||||||
}
|
}
|
||||||
@ -78,39 +78,39 @@ public:
|
|||||||
/// Release the object.
|
/// Release the object.
|
||||||
/// @warning it is the responsability of the caller to actually destruct the
|
/// @warning it is the responsability of the caller to actually destruct the
|
||||||
/// object.
|
/// object.
|
||||||
void release(AllocatedType *object) {
|
void release(AllocatedType* object) {
|
||||||
assert(object != 0);
|
assert(object != 0);
|
||||||
*(AllocatedType **)object = freeHead_;
|
*(AllocatedType**)object = freeHead_;
|
||||||
freeHead_ = object;
|
freeHead_ = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct BatchInfo {
|
struct BatchInfo {
|
||||||
BatchInfo *next_;
|
BatchInfo* next_;
|
||||||
AllocatedType *used_;
|
AllocatedType* used_;
|
||||||
AllocatedType *end_;
|
AllocatedType* end_;
|
||||||
AllocatedType buffer_[objectPerAllocation];
|
AllocatedType buffer_[objectPerAllocation];
|
||||||
};
|
};
|
||||||
|
|
||||||
// disabled copy constructor and assignement operator.
|
// disabled copy constructor and assignement operator.
|
||||||
BatchAllocator(const BatchAllocator &);
|
BatchAllocator(const BatchAllocator&);
|
||||||
void operator=(const BatchAllocator &);
|
void operator=(const BatchAllocator&);
|
||||||
|
|
||||||
static BatchInfo *allocateBatch(unsigned int objectsPerPage) {
|
static BatchInfo* allocateBatch(unsigned int objectsPerPage) {
|
||||||
const unsigned int mallocSize =
|
const unsigned int mallocSize =
|
||||||
sizeof(BatchInfo) - sizeof(AllocatedType) * objectPerAllocation +
|
sizeof(BatchInfo) - sizeof(AllocatedType) * objectPerAllocation +
|
||||||
sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
|
sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
|
||||||
BatchInfo *batch = static_cast<BatchInfo *>(malloc(mallocSize));
|
BatchInfo* batch = static_cast<BatchInfo*>(malloc(mallocSize));
|
||||||
batch->next_ = 0;
|
batch->next_ = 0;
|
||||||
batch->used_ = batch->buffer_;
|
batch->used_ = batch->buffer_;
|
||||||
batch->end_ = batch->buffer_ + objectsPerPage;
|
batch->end_ = batch->buffer_ + objectsPerPage;
|
||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
BatchInfo *batches_;
|
BatchInfo* batches_;
|
||||||
BatchInfo *currentBatch_;
|
BatchInfo* currentBatch_;
|
||||||
/// Head of a single linked list within the allocated space of freeed object
|
/// Head of a single linked list within the allocated space of freeed object
|
||||||
AllocatedType *freeHead_;
|
AllocatedType* freeHead_;
|
||||||
unsigned int objectsPerPage_;
|
unsigned int objectsPerPage_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,20 +75,20 @@ Reader::Reader()
|
|||||||
lastValue_(), commentsBefore_(), features_(Features::all()),
|
lastValue_(), commentsBefore_(), features_(Features::all()),
|
||||||
collectComments_() {}
|
collectComments_() {}
|
||||||
|
|
||||||
Reader::Reader(const Features &features)
|
Reader::Reader(const Features& features)
|
||||||
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
|
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
|
||||||
lastValue_(), commentsBefore_(), features_(features), collectComments_() {
|
lastValue_(), commentsBefore_(), features_(features), collectComments_() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Reader::parse(const std::string &document, Value &root, bool collectComments) {
|
Reader::parse(const std::string& document, Value& root, bool collectComments) {
|
||||||
document_ = document;
|
document_ = document;
|
||||||
const char *begin = document_.c_str();
|
const char* begin = document_.c_str();
|
||||||
const char *end = begin + document_.length();
|
const char* end = begin + document_.length();
|
||||||
return parse(begin, end, root, collectComments);
|
return parse(begin, end, root, collectComments);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::parse(std::istream &sin, Value &root, bool collectComments) {
|
bool Reader::parse(std::istream& sin, Value& root, bool collectComments) {
|
||||||
// std::istream_iterator<char> begin(sin);
|
// std::istream_iterator<char> begin(sin);
|
||||||
// std::istream_iterator<char> end;
|
// std::istream_iterator<char> end;
|
||||||
// Those would allow streamed input from a file, if parse() were a
|
// Those would allow streamed input from a file, if parse() were a
|
||||||
@ -101,9 +101,9 @@ bool Reader::parse(std::istream &sin, Value &root, bool collectComments) {
|
|||||||
return parse(doc, root, collectComments);
|
return parse(doc, root, collectComments);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::parse(const char *beginDoc,
|
bool Reader::parse(const char* beginDoc,
|
||||||
const char *endDoc,
|
const char* endDoc,
|
||||||
Value &root,
|
Value& root,
|
||||||
bool collectComments) {
|
bool collectComments) {
|
||||||
if (!features_.allowComments_) {
|
if (!features_.allowComments_) {
|
||||||
collectComments = false;
|
collectComments = false;
|
||||||
@ -215,7 +215,7 @@ bool Reader::readValue() {
|
|||||||
return successful;
|
return successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reader::skipCommentTokens(Token &token) {
|
void Reader::skipCommentTokens(Token& token) {
|
||||||
if (features_.allowComments_) {
|
if (features_.allowComments_) {
|
||||||
do {
|
do {
|
||||||
readToken(token);
|
readToken(token);
|
||||||
@ -225,14 +225,14 @@ void Reader::skipCommentTokens(Token &token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::expectToken(TokenType type, Token &token, const char *message) {
|
bool Reader::expectToken(TokenType type, Token& token, const char* message) {
|
||||||
readToken(token);
|
readToken(token);
|
||||||
if (token.type_ != type)
|
if (token.type_ != type)
|
||||||
return addError(message, token);
|
return addError(message, token);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::readToken(Token &token) {
|
bool Reader::readToken(Token& token) {
|
||||||
skipSpaces();
|
skipSpaces();
|
||||||
token.start_ = current_;
|
token.start_ = current_;
|
||||||
Char c = getNextChar();
|
Char c = getNextChar();
|
||||||
@ -399,7 +399,7 @@ bool Reader::readString() {
|
|||||||
return c == '"';
|
return c == '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::readObject(Token &tokenStart) {
|
bool Reader::readObject(Token& tokenStart) {
|
||||||
Token tokenName;
|
Token tokenName;
|
||||||
std::string name;
|
std::string name;
|
||||||
currentValue() = Value(objectValue);
|
currentValue() = Value(objectValue);
|
||||||
@ -430,7 +430,7 @@ bool Reader::readObject(Token &tokenStart) {
|
|||||||
return addErrorAndRecover(
|
return addErrorAndRecover(
|
||||||
"Missing ':' after object member name", colon, tokenObjectEnd);
|
"Missing ':' after object member name", colon, tokenObjectEnd);
|
||||||
}
|
}
|
||||||
Value &value = currentValue()[name];
|
Value& value = currentValue()[name];
|
||||||
nodes_.push(&value);
|
nodes_.push(&value);
|
||||||
bool ok = readValue();
|
bool ok = readValue();
|
||||||
nodes_.pop();
|
nodes_.pop();
|
||||||
@ -454,7 +454,7 @@ bool Reader::readObject(Token &tokenStart) {
|
|||||||
"Missing '}' or object member name", tokenName, tokenObjectEnd);
|
"Missing '}' or object member name", tokenName, tokenObjectEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::readArray(Token &tokenStart) {
|
bool Reader::readArray(Token& tokenStart) {
|
||||||
currentValue() = Value(arrayValue);
|
currentValue() = Value(arrayValue);
|
||||||
currentValue().setOffsetStart(tokenStart.start_ - begin_);
|
currentValue().setOffsetStart(tokenStart.start_ - begin_);
|
||||||
skipSpaces();
|
skipSpaces();
|
||||||
@ -466,7 +466,7 @@ bool Reader::readArray(Token &tokenStart) {
|
|||||||
}
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Value &value = currentValue()[index++];
|
Value& value = currentValue()[index++];
|
||||||
nodes_.push(&value);
|
nodes_.push(&value);
|
||||||
bool ok = readValue();
|
bool ok = readValue();
|
||||||
nodes_.pop();
|
nodes_.pop();
|
||||||
@ -491,7 +491,7 @@ bool Reader::readArray(Token &tokenStart) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeNumber(Token &token) {
|
bool Reader::decodeNumber(Token& token) {
|
||||||
Value decoded;
|
Value decoded;
|
||||||
if (!decodeNumber(token, decoded))
|
if (!decodeNumber(token, decoded))
|
||||||
return false;
|
return false;
|
||||||
@ -501,7 +501,7 @@ bool Reader::decodeNumber(Token &token) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeNumber(Token &token, Value &decoded) {
|
bool Reader::decodeNumber(Token& token, Value& decoded) {
|
||||||
bool isDouble = false;
|
bool isDouble = false;
|
||||||
for (Location inspect = token.start_; inspect != token.end_; ++inspect) {
|
for (Location inspect = token.start_; inspect != token.end_; ++inspect) {
|
||||||
isDouble = isDouble || in(*inspect, '.', 'e', 'E', '+') ||
|
isDouble = isDouble || in(*inspect, '.', 'e', 'E', '+') ||
|
||||||
@ -549,7 +549,7 @@ bool Reader::decodeNumber(Token &token, Value &decoded) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeDouble(Token &token) {
|
bool Reader::decodeDouble(Token& token) {
|
||||||
Value decoded;
|
Value decoded;
|
||||||
if (!decodeDouble(token, decoded))
|
if (!decodeDouble(token, decoded))
|
||||||
return false;
|
return false;
|
||||||
@ -559,7 +559,7 @@ bool Reader::decodeDouble(Token &token) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeDouble(Token &token, Value &decoded) {
|
bool Reader::decodeDouble(Token& token, Value& decoded) {
|
||||||
double value = 0;
|
double value = 0;
|
||||||
const int bufferSize = 32;
|
const int bufferSize = 32;
|
||||||
int count;
|
int count;
|
||||||
@ -595,7 +595,7 @@ bool Reader::decodeDouble(Token &token, Value &decoded) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeString(Token &token) {
|
bool Reader::decodeString(Token& token) {
|
||||||
std::string decoded;
|
std::string decoded;
|
||||||
if (!decodeString(token, decoded))
|
if (!decodeString(token, decoded))
|
||||||
return false;
|
return false;
|
||||||
@ -605,7 +605,7 @@ bool Reader::decodeString(Token &token) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeString(Token &token, std::string &decoded) {
|
bool Reader::decodeString(Token& token, std::string& decoded) {
|
||||||
decoded.reserve(token.end_ - token.start_ - 2);
|
decoded.reserve(token.end_ - token.start_ - 2);
|
||||||
Location current = token.start_ + 1; // skip '"'
|
Location current = token.start_ + 1; // skip '"'
|
||||||
Location end = token.end_ - 1; // do not include '"'
|
Location end = token.end_ - 1; // do not include '"'
|
||||||
@ -658,10 +658,10 @@ bool Reader::decodeString(Token &token, std::string &decoded) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeUnicodeCodePoint(Token &token,
|
bool Reader::decodeUnicodeCodePoint(Token& token,
|
||||||
Location ¤t,
|
Location& current,
|
||||||
Location end,
|
Location end,
|
||||||
unsigned int &unicode) {
|
unsigned int& unicode) {
|
||||||
|
|
||||||
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
|
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
|
||||||
return false;
|
return false;
|
||||||
@ -687,10 +687,10 @@ bool Reader::decodeUnicodeCodePoint(Token &token,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeUnicodeEscapeSequence(Token &token,
|
bool Reader::decodeUnicodeEscapeSequence(Token& token,
|
||||||
Location ¤t,
|
Location& current,
|
||||||
Location end,
|
Location end,
|
||||||
unsigned int &unicode) {
|
unsigned int& unicode) {
|
||||||
if (end - current < 4)
|
if (end - current < 4)
|
||||||
return addError(
|
return addError(
|
||||||
"Bad unicode escape sequence in string: four digits expected.",
|
"Bad unicode escape sequence in string: four digits expected.",
|
||||||
@ -716,7 +716,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token &token,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Reader::addError(const std::string &message, Token &token, Location extra) {
|
Reader::addError(const std::string& message, Token& token, Location extra) {
|
||||||
ErrorInfo info;
|
ErrorInfo info;
|
||||||
info.token_ = token;
|
info.token_ = token;
|
||||||
info.message_ = message;
|
info.message_ = message;
|
||||||
@ -738,14 +738,14 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::addErrorAndRecover(const std::string &message,
|
bool Reader::addErrorAndRecover(const std::string& message,
|
||||||
Token &token,
|
Token& token,
|
||||||
TokenType skipUntilToken) {
|
TokenType skipUntilToken) {
|
||||||
addError(message, token);
|
addError(message, token);
|
||||||
return recoverFromError(skipUntilToken);
|
return recoverFromError(skipUntilToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Reader::currentValue() { return *(nodes_.top()); }
|
Value& Reader::currentValue() { return *(nodes_.top()); }
|
||||||
|
|
||||||
Reader::Char Reader::getNextChar() {
|
Reader::Char Reader::getNextChar() {
|
||||||
if (current_ == end_)
|
if (current_ == end_)
|
||||||
@ -754,8 +754,8 @@ Reader::Char Reader::getNextChar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Reader::getLocationLineAndColumn(Location location,
|
void Reader::getLocationLineAndColumn(Location location,
|
||||||
int &line,
|
int& line,
|
||||||
int &column) const {
|
int& column) const {
|
||||||
Location current = begin_;
|
Location current = begin_;
|
||||||
Location lastLineStart = current;
|
Location lastLineStart = current;
|
||||||
line = 0;
|
line = 0;
|
||||||
@ -802,7 +802,7 @@ std::string Reader::getFormattedErrorMessages() const {
|
|||||||
for (Errors::const_iterator itError = errors_.begin();
|
for (Errors::const_iterator itError = errors_.begin();
|
||||||
itError != errors_.end();
|
itError != errors_.end();
|
||||||
++itError) {
|
++itError) {
|
||||||
const ErrorInfo &error = *itError;
|
const ErrorInfo& error = *itError;
|
||||||
formattedMessage +=
|
formattedMessage +=
|
||||||
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
||||||
formattedMessage += " " + error.message_ + "\n";
|
formattedMessage += " " + error.message_ + "\n";
|
||||||
@ -818,7 +818,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
|||||||
for (Errors::const_iterator itError = errors_.begin();
|
for (Errors::const_iterator itError = errors_.begin();
|
||||||
itError != errors_.end();
|
itError != errors_.end();
|
||||||
++itError) {
|
++itError) {
|
||||||
const ErrorInfo &error = *itError;
|
const ErrorInfo& error = *itError;
|
||||||
Reader::StructuredError structured;
|
Reader::StructuredError structured;
|
||||||
structured.offset_start = error.token_.start_ - begin_;
|
structured.offset_start = error.token_.start_ - begin_;
|
||||||
structured.offset_limit = error.token_.end_ - begin_;
|
structured.offset_limit = error.token_.end_ - begin_;
|
||||||
@ -828,7 +828,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
|||||||
return allErrors;
|
return allErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream &operator>>(std::istream &sin, Value &root) {
|
std::istream& operator>>(std::istream& sin, Value& root) {
|
||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
bool ok = reader.parse(sin, root, true);
|
bool ok = reader.parse(sin, root, true);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
@ -60,7 +60,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize];
|
|||||||
* @param current Input/Output string buffer.
|
* @param current Input/Output string buffer.
|
||||||
* Must have at least uintToStringBufferSize chars free.
|
* Must have at least uintToStringBufferSize chars free.
|
||||||
*/
|
*/
|
||||||
static inline void uintToString(LargestUInt value, char *¤t) {
|
static inline void uintToString(LargestUInt value, char*& current) {
|
||||||
*--current = 0;
|
*--current = 0;
|
||||||
do {
|
do {
|
||||||
*--current = char(value % 10) + '0';
|
*--current = char(value % 10) + '0';
|
||||||
@ -73,7 +73,7 @@ static inline void uintToString(LargestUInt value, char *¤t) {
|
|||||||
* We had a sophisticated way, but it did not work in WinCE.
|
* We had a sophisticated way, but it did not work in WinCE.
|
||||||
* @see https://github.com/open-source-parsers/jsoncpp/pull/9
|
* @see https://github.com/open-source-parsers/jsoncpp/pull/9
|
||||||
*/
|
*/
|
||||||
static inline void fixNumericLocale(char *begin, char *end) {
|
static inline void fixNumericLocale(char* begin, char* end) {
|
||||||
while (begin < end) {
|
while (begin < end) {
|
||||||
if (*begin == ',') {
|
if (*begin == ',') {
|
||||||
*begin = '.';
|
*begin = '.';
|
||||||
|
@ -34,8 +34,8 @@ namespace Json {
|
|||||||
#define ALIGNAS(byte_alignment)
|
#define ALIGNAS(byte_alignment)
|
||||||
#endif
|
#endif
|
||||||
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
|
static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
|
||||||
const unsigned char &kNullRef = kNull[0];
|
const unsigned char& kNullRef = kNull[0];
|
||||||
const Value &Value::null = reinterpret_cast<const Value &>(kNullRef);
|
const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
|
||||||
|
|
||||||
const Int Value::minInt = Int(~(UInt(-1) / 2));
|
const Int Value::minInt = Int(~(UInt(-1) / 2));
|
||||||
const Int Value::maxInt = Int(UInt(-1) / 2);
|
const Int Value::maxInt = Int(UInt(-1) / 2);
|
||||||
@ -83,7 +83,7 @@ static inline bool InRange(double d, T min, U max) {
|
|||||||
* computed using strlen(value).
|
* computed using strlen(value).
|
||||||
* @return Pointer on the duplicate instance of string.
|
* @return Pointer on the duplicate instance of string.
|
||||||
*/
|
*/
|
||||||
static inline char *duplicateStringValue(const char *value,
|
static inline char* duplicateStringValue(const char* value,
|
||||||
unsigned int length = unknown) {
|
unsigned int length = unknown) {
|
||||||
if (length == unknown)
|
if (length == unknown)
|
||||||
length = (unsigned int)strlen(value);
|
length = (unsigned int)strlen(value);
|
||||||
@ -93,7 +93,7 @@ static inline char *duplicateStringValue(const char *value,
|
|||||||
if (length >= (unsigned)Value::maxInt)
|
if (length >= (unsigned)Value::maxInt)
|
||||||
length = Value::maxInt - 1;
|
length = Value::maxInt - 1;
|
||||||
|
|
||||||
char *newString = static_cast<char *>(malloc(length + 1));
|
char* newString = static_cast<char*>(malloc(length + 1));
|
||||||
JSON_ASSERT_MESSAGE(newString != 0,
|
JSON_ASSERT_MESSAGE(newString != 0,
|
||||||
"in Json::Value::duplicateStringValue(): "
|
"in Json::Value::duplicateStringValue(): "
|
||||||
"Failed to allocate string value buffer");
|
"Failed to allocate string value buffer");
|
||||||
@ -104,7 +104,7 @@ static inline char *duplicateStringValue(const char *value,
|
|||||||
|
|
||||||
/** Free the string duplicated by duplicateStringValue().
|
/** Free the string duplicated by duplicateStringValue().
|
||||||
*/
|
*/
|
||||||
static inline void releaseStringValue(char *value) { free(value); }
|
static inline void releaseStringValue(char* value) { free(value); }
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ Value::CommentInfo::~CommentInfo() {
|
|||||||
releaseStringValue(comment_);
|
releaseStringValue(comment_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::CommentInfo::setComment(const char *text) {
|
void Value::CommentInfo::setComment(const char* text) {
|
||||||
if (comment_)
|
if (comment_)
|
||||||
releaseStringValue(comment_);
|
releaseStringValue(comment_);
|
||||||
JSON_ASSERT(text != 0);
|
JSON_ASSERT(text != 0);
|
||||||
@ -166,11 +166,11 @@ void Value::CommentInfo::setComment(const char *text) {
|
|||||||
|
|
||||||
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
|
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
|
||||||
|
|
||||||
Value::CZString::CZString(const char *cstr, DuplicationPolicy allocate)
|
Value::CZString::CZString(const char* cstr, DuplicationPolicy allocate)
|
||||||
: cstr_(allocate == duplicate ? duplicateStringValue(cstr) : cstr),
|
: cstr_(allocate == duplicate ? duplicateStringValue(cstr) : cstr),
|
||||||
index_(allocate) {}
|
index_(allocate) {}
|
||||||
|
|
||||||
Value::CZString::CZString(const CZString &other)
|
Value::CZString::CZString(const CZString& other)
|
||||||
: cstr_(other.index_ != noDuplication && other.cstr_ != 0
|
: cstr_(other.index_ != noDuplication && other.cstr_ != 0
|
||||||
? duplicateStringValue(other.cstr_)
|
? duplicateStringValue(other.cstr_)
|
||||||
: other.cstr_),
|
: other.cstr_),
|
||||||
@ -180,26 +180,26 @@ Value::CZString::CZString(const CZString &other)
|
|||||||
|
|
||||||
Value::CZString::~CZString() {
|
Value::CZString::~CZString() {
|
||||||
if (cstr_ && index_ == duplicate)
|
if (cstr_ && index_ == duplicate)
|
||||||
releaseStringValue(const_cast<char *>(cstr_));
|
releaseStringValue(const_cast<char*>(cstr_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::CZString::swap(CZString &other) {
|
void Value::CZString::swap(CZString& other) {
|
||||||
std::swap(cstr_, other.cstr_);
|
std::swap(cstr_, other.cstr_);
|
||||||
std::swap(index_, other.index_);
|
std::swap(index_, other.index_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::CZString &Value::CZString::operator=(CZString other) {
|
Value::CZString& Value::CZString::operator=(CZString other) {
|
||||||
swap(other);
|
swap(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::CZString::operator<(const CZString &other) const {
|
bool Value::CZString::operator<(const CZString& other) const {
|
||||||
if (cstr_)
|
if (cstr_)
|
||||||
return strcmp(cstr_, other.cstr_) < 0;
|
return strcmp(cstr_, other.cstr_) < 0;
|
||||||
return index_ < other.index_;
|
return index_ < other.index_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::CZString::operator==(const CZString &other) const {
|
bool Value::CZString::operator==(const CZString& other) const {
|
||||||
if (cstr_)
|
if (cstr_)
|
||||||
return strcmp(cstr_, other.cstr_) == 0;
|
return strcmp(cstr_, other.cstr_) == 0;
|
||||||
return index_ == other.index_;
|
return index_ == other.index_;
|
||||||
@ -207,7 +207,7 @@ bool Value::CZString::operator==(const CZString &other) const {
|
|||||||
|
|
||||||
ArrayIndex Value::CZString::index() const { return index_; }
|
ArrayIndex Value::CZString::index() const { return index_; }
|
||||||
|
|
||||||
const char *Value::CZString::c_str() const { return cstr_; }
|
const char* Value::CZString::c_str() const { return cstr_; }
|
||||||
|
|
||||||
bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
|
bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ Value::Value(double value)
|
|||||||
value_.real_ = value;
|
value_.real_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Value(const char *value)
|
Value::Value(const char* value)
|
||||||
: type_(stringValue), allocated_(true)
|
: type_(stringValue), allocated_(true)
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
,
|
,
|
||||||
@ -335,7 +335,7 @@ Value::Value(const char *value)
|
|||||||
value_.string_ = duplicateStringValue(value);
|
value_.string_ = duplicateStringValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Value(const char *beginValue, const char *endValue)
|
Value::Value(const char* beginValue, const char* endValue)
|
||||||
: type_(stringValue), allocated_(true)
|
: type_(stringValue), allocated_(true)
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
,
|
,
|
||||||
@ -347,7 +347,7 @@ Value::Value(const char *beginValue, const char *endValue)
|
|||||||
duplicateStringValue(beginValue, (unsigned int)(endValue - beginValue));
|
duplicateStringValue(beginValue, (unsigned int)(endValue - beginValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Value(const std::string &value)
|
Value::Value(const std::string& value)
|
||||||
: type_(stringValue), allocated_(true)
|
: type_(stringValue), allocated_(true)
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
,
|
,
|
||||||
@ -359,7 +359,7 @@ Value::Value(const std::string &value)
|
|||||||
duplicateStringValue(value.c_str(), (unsigned int)value.length());
|
duplicateStringValue(value.c_str(), (unsigned int)value.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Value(const StaticString &value)
|
Value::Value(const StaticString& value)
|
||||||
: type_(stringValue), allocated_(false)
|
: type_(stringValue), allocated_(false)
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
,
|
,
|
||||||
@ -367,11 +367,11 @@ Value::Value(const StaticString &value)
|
|||||||
#endif
|
#endif
|
||||||
,
|
,
|
||||||
comments_(0), start_(0), limit_(0) {
|
comments_(0), start_(0), limit_(0) {
|
||||||
value_.string_ = const_cast<char *>(value.c_str());
|
value_.string_ = const_cast<char*>(value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
Value::Value(const CppTL::ConstString &value)
|
Value::Value(const CppTL::ConstString& value)
|
||||||
: type_(stringValue), allocated_(true)
|
: type_(stringValue), allocated_(true)
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
,
|
,
|
||||||
@ -394,7 +394,7 @@ Value::Value(bool value)
|
|||||||
value_.bool_ = value;
|
value_.bool_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Value(const Value &other)
|
Value::Value(const Value& other)
|
||||||
: type_(other.type_), allocated_(false)
|
: type_(other.type_), allocated_(false)
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
,
|
,
|
||||||
@ -438,7 +438,7 @@ Value::Value(const Value &other)
|
|||||||
if (other.comments_) {
|
if (other.comments_) {
|
||||||
comments_ = new CommentInfo[numberOfCommentPlacement];
|
comments_ = new CommentInfo[numberOfCommentPlacement];
|
||||||
for (int comment = 0; comment < numberOfCommentPlacement; ++comment) {
|
for (int comment = 0; comment < numberOfCommentPlacement; ++comment) {
|
||||||
const CommentInfo &otherComment = other.comments_[comment];
|
const CommentInfo& otherComment = other.comments_[comment];
|
||||||
if (otherComment.comment_)
|
if (otherComment.comment_)
|
||||||
comments_[comment].setComment(otherComment.comment_);
|
comments_[comment].setComment(otherComment.comment_);
|
||||||
}
|
}
|
||||||
@ -478,12 +478,12 @@ Value::~Value() {
|
|||||||
delete[] comments_;
|
delete[] comments_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::operator=(Value other) {
|
Value& Value::operator=(Value other) {
|
||||||
swap(other);
|
swap(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::swap(Value &other) {
|
void Value::swap(Value& other) {
|
||||||
ValueType temp = type_;
|
ValueType temp = type_;
|
||||||
type_ = other.type_;
|
type_ = other.type_;
|
||||||
other.type_ = temp;
|
other.type_ = temp;
|
||||||
@ -497,7 +497,7 @@ void Value::swap(Value &other) {
|
|||||||
|
|
||||||
ValueType Value::type() const { return type_; }
|
ValueType Value::type() const { return type_; }
|
||||||
|
|
||||||
int Value::compare(const Value &other) const {
|
int Value::compare(const Value& other) const {
|
||||||
if (*this < other)
|
if (*this < other)
|
||||||
return -1;
|
return -1;
|
||||||
if (*this > other)
|
if (*this > other)
|
||||||
@ -505,7 +505,7 @@ int Value::compare(const Value &other) const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::operator<(const Value &other) const {
|
bool Value::operator<(const Value& other) const {
|
||||||
int typeDelta = type_ - other.type_;
|
int typeDelta = type_ - other.type_;
|
||||||
if (typeDelta)
|
if (typeDelta)
|
||||||
return typeDelta < 0 ? true : false;
|
return typeDelta < 0 ? true : false;
|
||||||
@ -544,13 +544,13 @@ bool Value::operator<(const Value &other) const {
|
|||||||
return false; // unreachable
|
return false; // unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::operator<=(const Value &other) const { return !(other < *this); }
|
bool Value::operator<=(const Value& other) const { return !(other < *this); }
|
||||||
|
|
||||||
bool Value::operator>=(const Value &other) const { return !(*this < other); }
|
bool Value::operator>=(const Value& other) const { return !(*this < other); }
|
||||||
|
|
||||||
bool Value::operator>(const Value &other) const { return other < *this; }
|
bool Value::operator>(const Value& other) const { return other < *this; }
|
||||||
|
|
||||||
bool Value::operator==(const Value &other) const {
|
bool Value::operator==(const Value& other) const {
|
||||||
// if ( type_ != other.type_ )
|
// if ( type_ != other.type_ )
|
||||||
// GCC 2.95.3 says:
|
// GCC 2.95.3 says:
|
||||||
// attempt to take address of bit-field structure member `Json::Value::type_'
|
// attempt to take address of bit-field structure member `Json::Value::type_'
|
||||||
@ -590,9 +590,9 @@ bool Value::operator==(const Value &other) const {
|
|||||||
return false; // unreachable
|
return false; // unreachable
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::operator!=(const Value &other) const { return !(*this == other); }
|
bool Value::operator!=(const Value& other) const { return !(*this == other); }
|
||||||
|
|
||||||
const char *Value::asCString() const {
|
const char* Value::asCString() const {
|
||||||
JSON_ASSERT_MESSAGE(type_ == stringValue,
|
JSON_ASSERT_MESSAGE(type_ == stringValue,
|
||||||
"in Json::Value::asCString(): requires stringValue");
|
"in Json::Value::asCString(): requires stringValue");
|
||||||
return value_.string_;
|
return value_.string_;
|
||||||
@ -910,7 +910,7 @@ void Value::resize(ArrayIndex newSize) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::operator[](ArrayIndex index) {
|
Value& Value::operator[](ArrayIndex index) {
|
||||||
JSON_ASSERT_MESSAGE(
|
JSON_ASSERT_MESSAGE(
|
||||||
type_ == nullValue || type_ == arrayValue,
|
type_ == nullValue || type_ == arrayValue,
|
||||||
"in Json::Value::operator[](ArrayIndex): requires arrayValue");
|
"in Json::Value::operator[](ArrayIndex): requires arrayValue");
|
||||||
@ -930,14 +930,14 @@ Value &Value::operator[](ArrayIndex index) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::operator[](int index) {
|
Value& Value::operator[](int index) {
|
||||||
JSON_ASSERT_MESSAGE(
|
JSON_ASSERT_MESSAGE(
|
||||||
index >= 0,
|
index >= 0,
|
||||||
"in Json::Value::operator[](int index): index cannot be negative");
|
"in Json::Value::operator[](int index): index cannot be negative");
|
||||||
return (*this)[ArrayIndex(index)];
|
return (*this)[ArrayIndex(index)];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value &Value::operator[](ArrayIndex index) const {
|
const Value& Value::operator[](ArrayIndex index) const {
|
||||||
JSON_ASSERT_MESSAGE(
|
JSON_ASSERT_MESSAGE(
|
||||||
type_ == nullValue || type_ == arrayValue,
|
type_ == nullValue || type_ == arrayValue,
|
||||||
"in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
|
"in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
|
||||||
@ -950,23 +950,23 @@ const Value &Value::operator[](ArrayIndex index) const {
|
|||||||
return null;
|
return null;
|
||||||
return (*it).second;
|
return (*it).second;
|
||||||
#else
|
#else
|
||||||
Value *value = value_.array_->find(index);
|
Value* value = value_.array_->find(index);
|
||||||
return value ? *value : null;
|
return value ? *value : null;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value &Value::operator[](int index) const {
|
const Value& Value::operator[](int index) const {
|
||||||
JSON_ASSERT_MESSAGE(
|
JSON_ASSERT_MESSAGE(
|
||||||
index >= 0,
|
index >= 0,
|
||||||
"in Json::Value::operator[](int index) const: index cannot be negative");
|
"in Json::Value::operator[](int index) const: index cannot be negative");
|
||||||
return (*this)[ArrayIndex(index)];
|
return (*this)[ArrayIndex(index)];
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::operator[](const char *key) {
|
Value& Value::operator[](const char* key) {
|
||||||
return resolveReference(key, false);
|
return resolveReference(key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::resolveReference(const char *key, bool isStatic) {
|
Value& Value::resolveReference(const char* key, bool isStatic) {
|
||||||
JSON_ASSERT_MESSAGE(
|
JSON_ASSERT_MESSAGE(
|
||||||
type_ == nullValue || type_ == objectValue,
|
type_ == nullValue || type_ == objectValue,
|
||||||
"in Json::Value::resolveReference(): requires objectValue");
|
"in Json::Value::resolveReference(): requires objectValue");
|
||||||
@ -981,21 +981,21 @@ Value &Value::resolveReference(const char *key, bool isStatic) {
|
|||||||
|
|
||||||
ObjectValues::value_type defaultValue(actualKey, null);
|
ObjectValues::value_type defaultValue(actualKey, null);
|
||||||
it = value_.map_->insert(it, defaultValue);
|
it = value_.map_->insert(it, defaultValue);
|
||||||
Value &value = (*it).second;
|
Value& value = (*it).second;
|
||||||
return value;
|
return value;
|
||||||
#else
|
#else
|
||||||
return value_.map_->resolveReference(key, isStatic);
|
return value_.map_->resolveReference(key, isStatic);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Value::get(ArrayIndex index, const Value &defaultValue) const {
|
Value Value::get(ArrayIndex index, const Value& defaultValue) const {
|
||||||
const Value *value = &((*this)[index]);
|
const Value* value = &((*this)[index]);
|
||||||
return value == &null ? defaultValue : *value;
|
return value == &null ? defaultValue : *value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
|
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
|
||||||
|
|
||||||
const Value &Value::operator[](const char *key) const {
|
const Value& Value::operator[](const char* key) const {
|
||||||
JSON_ASSERT_MESSAGE(
|
JSON_ASSERT_MESSAGE(
|
||||||
type_ == nullValue || type_ == objectValue,
|
type_ == nullValue || type_ == objectValue,
|
||||||
"in Json::Value::operator[](char const*)const: requires objectValue");
|
"in Json::Value::operator[](char const*)const: requires objectValue");
|
||||||
@ -1008,45 +1008,45 @@ const Value &Value::operator[](const char *key) const {
|
|||||||
return null;
|
return null;
|
||||||
return (*it).second;
|
return (*it).second;
|
||||||
#else
|
#else
|
||||||
const Value *value = value_.map_->find(key);
|
const Value* value = value_.map_->find(key);
|
||||||
return value ? *value : null;
|
return value ? *value : null;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::operator[](const std::string &key) {
|
Value& Value::operator[](const std::string& key) {
|
||||||
return (*this)[key.c_str()];
|
return (*this)[key.c_str()];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value &Value::operator[](const std::string &key) const {
|
const Value& Value::operator[](const std::string& key) const {
|
||||||
return (*this)[key.c_str()];
|
return (*this)[key.c_str()];
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Value::operator[](const StaticString &key) {
|
Value& Value::operator[](const StaticString& key) {
|
||||||
return resolveReference(key, true);
|
return resolveReference(key, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
Value &Value::operator[](const CppTL::ConstString &key) {
|
Value& Value::operator[](const CppTL::ConstString& key) {
|
||||||
return (*this)[key.c_str()];
|
return (*this)[key.c_str()];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value &Value::operator[](const CppTL::ConstString &key) const {
|
const Value& Value::operator[](const CppTL::ConstString& key) const {
|
||||||
return (*this)[key.c_str()];
|
return (*this)[key.c_str()];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Value &Value::append(const Value &value) { return (*this)[size()] = value; }
|
Value& Value::append(const Value& value) { return (*this)[size()] = value; }
|
||||||
|
|
||||||
Value Value::get(const char *key, const Value &defaultValue) const {
|
Value Value::get(const char* key, const Value& defaultValue) const {
|
||||||
const Value *value = &((*this)[key]);
|
const Value* value = &((*this)[key]);
|
||||||
return value == &null ? defaultValue : *value;
|
return value == &null ? defaultValue : *value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Value::get(const std::string &key, const Value &defaultValue) const {
|
Value Value::get(const std::string& key, const Value& defaultValue) const {
|
||||||
return get(key.c_str(), defaultValue);
|
return get(key.c_str(), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Value::removeMember(const char *key) {
|
Value Value::removeMember(const char* key) {
|
||||||
JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue,
|
JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue,
|
||||||
"in Json::Value::removeMember(): requires objectValue");
|
"in Json::Value::removeMember(): requires objectValue");
|
||||||
if (type_ == nullValue)
|
if (type_ == nullValue)
|
||||||
@ -1060,7 +1060,7 @@ Value Value::removeMember(const char *key) {
|
|||||||
value_.map_->erase(it);
|
value_.map_->erase(it);
|
||||||
return old;
|
return old;
|
||||||
#else
|
#else
|
||||||
Value *value = value_.map_->find(key);
|
Value* value = value_.map_->find(key);
|
||||||
if (value) {
|
if (value) {
|
||||||
Value old(*value);
|
Value old(*value);
|
||||||
value_.map_.remove(key);
|
value_.map_.remove(key);
|
||||||
@ -1071,28 +1071,28 @@ Value Value::removeMember(const char *key) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Value::removeMember(const std::string &key) {
|
Value Value::removeMember(const std::string& key) {
|
||||||
return removeMember(key.c_str());
|
return removeMember(key.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
Value Value::get(const CppTL::ConstString &key,
|
Value Value::get(const CppTL::ConstString& key,
|
||||||
const Value &defaultValue) const {
|
const Value& defaultValue) const {
|
||||||
return get(key.c_str(), defaultValue);
|
return get(key.c_str(), defaultValue);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Value::isMember(const char *key) const {
|
bool Value::isMember(const char* key) const {
|
||||||
const Value *value = &((*this)[key]);
|
const Value* value = &((*this)[key]);
|
||||||
return value != &null;
|
return value != &null;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::isMember(const std::string &key) const {
|
bool Value::isMember(const std::string& key) const {
|
||||||
return isMember(key.c_str());
|
return isMember(key.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
bool Value::isMember(const CppTL::ConstString &key) const {
|
bool Value::isMember(const CppTL::ConstString& key) const {
|
||||||
return isMember(key.c_str());
|
return isMember(key.c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1243,13 +1243,13 @@ bool Value::isArray() const { return type_ == arrayValue; }
|
|||||||
|
|
||||||
bool Value::isObject() const { return type_ == objectValue; }
|
bool Value::isObject() const { return type_ == objectValue; }
|
||||||
|
|
||||||
void Value::setComment(const char *comment, CommentPlacement placement) {
|
void Value::setComment(const char* comment, CommentPlacement placement) {
|
||||||
if (!comments_)
|
if (!comments_)
|
||||||
comments_ = new CommentInfo[numberOfCommentPlacement];
|
comments_ = new CommentInfo[numberOfCommentPlacement];
|
||||||
comments_[placement].setComment(comment);
|
comments_[placement].setComment(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setComment(const std::string &comment, CommentPlacement placement) {
|
void Value::setComment(const std::string& comment, CommentPlacement placement) {
|
||||||
setComment(comment.c_str(), placement);
|
setComment(comment.c_str(), placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1404,21 +1404,21 @@ PathArgument::PathArgument() : key_(), index_(), kind_(kindNone) {}
|
|||||||
PathArgument::PathArgument(ArrayIndex index)
|
PathArgument::PathArgument(ArrayIndex index)
|
||||||
: key_(), index_(index), kind_(kindIndex) {}
|
: key_(), index_(index), kind_(kindIndex) {}
|
||||||
|
|
||||||
PathArgument::PathArgument(const char *key)
|
PathArgument::PathArgument(const char* key)
|
||||||
: key_(key), index_(), kind_(kindKey) {}
|
: key_(key), index_(), kind_(kindKey) {}
|
||||||
|
|
||||||
PathArgument::PathArgument(const std::string &key)
|
PathArgument::PathArgument(const std::string& key)
|
||||||
: key_(key.c_str()), index_(), kind_(kindKey) {}
|
: key_(key.c_str()), index_(), kind_(kindKey) {}
|
||||||
|
|
||||||
// class Path
|
// class Path
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Path::Path(const std::string &path,
|
Path::Path(const std::string& path,
|
||||||
const PathArgument &a1,
|
const PathArgument& a1,
|
||||||
const PathArgument &a2,
|
const PathArgument& a2,
|
||||||
const PathArgument &a3,
|
const PathArgument& a3,
|
||||||
const PathArgument &a4,
|
const PathArgument& a4,
|
||||||
const PathArgument &a5) {
|
const PathArgument& a5) {
|
||||||
InArgs in;
|
InArgs in;
|
||||||
in.push_back(&a1);
|
in.push_back(&a1);
|
||||||
in.push_back(&a2);
|
in.push_back(&a2);
|
||||||
@ -1428,9 +1428,9 @@ Path::Path(const std::string &path,
|
|||||||
makePath(path, in);
|
makePath(path, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Path::makePath(const std::string &path, const InArgs &in) {
|
void Path::makePath(const std::string& path, const InArgs& in) {
|
||||||
const char *current = path.c_str();
|
const char* current = path.c_str();
|
||||||
const char *end = current + path.length();
|
const char* end = current + path.length();
|
||||||
InArgs::const_iterator itInArg = in.begin();
|
InArgs::const_iterator itInArg = in.begin();
|
||||||
while (current != end) {
|
while (current != end) {
|
||||||
if (*current == '[') {
|
if (*current == '[') {
|
||||||
@ -1451,7 +1451,7 @@ void Path::makePath(const std::string &path, const InArgs &in) {
|
|||||||
} else if (*current == '.') {
|
} else if (*current == '.') {
|
||||||
++current;
|
++current;
|
||||||
} else {
|
} else {
|
||||||
const char *beginName = current;
|
const char* beginName = current;
|
||||||
while (current != end && !strchr("[.", *current))
|
while (current != end && !strchr("[.", *current))
|
||||||
++current;
|
++current;
|
||||||
args_.push_back(std::string(beginName, current));
|
args_.push_back(std::string(beginName, current));
|
||||||
@ -1459,9 +1459,9 @@ void Path::makePath(const std::string &path, const InArgs &in) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Path::addPathInArg(const std::string & /*path*/,
|
void Path::addPathInArg(const std::string& /*path*/,
|
||||||
const InArgs &in,
|
const InArgs& in,
|
||||||
InArgs::const_iterator &itInArg,
|
InArgs::const_iterator& itInArg,
|
||||||
PathArgument::Kind kind) {
|
PathArgument::Kind kind) {
|
||||||
if (itInArg == in.end()) {
|
if (itInArg == in.end()) {
|
||||||
// Error: missing argument %d
|
// Error: missing argument %d
|
||||||
@ -1472,14 +1472,14 @@ void Path::addPathInArg(const std::string & /*path*/,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Path::invalidPath(const std::string & /*path*/, int /*location*/) {
|
void Path::invalidPath(const std::string& /*path*/, int /*location*/) {
|
||||||
// Error: invalid path.
|
// Error: invalid path.
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value &Path::resolve(const Value &root) const {
|
const Value& Path::resolve(const Value& root) const {
|
||||||
const Value *node = &root;
|
const Value* node = &root;
|
||||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
||||||
const PathArgument &arg = *it;
|
const PathArgument& arg = *it;
|
||||||
if (arg.kind_ == PathArgument::kindIndex) {
|
if (arg.kind_ == PathArgument::kindIndex) {
|
||||||
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
|
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
|
||||||
// Error: unable to resolve path (array value expected at position...
|
// Error: unable to resolve path (array value expected at position...
|
||||||
@ -1499,10 +1499,10 @@ const Value &Path::resolve(const Value &root) const {
|
|||||||
return *node;
|
return *node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value Path::resolve(const Value &root, const Value &defaultValue) const {
|
Value Path::resolve(const Value& root, const Value& defaultValue) const {
|
||||||
const Value *node = &root;
|
const Value* node = &root;
|
||||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
||||||
const PathArgument &arg = *it;
|
const PathArgument& arg = *it;
|
||||||
if (arg.kind_ == PathArgument::kindIndex) {
|
if (arg.kind_ == PathArgument::kindIndex) {
|
||||||
if (!node->isArray() || !node->isValidIndex(arg.index_))
|
if (!node->isArray() || !node->isValidIndex(arg.index_))
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@ -1518,10 +1518,10 @@ Value Path::resolve(const Value &root, const Value &defaultValue) const {
|
|||||||
return *node;
|
return *node;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value &Path::make(Value &root) const {
|
Value& Path::make(Value& root) const {
|
||||||
Value *node = &root;
|
Value* node = &root;
|
||||||
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
|
||||||
const PathArgument &arg = *it;
|
const PathArgument& arg = *it;
|
||||||
if (arg.kind_ == PathArgument::kindIndex) {
|
if (arg.kind_ == PathArgument::kindIndex) {
|
||||||
if (!node->isArray()) {
|
if (!node->isArray()) {
|
||||||
// Error: node is not an array at position ...
|
// Error: node is not an array at position ...
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
static bool containsControlCharacter(const char *str) {
|
static bool containsControlCharacter(const char* str) {
|
||||||
while (*str) {
|
while (*str) {
|
||||||
if (isControlCharacter(*(str++)))
|
if (isControlCharacter(*(str++)))
|
||||||
return true;
|
return true;
|
||||||
@ -32,7 +32,7 @@ static bool containsControlCharacter(const char *str) {
|
|||||||
|
|
||||||
std::string valueToString(LargestInt value) {
|
std::string valueToString(LargestInt value) {
|
||||||
UIntToStringBuffer buffer;
|
UIntToStringBuffer buffer;
|
||||||
char *current = buffer + sizeof(buffer);
|
char* current = buffer + sizeof(buffer);
|
||||||
bool isNegative = value < 0;
|
bool isNegative = value < 0;
|
||||||
if (isNegative)
|
if (isNegative)
|
||||||
value = -value;
|
value = -value;
|
||||||
@ -45,7 +45,7 @@ std::string valueToString(LargestInt value) {
|
|||||||
|
|
||||||
std::string valueToString(LargestUInt value) {
|
std::string valueToString(LargestUInt value) {
|
||||||
UIntToStringBuffer buffer;
|
UIntToStringBuffer buffer;
|
||||||
char *current = buffer + sizeof(buffer);
|
char* current = buffer + sizeof(buffer);
|
||||||
uintToString(value, current);
|
uintToString(value, current);
|
||||||
assert(current >= buffer);
|
assert(current >= buffer);
|
||||||
return current;
|
return current;
|
||||||
@ -102,7 +102,7 @@ std::string valueToString(double value) {
|
|||||||
|
|
||||||
std::string valueToString(bool value) { return value ? "true" : "false"; }
|
std::string valueToString(bool value) { return value ? "true" : "false"; }
|
||||||
|
|
||||||
std::string valueToQuotedString(const char *value) {
|
std::string valueToQuotedString(const char* value) {
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
return "";
|
return "";
|
||||||
// Not sure how to handle unicode...
|
// Not sure how to handle unicode...
|
||||||
@ -117,7 +117,7 @@ std::string valueToQuotedString(const char *value) {
|
|||||||
std::string result;
|
std::string result;
|
||||||
result.reserve(maxsize); // to avoid lots of mallocs
|
result.reserve(maxsize); // to avoid lots of mallocs
|
||||||
result += "\"";
|
result += "\"";
|
||||||
for (const char *c = value; *c != 0; ++c) {
|
for (const char* c = value; *c != 0; ++c) {
|
||||||
switch (*c) {
|
switch (*c) {
|
||||||
case '\"':
|
case '\"':
|
||||||
result += "\\\"";
|
result += "\\\"";
|
||||||
@ -181,7 +181,7 @@ void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
|
|||||||
|
|
||||||
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
|
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
|
||||||
|
|
||||||
std::string FastWriter::write(const Value &root) {
|
std::string FastWriter::write(const Value& root) {
|
||||||
document_ = "";
|
document_ = "";
|
||||||
writeValue(root);
|
writeValue(root);
|
||||||
if (!omitEndingLineFeed_)
|
if (!omitEndingLineFeed_)
|
||||||
@ -189,7 +189,7 @@ std::string FastWriter::write(const Value &root) {
|
|||||||
return document_;
|
return document_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FastWriter::writeValue(const Value &value) {
|
void FastWriter::writeValue(const Value& value) {
|
||||||
switch (value.type()) {
|
switch (value.type()) {
|
||||||
case nullValue:
|
case nullValue:
|
||||||
if (!dropNullPlaceholders_)
|
if (!dropNullPlaceholders_)
|
||||||
@ -225,7 +225,7 @@ void FastWriter::writeValue(const Value &value) {
|
|||||||
document_ += "{";
|
document_ += "{";
|
||||||
for (Value::Members::iterator it = members.begin(); it != members.end();
|
for (Value::Members::iterator it = members.begin(); it != members.end();
|
||||||
++it) {
|
++it) {
|
||||||
const std::string &name = *it;
|
const std::string& name = *it;
|
||||||
if (it != members.begin())
|
if (it != members.begin())
|
||||||
document_ += ",";
|
document_ += ",";
|
||||||
document_ += valueToQuotedString(name.c_str());
|
document_ += valueToQuotedString(name.c_str());
|
||||||
@ -243,7 +243,7 @@ void FastWriter::writeValue(const Value &value) {
|
|||||||
StyledWriter::StyledWriter()
|
StyledWriter::StyledWriter()
|
||||||
: rightMargin_(74), indentSize_(3), addChildValues_() {}
|
: rightMargin_(74), indentSize_(3), addChildValues_() {}
|
||||||
|
|
||||||
std::string StyledWriter::write(const Value &root) {
|
std::string StyledWriter::write(const Value& root) {
|
||||||
document_ = "";
|
document_ = "";
|
||||||
addChildValues_ = false;
|
addChildValues_ = false;
|
||||||
indentString_ = "";
|
indentString_ = "";
|
||||||
@ -254,7 +254,7 @@ std::string StyledWriter::write(const Value &root) {
|
|||||||
return document_;
|
return document_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::writeValue(const Value &value) {
|
void StyledWriter::writeValue(const Value& value) {
|
||||||
switch (value.type()) {
|
switch (value.type()) {
|
||||||
case nullValue:
|
case nullValue:
|
||||||
pushValue("null");
|
pushValue("null");
|
||||||
@ -286,8 +286,8 @@ void StyledWriter::writeValue(const Value &value) {
|
|||||||
indent();
|
indent();
|
||||||
Value::Members::iterator it = members.begin();
|
Value::Members::iterator it = members.begin();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const std::string &name = *it;
|
const std::string& name = *it;
|
||||||
const Value &childValue = value[name];
|
const Value& childValue = value[name];
|
||||||
writeCommentBeforeValue(childValue);
|
writeCommentBeforeValue(childValue);
|
||||||
writeWithIndent(valueToQuotedString(name.c_str()));
|
writeWithIndent(valueToQuotedString(name.c_str()));
|
||||||
document_ += " : ";
|
document_ += " : ";
|
||||||
@ -306,7 +306,7 @@ void StyledWriter::writeValue(const Value &value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::writeArrayValue(const Value &value) {
|
void StyledWriter::writeArrayValue(const Value& value) {
|
||||||
unsigned size = value.size();
|
unsigned size = value.size();
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
pushValue("[]");
|
pushValue("[]");
|
||||||
@ -318,7 +318,7 @@ void StyledWriter::writeArrayValue(const Value &value) {
|
|||||||
bool hasChildValue = !childValues_.empty();
|
bool hasChildValue = !childValues_.empty();
|
||||||
unsigned index = 0;
|
unsigned index = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const Value &childValue = value[index];
|
const Value& childValue = value[index];
|
||||||
writeCommentBeforeValue(childValue);
|
writeCommentBeforeValue(childValue);
|
||||||
if (hasChildValue)
|
if (hasChildValue)
|
||||||
writeWithIndent(childValues_[index]);
|
writeWithIndent(childValues_[index]);
|
||||||
@ -349,12 +349,12 @@ void StyledWriter::writeArrayValue(const Value &value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyledWriter::isMultineArray(const Value &value) {
|
bool StyledWriter::isMultineArray(const Value& value) {
|
||||||
int size = value.size();
|
int size = value.size();
|
||||||
bool isMultiLine = size * 3 >= rightMargin_;
|
bool isMultiLine = size * 3 >= rightMargin_;
|
||||||
childValues_.clear();
|
childValues_.clear();
|
||||||
for (int index = 0; index < size && !isMultiLine; ++index) {
|
for (int index = 0; index < size && !isMultiLine; ++index) {
|
||||||
const Value &childValue = value[index];
|
const Value& childValue = value[index];
|
||||||
isMultiLine =
|
isMultiLine =
|
||||||
isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
|
isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
|
||||||
childValue.size() > 0);
|
childValue.size() > 0);
|
||||||
@ -374,7 +374,7 @@ bool StyledWriter::isMultineArray(const Value &value) {
|
|||||||
return isMultiLine;
|
return isMultiLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::pushValue(const std::string &value) {
|
void StyledWriter::pushValue(const std::string& value) {
|
||||||
if (addChildValues_)
|
if (addChildValues_)
|
||||||
childValues_.push_back(value);
|
childValues_.push_back(value);
|
||||||
else
|
else
|
||||||
@ -392,7 +392,7 @@ void StyledWriter::writeIndent() {
|
|||||||
document_ += indentString_;
|
document_ += indentString_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::writeWithIndent(const std::string &value) {
|
void StyledWriter::writeWithIndent(const std::string& value) {
|
||||||
writeIndent();
|
writeIndent();
|
||||||
document_ += value;
|
document_ += value;
|
||||||
}
|
}
|
||||||
@ -404,7 +404,7 @@ void StyledWriter::unindent() {
|
|||||||
indentString_.resize(indentString_.size() - indentSize_);
|
indentString_.resize(indentString_.size() - indentSize_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::writeCommentBeforeValue(const Value &root) {
|
void StyledWriter::writeCommentBeforeValue(const Value& root) {
|
||||||
if (!root.hasComment(commentBefore))
|
if (!root.hasComment(commentBefore))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ void StyledWriter::writeCommentBeforeValue(const Value &root) {
|
|||||||
document_ += "\n";
|
document_ += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) {
|
||||||
if (root.hasComment(commentAfterOnSameLine))
|
if (root.hasComment(commentAfterOnSameLine))
|
||||||
document_ += " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
|
document_ += " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
|
||||||
|
|
||||||
@ -434,18 +434,18 @@ void StyledWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyledWriter::hasCommentForValue(const Value &value) {
|
bool StyledWriter::hasCommentForValue(const Value& value) {
|
||||||
return value.hasComment(commentBefore) ||
|
return value.hasComment(commentBefore) ||
|
||||||
value.hasComment(commentAfterOnSameLine) ||
|
value.hasComment(commentAfterOnSameLine) ||
|
||||||
value.hasComment(commentAfter);
|
value.hasComment(commentAfter);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StyledWriter::normalizeEOL(const std::string &text) {
|
std::string StyledWriter::normalizeEOL(const std::string& text) {
|
||||||
std::string normalized;
|
std::string normalized;
|
||||||
normalized.reserve(text.length());
|
normalized.reserve(text.length());
|
||||||
const char *begin = text.c_str();
|
const char* begin = text.c_str();
|
||||||
const char *end = begin + text.length();
|
const char* end = begin + text.length();
|
||||||
const char *current = begin;
|
const char* current = begin;
|
||||||
while (current != end) {
|
while (current != end) {
|
||||||
char c = *current++;
|
char c = *current++;
|
||||||
if (c == '\r') // mac or dos EOL
|
if (c == '\r') // mac or dos EOL
|
||||||
@ -466,7 +466,7 @@ StyledStreamWriter::StyledStreamWriter(std::string indentation)
|
|||||||
: document_(NULL), rightMargin_(74), indentation_(indentation),
|
: document_(NULL), rightMargin_(74), indentation_(indentation),
|
||||||
addChildValues_() {}
|
addChildValues_() {}
|
||||||
|
|
||||||
void StyledStreamWriter::write(std::ostream &out, const Value &root) {
|
void StyledStreamWriter::write(std::ostream& out, const Value& root) {
|
||||||
document_ = &out;
|
document_ = &out;
|
||||||
addChildValues_ = false;
|
addChildValues_ = false;
|
||||||
indentString_ = "";
|
indentString_ = "";
|
||||||
@ -477,7 +477,7 @@ void StyledStreamWriter::write(std::ostream &out, const Value &root) {
|
|||||||
document_ = NULL; // Forget the stream, for safety.
|
document_ = NULL; // Forget the stream, for safety.
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::writeValue(const Value &value) {
|
void StyledStreamWriter::writeValue(const Value& value) {
|
||||||
switch (value.type()) {
|
switch (value.type()) {
|
||||||
case nullValue:
|
case nullValue:
|
||||||
pushValue("null");
|
pushValue("null");
|
||||||
@ -509,8 +509,8 @@ void StyledStreamWriter::writeValue(const Value &value) {
|
|||||||
indent();
|
indent();
|
||||||
Value::Members::iterator it = members.begin();
|
Value::Members::iterator it = members.begin();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const std::string &name = *it;
|
const std::string& name = *it;
|
||||||
const Value &childValue = value[name];
|
const Value& childValue = value[name];
|
||||||
writeCommentBeforeValue(childValue);
|
writeCommentBeforeValue(childValue);
|
||||||
writeWithIndent(valueToQuotedString(name.c_str()));
|
writeWithIndent(valueToQuotedString(name.c_str()));
|
||||||
*document_ << " : ";
|
*document_ << " : ";
|
||||||
@ -529,7 +529,7 @@ void StyledStreamWriter::writeValue(const Value &value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::writeArrayValue(const Value &value) {
|
void StyledStreamWriter::writeArrayValue(const Value& value) {
|
||||||
unsigned size = value.size();
|
unsigned size = value.size();
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
pushValue("[]");
|
pushValue("[]");
|
||||||
@ -541,7 +541,7 @@ void StyledStreamWriter::writeArrayValue(const Value &value) {
|
|||||||
bool hasChildValue = !childValues_.empty();
|
bool hasChildValue = !childValues_.empty();
|
||||||
unsigned index = 0;
|
unsigned index = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const Value &childValue = value[index];
|
const Value& childValue = value[index];
|
||||||
writeCommentBeforeValue(childValue);
|
writeCommentBeforeValue(childValue);
|
||||||
if (hasChildValue)
|
if (hasChildValue)
|
||||||
writeWithIndent(childValues_[index]);
|
writeWithIndent(childValues_[index]);
|
||||||
@ -572,12 +572,12 @@ void StyledStreamWriter::writeArrayValue(const Value &value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyledStreamWriter::isMultineArray(const Value &value) {
|
bool StyledStreamWriter::isMultineArray(const Value& value) {
|
||||||
int size = value.size();
|
int size = value.size();
|
||||||
bool isMultiLine = size * 3 >= rightMargin_;
|
bool isMultiLine = size * 3 >= rightMargin_;
|
||||||
childValues_.clear();
|
childValues_.clear();
|
||||||
for (int index = 0; index < size && !isMultiLine; ++index) {
|
for (int index = 0; index < size && !isMultiLine; ++index) {
|
||||||
const Value &childValue = value[index];
|
const Value& childValue = value[index];
|
||||||
isMultiLine =
|
isMultiLine =
|
||||||
isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
|
isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
|
||||||
childValue.size() > 0);
|
childValue.size() > 0);
|
||||||
@ -597,7 +597,7 @@ bool StyledStreamWriter::isMultineArray(const Value &value) {
|
|||||||
return isMultiLine;
|
return isMultiLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::pushValue(const std::string &value) {
|
void StyledStreamWriter::pushValue(const std::string& value) {
|
||||||
if (addChildValues_)
|
if (addChildValues_)
|
||||||
childValues_.push_back(value);
|
childValues_.push_back(value);
|
||||||
else
|
else
|
||||||
@ -620,7 +620,7 @@ void StyledStreamWriter::writeIndent() {
|
|||||||
*document_ << '\n' << indentString_;
|
*document_ << '\n' << indentString_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::writeWithIndent(const std::string &value) {
|
void StyledStreamWriter::writeWithIndent(const std::string& value) {
|
||||||
writeIndent();
|
writeIndent();
|
||||||
*document_ << value;
|
*document_ << value;
|
||||||
}
|
}
|
||||||
@ -632,14 +632,14 @@ void StyledStreamWriter::unindent() {
|
|||||||
indentString_.resize(indentString_.size() - indentation_.size());
|
indentString_.resize(indentString_.size() - indentation_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::writeCommentBeforeValue(const Value &root) {
|
void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
|
||||||
if (!root.hasComment(commentBefore))
|
if (!root.hasComment(commentBefore))
|
||||||
return;
|
return;
|
||||||
*document_ << normalizeEOL(root.getComment(commentBefore));
|
*document_ << normalizeEOL(root.getComment(commentBefore));
|
||||||
*document_ << "\n";
|
*document_ << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
|
||||||
if (root.hasComment(commentAfterOnSameLine))
|
if (root.hasComment(commentAfterOnSameLine))
|
||||||
*document_ << " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
|
*document_ << " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
|
||||||
|
|
||||||
@ -650,18 +650,18 @@ void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value &root) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyledStreamWriter::hasCommentForValue(const Value &value) {
|
bool StyledStreamWriter::hasCommentForValue(const Value& value) {
|
||||||
return value.hasComment(commentBefore) ||
|
return value.hasComment(commentBefore) ||
|
||||||
value.hasComment(commentAfterOnSameLine) ||
|
value.hasComment(commentAfterOnSameLine) ||
|
||||||
value.hasComment(commentAfter);
|
value.hasComment(commentAfter);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StyledStreamWriter::normalizeEOL(const std::string &text) {
|
std::string StyledStreamWriter::normalizeEOL(const std::string& text) {
|
||||||
std::string normalized;
|
std::string normalized;
|
||||||
normalized.reserve(text.length());
|
normalized.reserve(text.length());
|
||||||
const char *begin = text.c_str();
|
const char* begin = text.c_str();
|
||||||
const char *end = begin + text.length();
|
const char* end = begin + text.length();
|
||||||
const char *current = begin;
|
const char* current = begin;
|
||||||
while (current != end) {
|
while (current != end) {
|
||||||
char c = *current++;
|
char c = *current++;
|
||||||
if (c == '\r') // mac or dos EOL
|
if (c == '\r') // mac or dos EOL
|
||||||
@ -675,7 +675,7 @@ std::string StyledStreamWriter::normalizeEOL(const std::string &text) {
|
|||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &sout, const Value &root) {
|
std::ostream& operator<<(std::ostream& sout, const Value& root) {
|
||||||
Json::StyledStreamWriter writer;
|
Json::StyledStreamWriter writer;
|
||||||
writer.write(sout, root);
|
writer.write(sout, root);
|
||||||
return sout;
|
return sout;
|
||||||
|
@ -81,14 +81,14 @@ TestResult::TestResult()
|
|||||||
predicateStackTail_ = &rootPredicateNode_;
|
predicateStackTail_ = &rootPredicateNode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestResult::setTestName(const std::string &name) { name_ = name; }
|
void TestResult::setTestName(const std::string& name) { name_ = name; }
|
||||||
|
|
||||||
TestResult &
|
TestResult&
|
||||||
TestResult::addFailure(const char *file, unsigned int line, const char *expr) {
|
TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
|
||||||
/// Walks the PredicateContext stack adding them to failures_ if not already
|
/// Walks the PredicateContext stack adding them to failures_ if not already
|
||||||
/// added.
|
/// added.
|
||||||
unsigned int nestingLevel = 0;
|
unsigned int nestingLevel = 0;
|
||||||
PredicateContext *lastNode = rootPredicateNode_.next_;
|
PredicateContext* lastNode = rootPredicateNode_.next_;
|
||||||
for (; lastNode != 0; lastNode = lastNode->next_) {
|
for (; lastNode != 0; lastNode = lastNode->next_) {
|
||||||
if (lastNode->id_ > lastUsedPredicateId_) // new PredicateContext
|
if (lastNode->id_ > lastUsedPredicateId_) // new PredicateContext
|
||||||
{
|
{
|
||||||
@ -108,9 +108,9 @@ TestResult::addFailure(const char *file, unsigned int line, const char *expr) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestResult::addFailureInfo(const char *file,
|
void TestResult::addFailureInfo(const char* file,
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
const char *expr,
|
const char* expr,
|
||||||
unsigned int nestingLevel) {
|
unsigned int nestingLevel) {
|
||||||
Failure failure;
|
Failure failure;
|
||||||
failure.file_ = file;
|
failure.file_ = file;
|
||||||
@ -122,13 +122,13 @@ void TestResult::addFailureInfo(const char *file,
|
|||||||
failures_.push_back(failure);
|
failures_.push_back(failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult &TestResult::popPredicateContext() {
|
TestResult& TestResult::popPredicateContext() {
|
||||||
PredicateContext *lastNode = &rootPredicateNode_;
|
PredicateContext* lastNode = &rootPredicateNode_;
|
||||||
while (lastNode->next_ != 0 && lastNode->next_->next_ != 0) {
|
while (lastNode->next_ != 0 && lastNode->next_->next_ != 0) {
|
||||||
lastNode = lastNode->next_;
|
lastNode = lastNode->next_;
|
||||||
}
|
}
|
||||||
// Set message target to popped failure
|
// Set message target to popped failure
|
||||||
PredicateContext *tail = lastNode->next_;
|
PredicateContext* tail = lastNode->next_;
|
||||||
if (tail != 0 && tail->failure_ != 0) {
|
if (tail != 0 && tail->failure_ != 0) {
|
||||||
messageTarget_ = tail->failure_;
|
messageTarget_ = tail->failure_;
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ bool TestResult::failed() const { return !failures_.empty(); }
|
|||||||
|
|
||||||
unsigned int TestResult::getAssertionNestingLevel() const {
|
unsigned int TestResult::getAssertionNestingLevel() const {
|
||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
const PredicateContext *lastNode = &rootPredicateNode_;
|
const PredicateContext* lastNode = &rootPredicateNode_;
|
||||||
while (lastNode->next_ != 0) {
|
while (lastNode->next_ != 0) {
|
||||||
lastNode = lastNode->next_;
|
lastNode = lastNode->next_;
|
||||||
++level;
|
++level;
|
||||||
@ -162,7 +162,7 @@ void TestResult::printFailure(bool printTestName) const {
|
|||||||
// Print in reverse to display the callstack in the right order
|
// Print in reverse to display the callstack in the right order
|
||||||
Failures::const_iterator itEnd = failures_.end();
|
Failures::const_iterator itEnd = failures_.end();
|
||||||
for (Failures::const_iterator it = failures_.begin(); it != itEnd; ++it) {
|
for (Failures::const_iterator it = failures_.begin(); it != itEnd; ++it) {
|
||||||
const Failure &failure = *it;
|
const Failure& failure = *it;
|
||||||
std::string indent(failure.nestingLevel_ * 2, ' ');
|
std::string indent(failure.nestingLevel_ * 2, ' ');
|
||||||
if (failure.file_) {
|
if (failure.file_) {
|
||||||
printf("%s%s(%d): ", indent.c_str(), failure.file_, failure.line_);
|
printf("%s%s(%d): ", indent.c_str(), failure.file_, failure.line_);
|
||||||
@ -179,8 +179,8 @@ void TestResult::printFailure(bool printTestName) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TestResult::indentText(const std::string &text,
|
std::string TestResult::indentText(const std::string& text,
|
||||||
const std::string &indent) {
|
const std::string& indent) {
|
||||||
std::string reindented;
|
std::string reindented;
|
||||||
std::string::size_type lastIndex = 0;
|
std::string::size_type lastIndex = 0;
|
||||||
while (lastIndex < text.size()) {
|
while (lastIndex < text.size()) {
|
||||||
@ -195,22 +195,22 @@ std::string TestResult::indentText(const std::string &text,
|
|||||||
return reindented;
|
return reindented;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult &TestResult::addToLastFailure(const std::string &message) {
|
TestResult& TestResult::addToLastFailure(const std::string& message) {
|
||||||
if (messageTarget_ != 0) {
|
if (messageTarget_ != 0) {
|
||||||
messageTarget_->message_ += message;
|
messageTarget_->message_ += message;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult &TestResult::operator<<(Json::Int64 value) {
|
TestResult& TestResult::operator<<(Json::Int64 value) {
|
||||||
return addToLastFailure(Json::valueToString(value));
|
return addToLastFailure(Json::valueToString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult &TestResult::operator<<(Json::UInt64 value) {
|
TestResult& TestResult::operator<<(Json::UInt64 value) {
|
||||||
return addToLastFailure(Json::valueToString(value));
|
return addToLastFailure(Json::valueToString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult &TestResult::operator<<(bool value) {
|
TestResult& TestResult::operator<<(bool value) {
|
||||||
return addToLastFailure(value ? "true" : "false");
|
return addToLastFailure(value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ TestCase::TestCase() : result_(0) {}
|
|||||||
|
|
||||||
TestCase::~TestCase() {}
|
TestCase::~TestCase() {}
|
||||||
|
|
||||||
void TestCase::run(TestResult &result) {
|
void TestCase::run(TestResult& result) {
|
||||||
result_ = &result;
|
result_ = &result;
|
||||||
runTestCase();
|
runTestCase();
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ void TestCase::run(TestResult &result) {
|
|||||||
|
|
||||||
Runner::Runner() {}
|
Runner::Runner() {}
|
||||||
|
|
||||||
Runner &Runner::add(TestCaseFactory factory) {
|
Runner& Runner::add(TestCaseFactory factory) {
|
||||||
tests_.push_back(factory);
|
tests_.push_back(factory);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -241,14 +241,14 @@ unsigned int Runner::testCount() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string Runner::testNameAt(unsigned int index) const {
|
std::string Runner::testNameAt(unsigned int index) const {
|
||||||
TestCase *test = tests_[index]();
|
TestCase* test = tests_[index]();
|
||||||
std::string name = test->testName();
|
std::string name = test->testName();
|
||||||
delete test;
|
delete test;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner::runTestAt(unsigned int index, TestResult &result) const {
|
void Runner::runTestAt(unsigned int index, TestResult& result) const {
|
||||||
TestCase *test = tests_[index]();
|
TestCase* test = tests_[index]();
|
||||||
result.setTestName(test->testName());
|
result.setTestName(test->testName());
|
||||||
printf("Testing %s: ", test->testName());
|
printf("Testing %s: ", test->testName());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -258,13 +258,13 @@ void Runner::runTestAt(unsigned int index, TestResult &result) const {
|
|||||||
test->run(result);
|
test->run(result);
|
||||||
#if JSON_USE_EXCEPTION
|
#if JSON_USE_EXCEPTION
|
||||||
}
|
}
|
||||||
catch (const std::exception &e) {
|
catch (const std::exception& e) {
|
||||||
result.addFailure(__FILE__, __LINE__, "Unexpected exception caught:")
|
result.addFailure(__FILE__, __LINE__, "Unexpected exception caught:")
|
||||||
<< e.what();
|
<< e.what();
|
||||||
}
|
}
|
||||||
#endif // if JSON_USE_EXCEPTION
|
#endif // if JSON_USE_EXCEPTION
|
||||||
delete test;
|
delete test;
|
||||||
const char *status = result.failed() ? "FAILED" : "OK";
|
const char* status = result.failed() ? "FAILED" : "OK";
|
||||||
printf("%s\n", status);
|
printf("%s\n", status);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
@ -287,7 +287,7 @@ bool Runner::runAllTest(bool printSummary) const {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (unsigned int index = 0; index < failures.size(); ++index) {
|
for (unsigned int index = 0; index < failures.size(); ++index) {
|
||||||
TestResult &result = failures[index];
|
TestResult& result = failures[index];
|
||||||
result.printFailure(count > 1);
|
result.printFailure(count > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,8 +303,8 @@ bool Runner::runAllTest(bool printSummary) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Runner::testIndex(const std::string &testName,
|
bool Runner::testIndex(const std::string& testName,
|
||||||
unsigned int &indexOut) const {
|
unsigned int& indexOut) const {
|
||||||
unsigned int count = testCount();
|
unsigned int count = testCount();
|
||||||
for (unsigned int index = 0; index < count; ++index) {
|
for (unsigned int index = 0; index < count; ++index) {
|
||||||
if (testNameAt(index) == testName) {
|
if (testNameAt(index) == testName) {
|
||||||
@ -322,7 +322,7 @@ void Runner::listTests() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Runner::runCommandLine(int argc, const char *argv[]) const {
|
int Runner::runCommandLine(int argc, const char* argv[]) const {
|
||||||
typedef std::deque<std::string> TestNames;
|
typedef std::deque<std::string> TestNames;
|
||||||
Runner subrunner;
|
Runner subrunner;
|
||||||
for (int index = 1; index < argc; ++index) {
|
for (int index = 1; index < argc; ++index) {
|
||||||
@ -363,7 +363,7 @@ int Runner::runCommandLine(int argc, const char *argv[]) const {
|
|||||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
// Hook MSVCRT assertions to prevent dialog from appearing
|
// Hook MSVCRT assertions to prevent dialog from appearing
|
||||||
static int
|
static int
|
||||||
msvcrtSilentReportHook(int reportType, char *message, int * /*returnValue*/) {
|
msvcrtSilentReportHook(int reportType, char* message, int* /*returnValue*/) {
|
||||||
// The default CRT handling of error and assertion is to display
|
// The default CRT handling of error and assertion is to display
|
||||||
// an error dialog to the user.
|
// an error dialog to the user.
|
||||||
// Instead, when an error or an assertion occurs, we force the
|
// Instead, when an error or an assertion occurs, we force the
|
||||||
@ -409,7 +409,7 @@ void Runner::preventDialogOnCrash() {
|
|||||||
#endif // if defined(_WIN32)
|
#endif // if defined(_WIN32)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner::printUsage(const char *appName) {
|
void Runner::printUsage(const char* appName) {
|
||||||
printf("Usage: %s [options]\n"
|
printf("Usage: %s [options]\n"
|
||||||
"\n"
|
"\n"
|
||||||
"If --test is not specified, then all the test cases be run.\n"
|
"If --test is not specified, then all the test cases be run.\n"
|
||||||
@ -426,12 +426,12 @@ void Runner::printUsage(const char *appName) {
|
|||||||
// Assertion functions
|
// Assertion functions
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TestResult &checkStringEqual(TestResult &result,
|
TestResult& checkStringEqual(TestResult& result,
|
||||||
const std::string &expected,
|
const std::string& expected,
|
||||||
const std::string &actual,
|
const std::string& actual,
|
||||||
const char *file,
|
const char* file,
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
const char *expr) {
|
const char* expr) {
|
||||||
if (expected != actual) {
|
if (expected != actual) {
|
||||||
result.addFailure(file, line, expr);
|
result.addFailure(file, line, expr);
|
||||||
result << "Expected: '" << expected << "'\n";
|
result << "Expected: '" << expected << "'\n";
|
||||||
|
@ -30,7 +30,7 @@ namespace JsonTest {
|
|||||||
|
|
||||||
class Failure {
|
class Failure {
|
||||||
public:
|
public:
|
||||||
const char *file_;
|
const char* file_;
|
||||||
unsigned int line_;
|
unsigned int line_;
|
||||||
std::string expr_;
|
std::string expr_;
|
||||||
std::string message_;
|
std::string message_;
|
||||||
@ -43,13 +43,13 @@ public:
|
|||||||
struct PredicateContext {
|
struct PredicateContext {
|
||||||
typedef unsigned int Id;
|
typedef unsigned int Id;
|
||||||
Id id_;
|
Id id_;
|
||||||
const char *file_;
|
const char* file_;
|
||||||
unsigned int line_;
|
unsigned int line_;
|
||||||
const char *expr_;
|
const char* expr_;
|
||||||
PredicateContext *next_;
|
PredicateContext* next_;
|
||||||
/// Related Failure, set when the PredicateContext is converted
|
/// Related Failure, set when the PredicateContext is converted
|
||||||
/// into a Failure.
|
/// into a Failure.
|
||||||
Failure *failure_;
|
Failure* failure_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestResult {
|
class TestResult {
|
||||||
@ -63,25 +63,25 @@ public:
|
|||||||
PredicateContext::Id predicateId_;
|
PredicateContext::Id predicateId_;
|
||||||
|
|
||||||
/// \internal Implementation detail for predicate macros
|
/// \internal Implementation detail for predicate macros
|
||||||
PredicateContext *predicateStackTail_;
|
PredicateContext* predicateStackTail_;
|
||||||
|
|
||||||
void setTestName(const std::string &name);
|
void setTestName(const std::string& name);
|
||||||
|
|
||||||
/// Adds an assertion failure.
|
/// Adds an assertion failure.
|
||||||
TestResult &
|
TestResult&
|
||||||
addFailure(const char *file, unsigned int line, const char *expr = 0);
|
addFailure(const char* file, unsigned int line, const char* expr = 0);
|
||||||
|
|
||||||
/// Removes the last PredicateContext added to the predicate stack
|
/// Removes the last PredicateContext added to the predicate stack
|
||||||
/// chained list.
|
/// chained list.
|
||||||
/// Next messages will be targed at the PredicateContext that was removed.
|
/// Next messages will be targed at the PredicateContext that was removed.
|
||||||
TestResult &popPredicateContext();
|
TestResult& popPredicateContext();
|
||||||
|
|
||||||
bool failed() const;
|
bool failed() const;
|
||||||
|
|
||||||
void printFailure(bool printTestName) const;
|
void printFailure(bool printTestName) const;
|
||||||
|
|
||||||
// Generic operator that will work with anything ostream can deal with.
|
// Generic operator that will work with anything ostream can deal with.
|
||||||
template <typename T> TestResult &operator<<(const T &value) {
|
template <typename T> TestResult& operator<<(const T& value) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss.precision(16);
|
oss.precision(16);
|
||||||
oss.setf(std::ios_base::floatfield);
|
oss.setf(std::ios_base::floatfield);
|
||||||
@ -90,21 +90,21 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Specialized versions.
|
// Specialized versions.
|
||||||
TestResult &operator<<(bool value);
|
TestResult& operator<<(bool value);
|
||||||
// std:ostream does not support 64bits integers on all STL implementation
|
// std:ostream does not support 64bits integers on all STL implementation
|
||||||
TestResult &operator<<(Json::Int64 value);
|
TestResult& operator<<(Json::Int64 value);
|
||||||
TestResult &operator<<(Json::UInt64 value);
|
TestResult& operator<<(Json::UInt64 value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TestResult &addToLastFailure(const std::string &message);
|
TestResult& addToLastFailure(const std::string& message);
|
||||||
unsigned int getAssertionNestingLevel() const;
|
unsigned int getAssertionNestingLevel() const;
|
||||||
/// Adds a failure or a predicate context
|
/// Adds a failure or a predicate context
|
||||||
void addFailureInfo(const char *file,
|
void addFailureInfo(const char* file,
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
const char *expr,
|
const char* expr,
|
||||||
unsigned int nestingLevel);
|
unsigned int nestingLevel);
|
||||||
static std::string indentText(const std::string &text,
|
static std::string indentText(const std::string& text,
|
||||||
const std::string &indent);
|
const std::string& indent);
|
||||||
|
|
||||||
typedef std::deque<Failure> Failures;
|
typedef std::deque<Failure> Failures;
|
||||||
Failures failures_;
|
Failures failures_;
|
||||||
@ -112,7 +112,7 @@ private:
|
|||||||
PredicateContext rootPredicateNode_;
|
PredicateContext rootPredicateNode_;
|
||||||
PredicateContext::Id lastUsedPredicateId_;
|
PredicateContext::Id lastUsedPredicateId_;
|
||||||
/// Failure which is the target of the messages added using operator <<
|
/// Failure which is the target of the messages added using operator <<
|
||||||
Failure *messageTarget_;
|
Failure* messageTarget_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestCase {
|
class TestCase {
|
||||||
@ -121,32 +121,32 @@ public:
|
|||||||
|
|
||||||
virtual ~TestCase();
|
virtual ~TestCase();
|
||||||
|
|
||||||
void run(TestResult &result);
|
void run(TestResult& result);
|
||||||
|
|
||||||
virtual const char *testName() const = 0;
|
virtual const char* testName() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TestResult *result_;
|
TestResult* result_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void runTestCase() = 0;
|
virtual void runTestCase() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Function pointer type for TestCase factory
|
/// Function pointer type for TestCase factory
|
||||||
typedef TestCase *(*TestCaseFactory)();
|
typedef TestCase* (*TestCaseFactory)();
|
||||||
|
|
||||||
class Runner {
|
class Runner {
|
||||||
public:
|
public:
|
||||||
Runner();
|
Runner();
|
||||||
|
|
||||||
/// Adds a test to the suite
|
/// Adds a test to the suite
|
||||||
Runner &add(TestCaseFactory factory);
|
Runner& add(TestCaseFactory factory);
|
||||||
|
|
||||||
/// Runs test as specified on the command-line
|
/// Runs test as specified on the command-line
|
||||||
/// If no command-line arguments are provided, run all tests.
|
/// If no command-line arguments are provided, run all tests.
|
||||||
/// If --list-tests is provided, then print the list of all test cases
|
/// If --list-tests is provided, then print the list of all test cases
|
||||||
/// If --test <testname> is provided, then run test testname.
|
/// If --test <testname> is provided, then run test testname.
|
||||||
int runCommandLine(int argc, const char *argv[]) const;
|
int runCommandLine(int argc, const char* argv[]) const;
|
||||||
|
|
||||||
/// Runs all the test cases
|
/// Runs all the test cases
|
||||||
bool runAllTest(bool printSummary) const;
|
bool runAllTest(bool printSummary) const;
|
||||||
@ -158,17 +158,17 @@ public:
|
|||||||
std::string testNameAt(unsigned int index) const;
|
std::string testNameAt(unsigned int index) const;
|
||||||
|
|
||||||
/// Runs the test case at the specified index using the specified TestResult
|
/// Runs the test case at the specified index using the specified TestResult
|
||||||
void runTestAt(unsigned int index, TestResult &result) const;
|
void runTestAt(unsigned int index, TestResult& result) const;
|
||||||
|
|
||||||
static void printUsage(const char *appName);
|
static void printUsage(const char* appName);
|
||||||
|
|
||||||
private: // prevents copy construction and assignment
|
private: // prevents copy construction and assignment
|
||||||
Runner(const Runner &other);
|
Runner(const Runner& other);
|
||||||
Runner &operator=(const Runner &other);
|
Runner& operator=(const Runner& other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void listTests() const;
|
void listTests() const;
|
||||||
bool testIndex(const std::string &testName, unsigned int &index) const;
|
bool testIndex(const std::string& testName, unsigned int& index) const;
|
||||||
static void preventDialogOnCrash();
|
static void preventDialogOnCrash();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -177,12 +177,12 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
TestResult &checkEqual(TestResult &result,
|
TestResult& checkEqual(TestResult& result,
|
||||||
const T &expected,
|
const T& expected,
|
||||||
const U &actual,
|
const U& actual,
|
||||||
const char *file,
|
const char* file,
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
const char *expr) {
|
const char* expr) {
|
||||||
if (static_cast<U>(expected) != actual) {
|
if (static_cast<U>(expected) != actual) {
|
||||||
result.addFailure(file, line, expr);
|
result.addFailure(file, line, expr);
|
||||||
result << "Expected: " << static_cast<U>(expected) << "\n";
|
result << "Expected: " << static_cast<U>(expected) << "\n";
|
||||||
@ -191,12 +191,12 @@ TestResult &checkEqual(TestResult &result,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult &checkStringEqual(TestResult &result,
|
TestResult& checkStringEqual(TestResult& result,
|
||||||
const std::string &expected,
|
const std::string& expected,
|
||||||
const std::string &actual,
|
const std::string& actual,
|
||||||
const char *file,
|
const char* file,
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
const char *expr);
|
const char* expr);
|
||||||
|
|
||||||
} // namespace JsonTest
|
} // namespace JsonTest
|
||||||
|
|
||||||
@ -260,12 +260,12 @@ TestResult &checkStringEqual(TestResult &result,
|
|||||||
#define JSONTEST_FIXTURE(FixtureType, name) \
|
#define JSONTEST_FIXTURE(FixtureType, name) \
|
||||||
class Test##FixtureType##name : public FixtureType { \
|
class Test##FixtureType##name : public FixtureType { \
|
||||||
public: \
|
public: \
|
||||||
static JsonTest::TestCase *factory() { \
|
static JsonTest::TestCase* factory() { \
|
||||||
return new Test##FixtureType##name(); \
|
return new Test##FixtureType##name(); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
public: /* overidden from TestCase */ \
|
public: /* overidden from TestCase */ \
|
||||||
virtual const char *testName() const { return #FixtureType "/" #name; } \
|
virtual const char* testName() const { return #FixtureType "/" #name; } \
|
||||||
virtual void runTestCase(); \
|
virtual void runTestCase(); \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
|
@ -85,23 +85,23 @@ struct ValueTest : JsonTest::TestCase {
|
|||||||
bool isNumeric_;
|
bool isNumeric_;
|
||||||
};
|
};
|
||||||
|
|
||||||
void checkConstMemberCount(const Json::Value &value,
|
void checkConstMemberCount(const Json::Value& value,
|
||||||
unsigned int expectedCount);
|
unsigned int expectedCount);
|
||||||
|
|
||||||
void checkMemberCount(Json::Value &value, unsigned int expectedCount);
|
void checkMemberCount(Json::Value& value, unsigned int expectedCount);
|
||||||
|
|
||||||
void checkIs(const Json::Value &value, const IsCheck &check);
|
void checkIs(const Json::Value& value, const IsCheck& check);
|
||||||
|
|
||||||
void checkIsLess(const Json::Value &x, const Json::Value &y);
|
void checkIsLess(const Json::Value& x, const Json::Value& y);
|
||||||
|
|
||||||
void checkIsEqual(const Json::Value &x, const Json::Value &y);
|
void checkIsEqual(const Json::Value& x, const Json::Value& y);
|
||||||
|
|
||||||
/// Normalize the representation of floating-point number by stripped leading
|
/// Normalize the representation of floating-point number by stripped leading
|
||||||
/// 0 in exponent.
|
/// 0 in exponent.
|
||||||
static std::string normalizeFloatingPointStr(const std::string &s);
|
static std::string normalizeFloatingPointStr(const std::string& s);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string ValueTest::normalizeFloatingPointStr(const std::string &s) {
|
std::string ValueTest::normalizeFloatingPointStr(const std::string& s) {
|
||||||
std::string::size_type index = s.find_last_of("eE");
|
std::string::size_type index = s.find_last_of("eE");
|
||||||
if (index != std::string::npos) {
|
if (index != std::string::npos) {
|
||||||
std::string::size_type hasSign =
|
std::string::size_type hasSign =
|
||||||
@ -187,7 +187,7 @@ JSONTEST_FIXTURE(ValueTest, objects) {
|
|||||||
JSONTEST_ASSERT(!emptyObject_.isConvertibleTo(Json::stringValue));
|
JSONTEST_ASSERT(!emptyObject_.isConvertibleTo(Json::stringValue));
|
||||||
|
|
||||||
// Access through const reference
|
// Access through const reference
|
||||||
const Json::Value &constObject = object1_;
|
const Json::Value& constObject = object1_;
|
||||||
|
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constObject["id"]);
|
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constObject["id"]);
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value(), constObject["unknown id"]);
|
JSONTEST_ASSERT_EQUAL(Json::Value(), constObject["unknown id"]);
|
||||||
@ -229,7 +229,7 @@ JSONTEST_FIXTURE(ValueTest, arrays) {
|
|||||||
JSONTEST_ASSERT(!emptyArray_.isConvertibleTo(Json::stringValue));
|
JSONTEST_ASSERT(!emptyArray_.isConvertibleTo(Json::stringValue));
|
||||||
|
|
||||||
// Access through const reference
|
// Access through const reference
|
||||||
const Json::Value &constArray = array1_;
|
const Json::Value& constArray = array1_;
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[index0]);
|
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[index0]);
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[0]);
|
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[0]);
|
||||||
|
|
||||||
@ -1239,7 +1239,7 @@ JSONTEST_FIXTURE(ValueTest, nonIntegers) {
|
|||||||
normalizeFloatingPointStr(val.asString()));
|
normalizeFloatingPointStr(val.asString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValueTest::checkConstMemberCount(const Json::Value &value,
|
void ValueTest::checkConstMemberCount(const Json::Value& value,
|
||||||
unsigned int expectedCount) {
|
unsigned int expectedCount) {
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
Json::Value::const_iterator itEnd = value.end();
|
Json::Value::const_iterator itEnd = value.end();
|
||||||
@ -1249,7 +1249,7 @@ void ValueTest::checkConstMemberCount(const Json::Value &value,
|
|||||||
JSONTEST_ASSERT_EQUAL(expectedCount, count) << "Json::Value::const_iterator";
|
JSONTEST_ASSERT_EQUAL(expectedCount, count) << "Json::Value::const_iterator";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValueTest::checkMemberCount(Json::Value &value,
|
void ValueTest::checkMemberCount(Json::Value& value,
|
||||||
unsigned int expectedCount) {
|
unsigned int expectedCount) {
|
||||||
JSONTEST_ASSERT_EQUAL(expectedCount, value.size());
|
JSONTEST_ASSERT_EQUAL(expectedCount, value.size());
|
||||||
|
|
||||||
@ -1269,7 +1269,7 @@ ValueTest::IsCheck::IsCheck()
|
|||||||
isUInt64_(false), isIntegral_(false), isDouble_(false),
|
isUInt64_(false), isIntegral_(false), isDouble_(false),
|
||||||
isNumeric_(false) {}
|
isNumeric_(false) {}
|
||||||
|
|
||||||
void ValueTest::checkIs(const Json::Value &value, const IsCheck &check) {
|
void ValueTest::checkIs(const Json::Value& value, const IsCheck& check) {
|
||||||
JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject());
|
JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject());
|
||||||
JSONTEST_ASSERT_EQUAL(check.isArray_, value.isArray());
|
JSONTEST_ASSERT_EQUAL(check.isArray_, value.isArray());
|
||||||
JSONTEST_ASSERT_EQUAL(check.isBool_, value.isBool());
|
JSONTEST_ASSERT_EQUAL(check.isBool_, value.isBool());
|
||||||
@ -1384,7 +1384,7 @@ JSONTEST_FIXTURE(ValueTest, compareType) {
|
|||||||
Json::Value(Json::objectValue)));
|
Json::Value(Json::objectValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValueTest::checkIsLess(const Json::Value &x, const Json::Value &y) {
|
void ValueTest::checkIsLess(const Json::Value& x, const Json::Value& y) {
|
||||||
JSONTEST_ASSERT(x < y);
|
JSONTEST_ASSERT(x < y);
|
||||||
JSONTEST_ASSERT(y > x);
|
JSONTEST_ASSERT(y > x);
|
||||||
JSONTEST_ASSERT(x <= y);
|
JSONTEST_ASSERT(x <= y);
|
||||||
@ -1399,7 +1399,7 @@ void ValueTest::checkIsLess(const Json::Value &x, const Json::Value &y) {
|
|||||||
JSONTEST_ASSERT(y.compare(x) >= 0);
|
JSONTEST_ASSERT(y.compare(x) >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValueTest::checkIsEqual(const Json::Value &x, const Json::Value &y) {
|
void ValueTest::checkIsEqual(const Json::Value& x, const Json::Value& y) {
|
||||||
JSONTEST_ASSERT(x == y);
|
JSONTEST_ASSERT(x == y);
|
||||||
JSONTEST_ASSERT(y == x);
|
JSONTEST_ASSERT(y == x);
|
||||||
JSONTEST_ASSERT(x <= y);
|
JSONTEST_ASSERT(x <= y);
|
||||||
@ -1601,7 +1601,7 @@ JSONTEST_FIXTURE(ReaderTest, parseWithDetailError) {
|
|||||||
JSONTEST_ASSERT(errors.at(0).message == "Bad escape sequence in string");
|
JSONTEST_ASSERT(errors.at(0).message == "Bad escape sequence in string");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
JsonTest::Runner runner;
|
JsonTest::Runner runner;
|
||||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, checkNormalizeFloatingPointStr);
|
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, checkNormalizeFloatingPointStr);
|
||||||
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, memberCount);
|
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, memberCount);
|
||||||
|
Loading…
Reference in New Issue
Block a user