mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-01-19 00:46:02 +01:00
convert JSONCPP_STRING etc from macros to typedefs
This commit is contained in:
parent
6e7cbf8f54
commit
1c2ed7a10f
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define JSON_FAIL_MESSAGE(message) \
|
#define JSON_FAIL_MESSAGE(message) \
|
||||||
{ \
|
{ \
|
||||||
JSONCPP_OSTRINGSTREAM oss; \
|
OStringStream oss; \
|
||||||
oss << message; \
|
oss << message; \
|
||||||
Json::throwLogicError(oss.str()); \
|
Json::throwLogicError(oss.str()); \
|
||||||
abort(); \
|
abort(); \
|
||||||
@ -43,7 +43,7 @@
|
|||||||
// release builds we abort, for a core-dump or debugger.
|
// release builds we abort, for a core-dump or debugger.
|
||||||
#define JSON_FAIL_MESSAGE(message) \
|
#define JSON_FAIL_MESSAGE(message) \
|
||||||
{ \
|
{ \
|
||||||
JSONCPP_OSTRINGSTREAM oss; \
|
OStringStream oss; \
|
||||||
oss << message; \
|
oss << message; \
|
||||||
assert(false && oss.str().c_str()); \
|
assert(false && oss.str().c_str()); \
|
||||||
abort(); \
|
abort(); \
|
||||||
|
@ -6,8 +6,13 @@
|
|||||||
#ifndef JSON_CONFIG_H_INCLUDED
|
#ifndef JSON_CONFIG_H_INCLUDED
|
||||||
#define JSON_CONFIG_H_INCLUDED
|
#define JSON_CONFIG_H_INCLUDED
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint> //typedef int64_t, uint64_t
|
#include <cstdint>
|
||||||
#include <string> //typedef String
|
#include <istream>
|
||||||
|
#include <memory>
|
||||||
|
#include <ostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
/// If defined, indicates that json library is embedded in CppTL library.
|
/// If defined, indicates that json library is embedded in CppTL library.
|
||||||
//# define JSON_IN_CPPTL 1
|
//# define JSON_IN_CPPTL 1
|
||||||
@ -142,12 +147,9 @@ msvc_pre1900_c99_snprintf(char* outBuf, size_t size, const char* format, ...);
|
|||||||
|
|
||||||
#if !defined(JSON_IS_AMALGAMATION)
|
#if !defined(JSON_IS_AMALGAMATION)
|
||||||
|
|
||||||
|
#include "allocator.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
|
||||||
#include "allocator.h" //typedef Allocator
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // if !defined(JSON_IS_AMALGAMATION)
|
#endif // if !defined(JSON_IS_AMALGAMATION)
|
||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
@ -170,24 +172,28 @@ typedef Int64 LargestInt;
|
|||||||
typedef UInt64 LargestUInt;
|
typedef UInt64 LargestUInt;
|
||||||
#define JSON_HAS_INT64
|
#define JSON_HAS_INT64
|
||||||
#endif // if defined(JSON_NO_INT64)
|
#endif // if defined(JSON_NO_INT64)
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
|
||||||
#define JSONCPP_STRING \
|
template <typename T>
|
||||||
std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
|
using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY,
|
||||||
#define JSONCPP_OSTRINGSTREAM \
|
SecureAllocator<T>,
|
||||||
std::basic_ostringstream<char, std::char_traits<char>, \
|
std::allocator<T> >::type;
|
||||||
Json::SecureAllocator<char> >
|
using String =
|
||||||
#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char> >
|
std::basic_string<char, std::char_traits<char>, Allocator<char> >;
|
||||||
#define JSONCPP_ISTRINGSTREAM \
|
using IStringStream = std::basic_istringstream<String::value_type,
|
||||||
std::basic_istringstream<char, std::char_traits<char>, \
|
String::traits_type,
|
||||||
Json::SecureAllocator<char> >
|
String::allocator_type>;
|
||||||
#define JSONCPP_ISTREAM std::istream
|
using OStringStream = std::basic_ostringstream<String::value_type,
|
||||||
#else
|
String::traits_type,
|
||||||
#define JSONCPP_STRING std::string
|
String::allocator_type>;
|
||||||
#define JSONCPP_OSTRINGSTREAM std::ostringstream
|
using IStream = std::istream;
|
||||||
#define JSONCPP_OSTREAM std::ostream
|
using OStream = std::ostream;
|
||||||
#define JSONCPP_ISTRINGSTREAM std::istringstream
|
} // namespace Json
|
||||||
#define JSONCPP_ISTREAM std::istream
|
|
||||||
#endif // if JSONCPP_USING_SECURE_MEMORY
|
// Legacy names (formerly macros).
|
||||||
} // end namespace Json
|
using JSONCPP_STRING = Json::String;
|
||||||
|
using JSONCPP_ISTRINGSTREAM = Json::IStringStream;
|
||||||
|
using JSONCPP_OSTRINGSTREAM = Json::OStringStream;
|
||||||
|
using JSONCPP_ISTREAM = Json::IStream;
|
||||||
|
using JSONCPP_OSTREAM = Json::OStream;
|
||||||
|
|
||||||
#endif // JSON_CONFIG_H_INCLUDED
|
#endif // JSON_CONFIG_H_INCLUDED
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
struct StructuredError {
|
struct StructuredError {
|
||||||
ptrdiff_t offset_start;
|
ptrdiff_t offset_start;
|
||||||
ptrdiff_t offset_limit;
|
ptrdiff_t offset_limit;
|
||||||
JSONCPP_STRING message;
|
String message;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief Constructs a Reader allowing all features
|
/** \brief Constructs a Reader allowing all features
|
||||||
@ -103,7 +103,7 @@ public:
|
|||||||
|
|
||||||
/// \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(JSONCPP_ISTREAM& is, Value& root, bool collectComments = true);
|
bool parse(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.
|
||||||
@ -115,7 +115,7 @@ public:
|
|||||||
* \deprecated Use getFormattedErrorMessages() instead (typo fix).
|
* \deprecated Use getFormattedErrorMessages() instead (typo fix).
|
||||||
*/
|
*/
|
||||||
JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
|
JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
|
||||||
JSONCPP_STRING getFormatedErrorMessages() const;
|
String getFormatedErrorMessages() const;
|
||||||
|
|
||||||
/** \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.
|
||||||
@ -125,7 +125,7 @@ public:
|
|||||||
* occurred
|
* occurred
|
||||||
* during parsing.
|
* during parsing.
|
||||||
*/
|
*/
|
||||||
JSONCPP_STRING getFormattedErrorMessages() const;
|
String getFormattedErrorMessages() const;
|
||||||
|
|
||||||
/** \brief Returns a vector of structured erros encounted while parsing.
|
/** \brief Returns a vector of structured erros encounted while parsing.
|
||||||
* \return A (possibly empty) vector of StructuredError objects. Currently
|
* \return A (possibly empty) vector of StructuredError objects. Currently
|
||||||
@ -142,7 +142,7 @@ public:
|
|||||||
* \return \c true if the error was successfully added, \c false if the
|
* \return \c true if the error was successfully added, \c false if the
|
||||||
* Value offset exceeds the document size.
|
* Value offset exceeds the document size.
|
||||||
*/
|
*/
|
||||||
bool pushError(const Value& value, const JSONCPP_STRING& message);
|
bool pushError(const Value& value, const String& message);
|
||||||
|
|
||||||
/** \brief Add a semantic error message with extra context.
|
/** \brief Add a semantic error message with extra context.
|
||||||
* \param value JSON Value location associated with the error
|
* \param value JSON Value location associated with the error
|
||||||
@ -151,9 +151,7 @@ public:
|
|||||||
* \return \c true if the error was successfully added, \c false if either
|
* \return \c true if the error was successfully added, \c false if either
|
||||||
* Value offset exceeds the document size.
|
* Value offset exceeds the document size.
|
||||||
*/
|
*/
|
||||||
bool pushError(const Value& value,
|
bool pushError(const Value& value, const String& message, const Value& extra);
|
||||||
const JSONCPP_STRING& message,
|
|
||||||
const Value& extra);
|
|
||||||
|
|
||||||
/** \brief Return whether there are any errors.
|
/** \brief Return whether there are any errors.
|
||||||
* \return \c true if there are no errors to report \c false if
|
* \return \c true if there are no errors to report \c false if
|
||||||
@ -189,7 +187,7 @@ private:
|
|||||||
class ErrorInfo {
|
class ErrorInfo {
|
||||||
public:
|
public:
|
||||||
Token token_;
|
Token token_;
|
||||||
JSONCPP_STRING message_;
|
String message_;
|
||||||
Location extra_;
|
Location extra_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -209,7 +207,7 @@ private:
|
|||||||
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, JSONCPP_STRING& decoded);
|
bool decodeString(Token& token, 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,
|
||||||
@ -220,11 +218,9 @@ private:
|
|||||||
Location& current,
|
Location& current,
|
||||||
Location end,
|
Location end,
|
||||||
unsigned int& unicode);
|
unsigned int& unicode);
|
||||||
bool addError(const JSONCPP_STRING& message,
|
bool addError(const String& message, Token& token, Location extra = nullptr);
|
||||||
Token& token,
|
|
||||||
Location extra = nullptr);
|
|
||||||
bool recoverFromError(TokenType skipUntilToken);
|
bool recoverFromError(TokenType skipUntilToken);
|
||||||
bool addErrorAndRecover(const JSONCPP_STRING& message,
|
bool addErrorAndRecover(const String& message,
|
||||||
Token& token,
|
Token& token,
|
||||||
TokenType skipUntilToken);
|
TokenType skipUntilToken);
|
||||||
void skipUntilSpace();
|
void skipUntilSpace();
|
||||||
@ -232,23 +228,23 @@ private:
|
|||||||
Char getNextChar();
|
Char getNextChar();
|
||||||
void
|
void
|
||||||
getLocationLineAndColumn(Location location, int& line, int& column) const;
|
getLocationLineAndColumn(Location location, int& line, int& column) const;
|
||||||
JSONCPP_STRING getLocationLineAndColumn(Location location) const;
|
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);
|
||||||
|
|
||||||
static bool containsNewLine(Location begin, Location end);
|
static bool containsNewLine(Location begin, Location end);
|
||||||
static JSONCPP_STRING normalizeEOL(Location begin, Location end);
|
static String normalizeEOL(Location begin, Location end);
|
||||||
|
|
||||||
typedef std::stack<Value*> Nodes;
|
typedef std::stack<Value*> Nodes;
|
||||||
Nodes nodes_;
|
Nodes nodes_;
|
||||||
Errors errors_;
|
Errors errors_;
|
||||||
JSONCPP_STRING document_;
|
String document_;
|
||||||
Location begin_{};
|
Location begin_{};
|
||||||
Location end_{};
|
Location end_{};
|
||||||
Location current_{};
|
Location current_{};
|
||||||
Location lastValueEnd_{};
|
Location lastValueEnd_{};
|
||||||
Value* lastValue_{};
|
Value* lastValue_{};
|
||||||
JSONCPP_STRING commentsBefore_;
|
String commentsBefore_;
|
||||||
Features features_;
|
Features features_;
|
||||||
bool collectComments_{};
|
bool collectComments_{};
|
||||||
}; // Reader
|
}; // Reader
|
||||||
@ -279,7 +275,7 @@ public:
|
|||||||
virtual bool parse(char const* beginDoc,
|
virtual bool parse(char const* beginDoc,
|
||||||
char const* endDoc,
|
char const* endDoc,
|
||||||
Value* root,
|
Value* root,
|
||||||
JSONCPP_STRING* errs) = 0;
|
String* errs) = 0;
|
||||||
|
|
||||||
class JSON_API Factory {
|
class JSON_API Factory {
|
||||||
public:
|
public:
|
||||||
@ -299,7 +295,7 @@ Usage:
|
|||||||
CharReaderBuilder builder;
|
CharReaderBuilder builder;
|
||||||
builder["collectComments"] = false;
|
builder["collectComments"] = false;
|
||||||
Value value;
|
Value value;
|
||||||
JSONCPP_STRING errs;
|
String errs;
|
||||||
bool ok = parseFromStream(builder, std::cin, &value, &errs);
|
bool ok = parseFromStream(builder, std::cin, &value, &errs);
|
||||||
\endcode
|
\endcode
|
||||||
*/
|
*/
|
||||||
@ -359,7 +355,7 @@ public:
|
|||||||
|
|
||||||
/** A simple way to update a specific setting.
|
/** A simple way to update a specific setting.
|
||||||
*/
|
*/
|
||||||
Value& operator[](const JSONCPP_STRING& key);
|
Value& operator[](const String& key);
|
||||||
|
|
||||||
/** Called by ctor, but you can use this to reset settings_.
|
/** Called by ctor, but you can use this to reset settings_.
|
||||||
* \pre 'settings' != NULL (but Json::null is fine)
|
* \pre 'settings' != NULL (but Json::null is fine)
|
||||||
@ -380,7 +376,7 @@ public:
|
|||||||
* is convenient.
|
* is convenient.
|
||||||
*/
|
*/
|
||||||
bool JSON_API parseFromStream(CharReader::Factory const&,
|
bool JSON_API parseFromStream(CharReader::Factory const&,
|
||||||
JSONCPP_ISTREAM&,
|
IStream&,
|
||||||
Value* root,
|
Value* root,
|
||||||
std::string* errs);
|
std::string* errs);
|
||||||
|
|
||||||
@ -408,7 +404,7 @@ bool JSON_API parseFromStream(CharReader::Factory const&,
|
|||||||
\throw std::exception on parse error.
|
\throw std::exception on parse error.
|
||||||
\see Json::operator<<()
|
\see Json::operator<<()
|
||||||
*/
|
*/
|
||||||
JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
|
JSON_API IStream& operator>>(IStream&, Value&);
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
|
@ -54,12 +54,12 @@ namespace Json {
|
|||||||
*/
|
*/
|
||||||
class JSON_API Exception : public std::exception {
|
class JSON_API Exception : public std::exception {
|
||||||
public:
|
public:
|
||||||
Exception(JSONCPP_STRING msg);
|
Exception(String msg);
|
||||||
~Exception() JSONCPP_NOEXCEPT override;
|
~Exception() JSONCPP_NOEXCEPT override;
|
||||||
char const* what() const JSONCPP_NOEXCEPT override;
|
char const* what() const JSONCPP_NOEXCEPT override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JSONCPP_STRING msg_;
|
String msg_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Exceptions which the user cannot easily avoid.
|
/** Exceptions which the user cannot easily avoid.
|
||||||
@ -70,7 +70,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
class JSON_API RuntimeError : public Exception {
|
class JSON_API RuntimeError : public Exception {
|
||||||
public:
|
public:
|
||||||
RuntimeError(JSONCPP_STRING const& msg);
|
RuntimeError(String const& msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
|
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
|
||||||
@ -81,13 +81,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
class JSON_API LogicError : public Exception {
|
class JSON_API LogicError : public Exception {
|
||||||
public:
|
public:
|
||||||
LogicError(JSONCPP_STRING const& msg);
|
LogicError(String const& msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// used internally
|
/// used internally
|
||||||
JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg);
|
JSONCPP_NORETURN void throwRuntimeError(String const& msg);
|
||||||
/// used internally
|
/// used internally
|
||||||
JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg);
|
JSONCPP_NORETURN void throwLogicError(String const& msg);
|
||||||
|
|
||||||
/** \brief Type of the value held by a Value object.
|
/** \brief Type of the value held by a Value object.
|
||||||
*/
|
*/
|
||||||
@ -186,7 +186,7 @@ class JSON_API Value {
|
|||||||
friend class ValueIteratorBase;
|
friend class ValueIteratorBase;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::vector<JSONCPP_STRING> Members;
|
typedef std::vector<String> Members;
|
||||||
typedef ValueIterator iterator;
|
typedef ValueIterator iterator;
|
||||||
typedef ValueConstIterator const_iterator;
|
typedef ValueConstIterator const_iterator;
|
||||||
typedef Json::UInt UInt;
|
typedef Json::UInt UInt;
|
||||||
@ -332,8 +332,8 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
* \endcode
|
* \endcode
|
||||||
*/
|
*/
|
||||||
Value(const StaticString& value);
|
Value(const StaticString& value);
|
||||||
Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded
|
Value(const String& value); ///< Copy data() til size(). Embedded
|
||||||
///< zeroes too.
|
///< zeroes too.
|
||||||
#ifdef JSON_USE_CPPTL
|
#ifdef JSON_USE_CPPTL
|
||||||
Value(const CppTL::ConstString& value);
|
Value(const CppTL::ConstString& value);
|
||||||
#endif
|
#endif
|
||||||
@ -377,7 +377,7 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
unsigned getCStringLength() const; // Allows you to understand the length of
|
unsigned getCStringLength() const; // Allows you to understand the length of
|
||||||
// the CString
|
// the CString
|
||||||
#endif
|
#endif
|
||||||
JSONCPP_STRING asString() const; ///< Embedded zeroes are possible.
|
String asString() const; ///< Embedded zeroes are possible.
|
||||||
/** Get raw char* of string-value.
|
/** Get raw char* of string-value.
|
||||||
* \return false if !string. (Seg-fault if str or end are NULL.)
|
* \return false if !string. (Seg-fault if str or end are NULL.)
|
||||||
*/
|
*/
|
||||||
@ -484,11 +484,11 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
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.
|
||||||
/// \param key may contain embedded nulls.
|
/// \param key may contain embedded nulls.
|
||||||
Value& operator[](const JSONCPP_STRING& key);
|
Value& operator[](const 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.
|
||||||
/// \param key may contain embedded nulls.
|
/// \param key may contain embedded nulls.
|
||||||
const Value& operator[](const JSONCPP_STRING& key) const;
|
const Value& operator[](const 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.
|
||||||
|
|
||||||
@ -521,7 +521,7 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
/// Return the member named key if it exist, defaultValue otherwise.
|
/// Return the member named key if it exist, defaultValue otherwise.
|
||||||
/// \note deep copy
|
/// \note deep copy
|
||||||
/// \param key may contain embedded nulls.
|
/// \param key may contain embedded nulls.
|
||||||
Value get(const JSONCPP_STRING& key, const Value& defaultValue) const;
|
Value get(const 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.
|
||||||
/// \note deep copy
|
/// \note deep copy
|
||||||
@ -543,7 +543,7 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
void removeMember(const char* key);
|
void removeMember(const char* key);
|
||||||
/// Same as removeMember(const char*)
|
/// Same as removeMember(const char*)
|
||||||
/// \param key may contain embedded nulls.
|
/// \param key may contain embedded nulls.
|
||||||
void removeMember(const JSONCPP_STRING& key);
|
void removeMember(const String& key);
|
||||||
/// Same as removeMember(const char* begin, const char* end, Value* removed),
|
/// Same as removeMember(const char* begin, const char* end, Value* removed),
|
||||||
/// but 'key' is null-terminated.
|
/// but 'key' is null-terminated.
|
||||||
bool removeMember(const char* key, Value* removed);
|
bool removeMember(const char* key, Value* removed);
|
||||||
@ -553,8 +553,8 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
\param key may contain embedded nulls.
|
\param key may contain embedded nulls.
|
||||||
\return true iff removed (no exceptions)
|
\return true iff removed (no exceptions)
|
||||||
*/
|
*/
|
||||||
bool removeMember(JSONCPP_STRING const& key, Value* removed);
|
bool removeMember(String const& key, Value* removed);
|
||||||
/// Same as removeMember(JSONCPP_STRING const& key, Value* removed)
|
/// Same as removeMember(String const& key, Value* removed)
|
||||||
bool removeMember(const char* begin, const char* end, Value* removed);
|
bool removeMember(const char* begin, const char* end, Value* removed);
|
||||||
/** \brief Remove the indexed array element.
|
/** \brief Remove the indexed array element.
|
||||||
|
|
||||||
@ -569,8 +569,8 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
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.
|
||||||
/// \param key may contain embedded nulls.
|
/// \param key may contain embedded nulls.
|
||||||
bool isMember(const JSONCPP_STRING& key) const;
|
bool isMember(const String& key) const;
|
||||||
/// Same as isMember(JSONCPP_STRING const& key)const
|
/// Same as isMember(String const& key)const
|
||||||
bool isMember(const char* begin, const char* end) const;
|
bool isMember(const char* begin, const char* end) 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.
|
||||||
@ -590,17 +590,17 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
//# endif
|
//# endif
|
||||||
|
|
||||||
/// \deprecated Always pass len.
|
/// \deprecated Always pass len.
|
||||||
JSONCPP_DEPRECATED("Use setComment(JSONCPP_STRING const&) instead.")
|
JSONCPP_DEPRECATED("Use setComment(String const&) instead.")
|
||||||
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 char* comment, size_t len, CommentPlacement placement);
|
void setComment(const char* comment, size_t len, CommentPlacement placement);
|
||||||
/// Comments must be //... or /* ... */
|
/// Comments must be //... or /* ... */
|
||||||
void setComment(const JSONCPP_STRING& comment, CommentPlacement placement);
|
void setComment(const String& comment, CommentPlacement placement);
|
||||||
bool hasComment(CommentPlacement placement) const;
|
bool hasComment(CommentPlacement placement) const;
|
||||||
/// Include delimiters and embedded newlines.
|
/// Include delimiters and embedded newlines.
|
||||||
JSONCPP_STRING getComment(CommentPlacement placement) const;
|
String getComment(CommentPlacement placement) const;
|
||||||
|
|
||||||
JSONCPP_STRING toStyledString() const;
|
String toStyledString() const;
|
||||||
|
|
||||||
const_iterator begin() const;
|
const_iterator begin() const;
|
||||||
const_iterator end() const;
|
const_iterator end() const;
|
||||||
@ -673,11 +673,11 @@ public:
|
|||||||
PathArgument();
|
PathArgument();
|
||||||
PathArgument(ArrayIndex index);
|
PathArgument(ArrayIndex index);
|
||||||
PathArgument(const char* key);
|
PathArgument(const char* key);
|
||||||
PathArgument(const JSONCPP_STRING& key);
|
PathArgument(const String& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Kind { kindNone = 0, kindIndex, kindKey };
|
enum Kind { kindNone = 0, kindIndex, kindKey };
|
||||||
JSONCPP_STRING key_;
|
String key_;
|
||||||
ArrayIndex index_{};
|
ArrayIndex index_{};
|
||||||
Kind kind_{ kindNone };
|
Kind kind_{ kindNone };
|
||||||
};
|
};
|
||||||
@ -695,7 +695,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
class JSON_API Path {
|
class JSON_API Path {
|
||||||
public:
|
public:
|
||||||
Path(const JSONCPP_STRING& path,
|
Path(const 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(),
|
||||||
@ -712,12 +712,12 @@ 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 JSONCPP_STRING& path, const InArgs& in);
|
void makePath(const String& path, const InArgs& in);
|
||||||
void addPathInArg(const JSONCPP_STRING& path,
|
void addPathInArg(const String& path,
|
||||||
const InArgs& in,
|
const InArgs& in,
|
||||||
InArgs::const_iterator& itInArg,
|
InArgs::const_iterator& itInArg,
|
||||||
PathArgument::Kind kind);
|
PathArgument::Kind kind);
|
||||||
static void invalidPath(const JSONCPP_STRING& path, int location);
|
static void invalidPath(const String& path, int location);
|
||||||
|
|
||||||
Args args_;
|
Args args_;
|
||||||
};
|
};
|
||||||
@ -751,7 +751,7 @@ public:
|
|||||||
/// Return the member name of the referenced Value, or "" if it is not an
|
/// Return the member name of the referenced Value, or "" if it is not an
|
||||||
/// objectValue.
|
/// objectValue.
|
||||||
/// \note Avoid `c_str()` on result, as embedded zeroes are possible.
|
/// \note Avoid `c_str()` on result, as embedded zeroes are possible.
|
||||||
JSONCPP_STRING name() const;
|
String name() const;
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -41,7 +41,7 @@ Usage:
|
|||||||
*/
|
*/
|
||||||
class JSON_API StreamWriter {
|
class JSON_API StreamWriter {
|
||||||
protected:
|
protected:
|
||||||
JSONCPP_OSTREAM* sout_; // not owned; will not delete
|
OStream* sout_; // not owned; will not delete
|
||||||
public:
|
public:
|
||||||
StreamWriter();
|
StreamWriter();
|
||||||
virtual ~StreamWriter();
|
virtual ~StreamWriter();
|
||||||
@ -51,7 +51,7 @@ public:
|
|||||||
\return zero on success (For now, we always return zero, so check the
|
\return zero on success (For now, we always return zero, so check the
|
||||||
stream instead.) \throw std::exception possibly, depending on configuration
|
stream instead.) \throw std::exception possibly, depending on configuration
|
||||||
*/
|
*/
|
||||||
virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;
|
virtual int write(Value const& root, OStream* sout) = 0;
|
||||||
|
|
||||||
/** \brief A simple abstract factory.
|
/** \brief A simple abstract factory.
|
||||||
*/
|
*/
|
||||||
@ -68,8 +68,8 @@ public:
|
|||||||
/** \brief Write into stringstream, then return string, for convenience.
|
/** \brief Write into stringstream, then return string, for convenience.
|
||||||
* A StreamWriter will be created from the factory, used, and then deleted.
|
* A StreamWriter will be created from the factory, used, and then deleted.
|
||||||
*/
|
*/
|
||||||
JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory,
|
String JSON_API writeString(StreamWriter::Factory const& factory,
|
||||||
Value const& root);
|
Value const& root);
|
||||||
|
|
||||||
/** \brief Build a StreamWriter implementation.
|
/** \brief Build a StreamWriter implementation.
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ public:
|
|||||||
bool validate(Json::Value* invalid) const;
|
bool validate(Json::Value* invalid) const;
|
||||||
/** A simple way to update a specific setting.
|
/** A simple way to update a specific setting.
|
||||||
*/
|
*/
|
||||||
Value& operator[](const JSONCPP_STRING& key);
|
Value& operator[](const String& key);
|
||||||
|
|
||||||
/** Called by ctor, but you can use this to reset settings_.
|
/** Called by ctor, but you can use this to reset settings_.
|
||||||
* \pre 'settings' != NULL (but Json::null is fine)
|
* \pre 'settings' != NULL (but Json::null is fine)
|
||||||
@ -149,7 +149,7 @@ class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
|
|||||||
public:
|
public:
|
||||||
virtual ~Writer();
|
virtual ~Writer();
|
||||||
|
|
||||||
virtual JSONCPP_STRING write(const Value& root) = 0;
|
virtual 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
|
||||||
@ -183,12 +183,12 @@ public:
|
|||||||
void omitEndingLineFeed();
|
void omitEndingLineFeed();
|
||||||
|
|
||||||
public: // overridden from Writer
|
public: // overridden from Writer
|
||||||
JSONCPP_STRING write(const Value& root) override;
|
String write(const Value& root) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue(const Value& value);
|
void writeValue(const Value& value);
|
||||||
|
|
||||||
JSONCPP_STRING document_;
|
String document_;
|
||||||
bool yamlCompatibilityEnabled_{ false };
|
bool yamlCompatibilityEnabled_{ false };
|
||||||
bool dropNullPlaceholders_{ false };
|
bool dropNullPlaceholders_{ false };
|
||||||
bool omitEndingLineFeed_{ false };
|
bool omitEndingLineFeed_{ false };
|
||||||
@ -236,27 +236,27 @@ 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.
|
||||||
*/
|
*/
|
||||||
JSONCPP_STRING write(const Value& root) override;
|
String write(const Value& root) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue(const Value& value);
|
void writeValue(const Value& value);
|
||||||
void writeArrayValue(const Value& value);
|
void writeArrayValue(const Value& value);
|
||||||
bool isMultilineArray(const Value& value);
|
bool isMultilineArray(const Value& value);
|
||||||
void pushValue(const JSONCPP_STRING& value);
|
void pushValue(const String& value);
|
||||||
void writeIndent();
|
void writeIndent();
|
||||||
void writeWithIndent(const JSONCPP_STRING& value);
|
void writeWithIndent(const 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);
|
||||||
static bool hasCommentForValue(const Value& value);
|
static bool hasCommentForValue(const Value& value);
|
||||||
static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
|
static String normalizeEOL(const String& text);
|
||||||
|
|
||||||
typedef std::vector<JSONCPP_STRING> ChildValues;
|
typedef std::vector<String> ChildValues;
|
||||||
|
|
||||||
ChildValues childValues_;
|
ChildValues childValues_;
|
||||||
JSONCPP_STRING document_;
|
String document_;
|
||||||
JSONCPP_STRING indentString_;
|
String indentString_;
|
||||||
unsigned int rightMargin_{ 74 };
|
unsigned int rightMargin_{ 74 };
|
||||||
unsigned int indentSize_{ 3 };
|
unsigned int indentSize_{ 3 };
|
||||||
bool addChildValues_{ false };
|
bool addChildValues_{ false };
|
||||||
@ -300,7 +300,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* \param indentation Each level will be indented by this amount extra.
|
* \param indentation Each level will be indented by this amount extra.
|
||||||
*/
|
*/
|
||||||
StyledStreamWriter(JSONCPP_STRING indentation = "\t");
|
StyledStreamWriter(String indentation = "\t");
|
||||||
~StyledStreamWriter() = default;
|
~StyledStreamWriter() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -310,29 +310,29 @@ 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(JSONCPP_OSTREAM& out, const Value& root);
|
void write(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 isMultilineArray(const Value& value);
|
bool isMultilineArray(const Value& value);
|
||||||
void pushValue(const JSONCPP_STRING& value);
|
void pushValue(const String& value);
|
||||||
void writeIndent();
|
void writeIndent();
|
||||||
void writeWithIndent(const JSONCPP_STRING& value);
|
void writeWithIndent(const 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);
|
||||||
static bool hasCommentForValue(const Value& value);
|
static bool hasCommentForValue(const Value& value);
|
||||||
static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
|
static String normalizeEOL(const String& text);
|
||||||
|
|
||||||
typedef std::vector<JSONCPP_STRING> ChildValues;
|
typedef std::vector<String> ChildValues;
|
||||||
|
|
||||||
ChildValues childValues_;
|
ChildValues childValues_;
|
||||||
JSONCPP_OSTREAM* document_;
|
OStream* document_;
|
||||||
JSONCPP_STRING indentString_;
|
String indentString_;
|
||||||
unsigned int rightMargin_{ 74 };
|
unsigned int rightMargin_{ 74 };
|
||||||
JSONCPP_STRING indentation_;
|
String indentation_;
|
||||||
bool addChildValues_ : 1;
|
bool addChildValues_ : 1;
|
||||||
bool indented_ : 1;
|
bool indented_ : 1;
|
||||||
};
|
};
|
||||||
@ -341,21 +341,21 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(JSON_HAS_INT64)
|
#if defined(JSON_HAS_INT64)
|
||||||
JSONCPP_STRING JSON_API valueToString(Int value);
|
String JSON_API valueToString(Int value);
|
||||||
JSONCPP_STRING JSON_API valueToString(UInt value);
|
String JSON_API valueToString(UInt value);
|
||||||
#endif // if defined(JSON_HAS_INT64)
|
#endif // if defined(JSON_HAS_INT64)
|
||||||
JSONCPP_STRING JSON_API valueToString(LargestInt value);
|
String JSON_API valueToString(LargestInt value);
|
||||||
JSONCPP_STRING JSON_API valueToString(LargestUInt value);
|
String JSON_API valueToString(LargestUInt value);
|
||||||
JSONCPP_STRING JSON_API
|
String JSON_API
|
||||||
valueToString(double value,
|
valueToString(double value,
|
||||||
unsigned int precision = Value::defaultRealPrecision,
|
unsigned int precision = Value::defaultRealPrecision,
|
||||||
PrecisionType precisionType = PrecisionType::significantDigits);
|
PrecisionType precisionType = PrecisionType::significantDigits);
|
||||||
JSONCPP_STRING JSON_API valueToString(bool value);
|
String JSON_API valueToString(bool value);
|
||||||
JSONCPP_STRING JSON_API valueToQuotedString(const char* value);
|
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 JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
|
JSON_API OStream& operator<<(OStream&, const Value& root);
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
|
@ -19,29 +19,28 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
JSONCPP_STRING path;
|
Json::String path;
|
||||||
Json::Features features;
|
Json::Features features;
|
||||||
bool parseOnly;
|
bool parseOnly;
|
||||||
typedef JSONCPP_STRING (*writeFuncType)(Json::Value const&);
|
using writeFuncType = Json::String(*)(Json::Value const&);
|
||||||
writeFuncType write;
|
writeFuncType write;
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSONCPP_STRING normalizeFloatingPointStr(double value) {
|
static Json::String normalizeFloatingPointStr(double value) {
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
jsoncpp_snprintf(buffer, sizeof(buffer), "%.16g", value);
|
jsoncpp_snprintf(buffer, sizeof(buffer), "%.16g", value);
|
||||||
buffer[sizeof(buffer) - 1] = 0;
|
buffer[sizeof(buffer) - 1] = 0;
|
||||||
JSONCPP_STRING s(buffer);
|
Json::String s(buffer);
|
||||||
JSONCPP_STRING::size_type index = s.find_last_of("eE");
|
Json::String::size_type index = s.find_last_of("eE");
|
||||||
if (index != JSONCPP_STRING::npos) {
|
if (index != Json::String::npos) {
|
||||||
JSONCPP_STRING::size_type hasSign =
|
Json::String::size_type hasSign =
|
||||||
(s[index + 1] == '+' || s[index + 1] == '-') ? 1 : 0;
|
(s[index + 1] == '+' || s[index + 1] == '-') ? 1 : 0;
|
||||||
JSONCPP_STRING::size_type exponentStartIndex = index + 1 + hasSign;
|
Json::String::size_type exponentStartIndex = index + 1 + hasSign;
|
||||||
JSONCPP_STRING normalized = s.substr(0, exponentStartIndex);
|
Json::String normalized = s.substr(0, exponentStartIndex);
|
||||||
JSONCPP_STRING::size_type indexDigit =
|
Json::String::size_type indexDigit = s.find_first_not_of('0', exponentStartIndex);
|
||||||
s.find_first_not_of('0', exponentStartIndex);
|
Json::String exponent = "0";
|
||||||
JSONCPP_STRING exponent = "0";
|
if (indexDigit != Json::String::npos) // There is an exponent different
|
||||||
if (indexDigit != JSONCPP_STRING::npos) // There is an exponent different
|
// from 0
|
||||||
// from 0
|
|
||||||
{
|
{
|
||||||
exponent = s.substr(indexDigit);
|
exponent = s.substr(indexDigit);
|
||||||
}
|
}
|
||||||
@ -50,17 +49,17 @@ static JSONCPP_STRING normalizeFloatingPointStr(double value) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSONCPP_STRING readInputTestFile(const char* path) {
|
static Json::String readInputTestFile(const char* path) {
|
||||||
FILE* file = fopen(path, "rb");
|
FILE* file = fopen(path, "rb");
|
||||||
if (!file)
|
if (!file)
|
||||||
return JSONCPP_STRING("");
|
return "";
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
long const size = ftell(file);
|
long const size = ftell(file);
|
||||||
size_t const usize = static_cast<unsigned long>(size);
|
size_t const usize = static_cast<unsigned long>(size);
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
JSONCPP_STRING text;
|
|
||||||
char* buffer = new char[size + 1];
|
char* buffer = new char[size + 1];
|
||||||
buffer[size] = 0;
|
buffer[size] = 0;
|
||||||
|
Json::String text;
|
||||||
if (fread(buffer, 1, usize, file) == usize)
|
if (fread(buffer, 1, usize, file) == usize)
|
||||||
text = buffer;
|
text = buffer;
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@ -68,9 +67,8 @@ static JSONCPP_STRING readInputTestFile(const char* path) {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printValueTree(FILE* fout,
|
static void
|
||||||
Json::Value& value,
|
printValueTree(FILE* fout, Json::Value& value, const Json::String& path = ".") {
|
||||||
const JSONCPP_STRING& path = ".") {
|
|
||||||
if (value.hasComment(Json::commentBefore)) {
|
if (value.hasComment(Json::commentBefore)) {
|
||||||
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
|
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
|
||||||
}
|
}
|
||||||
@ -109,7 +107,7 @@ static void printValueTree(FILE* fout,
|
|||||||
fprintf(fout, "%s={}\n", path.c_str());
|
fprintf(fout, "%s={}\n", path.c_str());
|
||||||
Json::Value::Members members(value.getMemberNames());
|
Json::Value::Members members(value.getMemberNames());
|
||||||
std::sort(members.begin(), members.end());
|
std::sort(members.begin(), members.end());
|
||||||
JSONCPP_STRING suffix = *(path.end() - 1) == '.' ? "" : ".";
|
Json::String suffix = *(path.end() - 1) == '.' ? "" : ".";
|
||||||
for (auto name : members) {
|
for (auto name : members) {
|
||||||
printValueTree(fout, value[name], path + suffix + name);
|
printValueTree(fout, value[name], path + suffix + name);
|
||||||
}
|
}
|
||||||
@ -123,9 +121,9 @@ static void printValueTree(FILE* fout,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parseAndSaveValueTree(const JSONCPP_STRING& input,
|
static int parseAndSaveValueTree(const Json::String& input,
|
||||||
const JSONCPP_STRING& actual,
|
const Json::String& actual,
|
||||||
const JSONCPP_STRING& kind,
|
const Json::String& kind,
|
||||||
const Json::Features& features,
|
const Json::Features& features,
|
||||||
bool parseOnly,
|
bool parseOnly,
|
||||||
Json::Value* root) {
|
Json::Value* root) {
|
||||||
@ -148,29 +146,29 @@ static int parseAndSaveValueTree(const JSONCPP_STRING& input,
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// static JSONCPP_STRING useFastWriter(Json::Value const& root) {
|
// static Json::String useFastWriter(Json::Value const& root) {
|
||||||
// Json::FastWriter writer;
|
// Json::FastWriter writer;
|
||||||
// writer.enableYAMLCompatibility();
|
// writer.enableYAMLCompatibility();
|
||||||
// return writer.write(root);
|
// return writer.write(root);
|
||||||
// }
|
// }
|
||||||
static JSONCPP_STRING useStyledWriter(Json::Value const& root) {
|
static Json::String useStyledWriter(Json::Value const& root) {
|
||||||
Json::StyledWriter writer;
|
Json::StyledWriter writer;
|
||||||
return writer.write(root);
|
return writer.write(root);
|
||||||
}
|
}
|
||||||
static JSONCPP_STRING useStyledStreamWriter(Json::Value const& root) {
|
static Json::String useStyledStreamWriter(Json::Value const& root) {
|
||||||
Json::StyledStreamWriter writer;
|
Json::StyledStreamWriter writer;
|
||||||
JSONCPP_OSTRINGSTREAM sout;
|
Json::OStringStream sout;
|
||||||
writer.write(sout, root);
|
writer.write(sout, root);
|
||||||
return sout.str();
|
return sout.str();
|
||||||
}
|
}
|
||||||
static JSONCPP_STRING useBuiltStyledStreamWriter(Json::Value const& root) {
|
static Json::String useBuiltStyledStreamWriter(Json::Value const& root) {
|
||||||
Json::StreamWriterBuilder builder;
|
Json::StreamWriterBuilder builder;
|
||||||
return Json::writeString(builder, root);
|
return Json::writeString(builder, root);
|
||||||
}
|
}
|
||||||
static int rewriteValueTree(const JSONCPP_STRING& rewritePath,
|
static int rewriteValueTree(const Json::String& rewritePath,
|
||||||
const Json::Value& root,
|
const Json::Value& root,
|
||||||
Options::writeFuncType write,
|
Options::writeFuncType write,
|
||||||
JSONCPP_STRING* rewrite) {
|
Json::String* rewrite) {
|
||||||
*rewrite = write(root);
|
*rewrite = write(root);
|
||||||
FILE* fout = fopen(rewritePath.c_str(), "wt");
|
FILE* fout = fopen(rewritePath.c_str(), "wt");
|
||||||
if (!fout) {
|
if (!fout) {
|
||||||
@ -182,13 +180,12 @@ static int rewriteValueTree(const JSONCPP_STRING& rewritePath,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSONCPP_STRING removeSuffix(const JSONCPP_STRING& path,
|
static Json::String removeSuffix(const Json::String& path, const Json::String& extension) {
|
||||||
const JSONCPP_STRING& extension) {
|
|
||||||
if (extension.length() >= path.length())
|
if (extension.length() >= path.length())
|
||||||
return JSONCPP_STRING("");
|
return Json::String("");
|
||||||
JSONCPP_STRING suffix = path.substr(path.length() - extension.length());
|
Json::String suffix = path.substr(path.length() - extension.length());
|
||||||
if (suffix != extension)
|
if (suffix != extension)
|
||||||
return JSONCPP_STRING("");
|
return Json::String("");
|
||||||
return path.substr(0, path.length() - extension.length());
|
return path.substr(0, path.length() - extension.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,18 +210,18 @@ static int parseCommandLine(int argc, const char* argv[], Options* opts) {
|
|||||||
return printUsage(argv);
|
return printUsage(argv);
|
||||||
}
|
}
|
||||||
int index = 1;
|
int index = 1;
|
||||||
if (JSONCPP_STRING(argv[index]) == "--json-checker") {
|
if (Json::String(argv[index]) == "--json-checker") {
|
||||||
opts->features = Json::Features::strictMode();
|
opts->features = Json::Features::strictMode();
|
||||||
opts->parseOnly = true;
|
opts->parseOnly = true;
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
if (JSONCPP_STRING(argv[index]) == "--json-config") {
|
if (Json::String(argv[index]) == "--json-config") {
|
||||||
printConfig();
|
printConfig();
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
if (JSONCPP_STRING(argv[index]) == "--json-writer") {
|
if (Json::String(argv[index]) == "--json-writer") {
|
||||||
++index;
|
++index;
|
||||||
JSONCPP_STRING const writerName(argv[index++]);
|
Json::String const writerName(argv[index++]);
|
||||||
if (writerName == "StyledWriter") {
|
if (writerName == "StyledWriter") {
|
||||||
opts->write = &useStyledWriter;
|
opts->write = &useStyledWriter;
|
||||||
} else if (writerName == "StyledStreamWriter") {
|
} else if (writerName == "StyledStreamWriter") {
|
||||||
@ -245,22 +242,22 @@ static int parseCommandLine(int argc, const char* argv[], Options* opts) {
|
|||||||
static int runTest(Options const& opts) {
|
static int runTest(Options const& opts) {
|
||||||
int exitCode = 0;
|
int exitCode = 0;
|
||||||
|
|
||||||
JSONCPP_STRING input = readInputTestFile(opts.path.c_str());
|
Json::String input = readInputTestFile(opts.path.c_str());
|
||||||
if (input.empty()) {
|
if (input.empty()) {
|
||||||
printf("Failed to read input or empty input: %s\n", opts.path.c_str());
|
printf("Failed to read input or empty input: %s\n", opts.path.c_str());
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING basePath = removeSuffix(opts.path, ".json");
|
Json::String basePath = removeSuffix(opts.path, ".json");
|
||||||
if (!opts.parseOnly && basePath.empty()) {
|
if (!opts.parseOnly && basePath.empty()) {
|
||||||
printf("Bad input path. Path does not end with '.expected':\n%s\n",
|
printf("Bad input path. Path does not end with '.expected':\n%s\n",
|
||||||
opts.path.c_str());
|
opts.path.c_str());
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING const actualPath = basePath + ".actual";
|
Json::String const actualPath = basePath + ".actual";
|
||||||
JSONCPP_STRING const rewritePath = basePath + ".rewrite";
|
Json::String const rewritePath = basePath + ".rewrite";
|
||||||
JSONCPP_STRING const rewriteActualPath = basePath + ".actual-rewrite";
|
Json::String const rewriteActualPath = basePath + ".actual-rewrite";
|
||||||
|
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
exitCode = parseAndSaveValueTree(input, actualPath, "input", opts.features,
|
exitCode = parseAndSaveValueTree(input, actualPath, "input", opts.features,
|
||||||
@ -268,7 +265,7 @@ static int runTest(Options const& opts) {
|
|||||||
if (exitCode || opts.parseOnly) {
|
if (exitCode || opts.parseOnly) {
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
JSONCPP_STRING rewrite;
|
Json::String rewrite;
|
||||||
exitCode = rewriteValueTree(rewritePath, root, opts.write, &rewrite);
|
exitCode = rewriteValueTree(rewritePath, root, opts.write, &rewrite);
|
||||||
if (exitCode) {
|
if (exitCode) {
|
||||||
return exitCode;
|
return exitCode;
|
||||||
|
@ -108,9 +108,9 @@ bool Reader::parse(std::istream& is, Value& root, bool collectComments) {
|
|||||||
// Those would allow streamed input from a file, if parse() were a
|
// Those would allow streamed input from a file, if parse() were a
|
||||||
// template function.
|
// template function.
|
||||||
|
|
||||||
// Since JSONCPP_STRING is reference-counted, this at least does not
|
// Since String is reference-counted, this at least does not
|
||||||
// create an extra copy.
|
// create an extra copy.
|
||||||
JSONCPP_STRING doc;
|
String doc;
|
||||||
std::getline(is, doc, (char)EOF);
|
std::getline(is, doc, (char)EOF);
|
||||||
return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
|
return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
|
||||||
}
|
}
|
||||||
@ -358,9 +358,8 @@ bool Reader::readComment() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING Reader::normalizeEOL(Reader::Location begin,
|
String Reader::normalizeEOL(Reader::Location begin, Reader::Location end) {
|
||||||
Reader::Location end) {
|
String normalized;
|
||||||
JSONCPP_STRING normalized;
|
|
||||||
normalized.reserve(static_cast<size_t>(end - begin));
|
normalized.reserve(static_cast<size_t>(end - begin));
|
||||||
Reader::Location current = begin;
|
Reader::Location current = begin;
|
||||||
while (current != end) {
|
while (current != end) {
|
||||||
@ -382,7 +381,7 @@ void Reader::addComment(Location begin,
|
|||||||
Location end,
|
Location end,
|
||||||
CommentPlacement placement) {
|
CommentPlacement placement) {
|
||||||
assert(collectComments_);
|
assert(collectComments_);
|
||||||
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
|
const String& normalized = normalizeEOL(begin, end);
|
||||||
if (placement == commentAfterOnSameLine) {
|
if (placement == commentAfterOnSameLine) {
|
||||||
assert(lastValue_ != nullptr);
|
assert(lastValue_ != nullptr);
|
||||||
lastValue_->setComment(normalized, placement);
|
lastValue_->setComment(normalized, placement);
|
||||||
@ -452,7 +451,7 @@ bool Reader::readString() {
|
|||||||
|
|
||||||
bool Reader::readObject(Token& token) {
|
bool Reader::readObject(Token& token) {
|
||||||
Token tokenName;
|
Token tokenName;
|
||||||
JSONCPP_STRING name;
|
String name;
|
||||||
Value init(objectValue);
|
Value init(objectValue);
|
||||||
currentValue().swapPayload(init);
|
currentValue().swapPayload(init);
|
||||||
currentValue().setOffsetStart(token.start_ - begin_);
|
currentValue().setOffsetStart(token.start_ - begin_);
|
||||||
@ -472,7 +471,7 @@ bool Reader::readObject(Token& token) {
|
|||||||
Value numberName;
|
Value numberName;
|
||||||
if (!decodeNumber(tokenName, numberName))
|
if (!decodeNumber(tokenName, numberName))
|
||||||
return recoverFromError(tokenObjectEnd);
|
return recoverFromError(tokenObjectEnd);
|
||||||
name = JSONCPP_STRING(numberName.asCString());
|
name = String(numberName.asCString());
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -609,18 +608,17 @@ bool Reader::decodeDouble(Token& token) {
|
|||||||
|
|
||||||
bool Reader::decodeDouble(Token& token, Value& decoded) {
|
bool Reader::decodeDouble(Token& token, Value& decoded) {
|
||||||
double value = 0;
|
double value = 0;
|
||||||
JSONCPP_STRING buffer(token.start_, token.end_);
|
String buffer(token.start_, token.end_);
|
||||||
JSONCPP_ISTRINGSTREAM is(buffer);
|
IStringStream is(buffer);
|
||||||
if (!(is >> value))
|
if (!(is >> value))
|
||||||
return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
|
return addError(
|
||||||
"' is not a number.",
|
"'" + String(token.start_, token.end_) + "' is not a number.", token);
|
||||||
token);
|
|
||||||
decoded = value;
|
decoded = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeString(Token& token) {
|
bool Reader::decodeString(Token& token) {
|
||||||
JSONCPP_STRING decoded_string;
|
String decoded_string;
|
||||||
if (!decodeString(token, decoded_string))
|
if (!decodeString(token, decoded_string))
|
||||||
return false;
|
return false;
|
||||||
Value decoded(decoded_string);
|
Value decoded(decoded_string);
|
||||||
@ -630,7 +628,7 @@ bool Reader::decodeString(Token& token) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::decodeString(Token& token, JSONCPP_STRING& decoded) {
|
bool Reader::decodeString(Token& token, String& decoded) {
|
||||||
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
|
decoded.reserve(static_cast<size_t>(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 '"'
|
||||||
@ -737,9 +735,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token& token,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::addError(const JSONCPP_STRING& message,
|
bool Reader::addError(const String& message, Token& token, Location extra) {
|
||||||
Token& token,
|
|
||||||
Location extra) {
|
|
||||||
ErrorInfo info;
|
ErrorInfo info;
|
||||||
info.token_ = token;
|
info.token_ = token;
|
||||||
info.message_ = message;
|
info.message_ = message;
|
||||||
@ -761,7 +757,7 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::addErrorAndRecover(const JSONCPP_STRING& message,
|
bool Reader::addErrorAndRecover(const String& message,
|
||||||
Token& token,
|
Token& token,
|
||||||
TokenType skipUntilToken) {
|
TokenType skipUntilToken) {
|
||||||
addError(message, token);
|
addError(message, token);
|
||||||
@ -799,7 +795,7 @@ void Reader::getLocationLineAndColumn(Location location,
|
|||||||
++line;
|
++line;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING Reader::getLocationLineAndColumn(Location location) const {
|
String Reader::getLocationLineAndColumn(Location location) const {
|
||||||
int line, column;
|
int line, column;
|
||||||
getLocationLineAndColumn(location, line, column);
|
getLocationLineAndColumn(location, line, column);
|
||||||
char buffer[18 + 16 + 16 + 1];
|
char buffer[18 + 16 + 16 + 1];
|
||||||
@ -808,12 +804,12 @@ JSONCPP_STRING Reader::getLocationLineAndColumn(Location location) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated. Preserved for backward compatibility
|
// Deprecated. Preserved for backward compatibility
|
||||||
JSONCPP_STRING Reader::getFormatedErrorMessages() const {
|
String Reader::getFormatedErrorMessages() const {
|
||||||
return getFormattedErrorMessages();
|
return getFormattedErrorMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING Reader::getFormattedErrorMessages() const {
|
String Reader::getFormattedErrorMessages() const {
|
||||||
JSONCPP_STRING formattedMessage;
|
String formattedMessage;
|
||||||
for (const auto& error : errors_) {
|
for (const auto& error : errors_) {
|
||||||
formattedMessage +=
|
formattedMessage +=
|
||||||
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
||||||
@ -837,7 +833,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
|
|||||||
return allErrors;
|
return allErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::pushError(const Value& value, const JSONCPP_STRING& message) {
|
bool Reader::pushError(const Value& value, const String& message) {
|
||||||
ptrdiff_t const length = end_ - begin_;
|
ptrdiff_t const length = end_ - begin_;
|
||||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
|
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
|
||||||
return false;
|
return false;
|
||||||
@ -854,7 +850,7 @@ bool Reader::pushError(const Value& value, const JSONCPP_STRING& message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Reader::pushError(const Value& value,
|
bool Reader::pushError(const Value& value,
|
||||||
const JSONCPP_STRING& message,
|
const String& message,
|
||||||
const Value& extra) {
|
const Value& extra) {
|
||||||
ptrdiff_t const length = end_ - begin_;
|
ptrdiff_t const length = end_ - begin_;
|
||||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
|
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
|
||||||
@ -905,7 +901,7 @@ public:
|
|||||||
struct StructuredError {
|
struct StructuredError {
|
||||||
ptrdiff_t offset_start;
|
ptrdiff_t offset_start;
|
||||||
ptrdiff_t offset_limit;
|
ptrdiff_t offset_limit;
|
||||||
JSONCPP_STRING message;
|
String message;
|
||||||
};
|
};
|
||||||
|
|
||||||
OurReader(OurFeatures const& features);
|
OurReader(OurFeatures const& features);
|
||||||
@ -913,12 +909,10 @@ public:
|
|||||||
const char* endDoc,
|
const char* endDoc,
|
||||||
Value& root,
|
Value& root,
|
||||||
bool collectComments = true);
|
bool collectComments = true);
|
||||||
JSONCPP_STRING getFormattedErrorMessages() const;
|
String getFormattedErrorMessages() const;
|
||||||
std::vector<StructuredError> getStructuredErrors() const;
|
std::vector<StructuredError> getStructuredErrors() const;
|
||||||
bool pushError(const Value& value, const JSONCPP_STRING& message);
|
bool pushError(const Value& value, const String& message);
|
||||||
bool pushError(const Value& value,
|
bool pushError(const Value& value, const String& message, const Value& extra);
|
||||||
const JSONCPP_STRING& message,
|
|
||||||
const Value& extra);
|
|
||||||
bool good() const;
|
bool good() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -955,7 +949,7 @@ private:
|
|||||||
class ErrorInfo {
|
class ErrorInfo {
|
||||||
public:
|
public:
|
||||||
Token token_;
|
Token token_;
|
||||||
JSONCPP_STRING message_;
|
String message_;
|
||||||
Location extra_;
|
Location extra_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -976,7 +970,7 @@ private:
|
|||||||
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, JSONCPP_STRING& decoded);
|
bool decodeString(Token& token, 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,
|
||||||
@ -987,11 +981,9 @@ private:
|
|||||||
Location& current,
|
Location& current,
|
||||||
Location end,
|
Location end,
|
||||||
unsigned int& unicode);
|
unsigned int& unicode);
|
||||||
bool addError(const JSONCPP_STRING& message,
|
bool addError(const String& message, Token& token, Location extra = nullptr);
|
||||||
Token& token,
|
|
||||||
Location extra = nullptr);
|
|
||||||
bool recoverFromError(TokenType skipUntilToken);
|
bool recoverFromError(TokenType skipUntilToken);
|
||||||
bool addErrorAndRecover(const JSONCPP_STRING& message,
|
bool addErrorAndRecover(const String& message,
|
||||||
Token& token,
|
Token& token,
|
||||||
TokenType skipUntilToken);
|
TokenType skipUntilToken);
|
||||||
void skipUntilSpace();
|
void skipUntilSpace();
|
||||||
@ -999,23 +991,23 @@ private:
|
|||||||
Char getNextChar();
|
Char getNextChar();
|
||||||
void
|
void
|
||||||
getLocationLineAndColumn(Location location, int& line, int& column) const;
|
getLocationLineAndColumn(Location location, int& line, int& column) const;
|
||||||
JSONCPP_STRING getLocationLineAndColumn(Location location) const;
|
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);
|
||||||
|
|
||||||
static JSONCPP_STRING normalizeEOL(Location begin, Location end);
|
static String normalizeEOL(Location begin, Location end);
|
||||||
static bool containsNewLine(Location begin, Location end);
|
static bool containsNewLine(Location begin, Location end);
|
||||||
|
|
||||||
typedef std::stack<Value*> Nodes;
|
typedef std::stack<Value*> Nodes;
|
||||||
Nodes nodes_;
|
Nodes nodes_;
|
||||||
Errors errors_;
|
Errors errors_;
|
||||||
JSONCPP_STRING document_;
|
String document_;
|
||||||
Location begin_;
|
Location begin_;
|
||||||
Location end_;
|
Location end_;
|
||||||
Location current_;
|
Location current_;
|
||||||
Location lastValueEnd_;
|
Location lastValueEnd_;
|
||||||
Value* lastValue_;
|
Value* lastValue_;
|
||||||
JSONCPP_STRING commentsBefore_;
|
String commentsBefore_;
|
||||||
|
|
||||||
OurFeatures const features_;
|
OurFeatures const features_;
|
||||||
bool collectComments_;
|
bool collectComments_;
|
||||||
@ -1329,9 +1321,9 @@ bool OurReader::readComment() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING OurReader::normalizeEOL(OurReader::Location begin,
|
String OurReader::normalizeEOL(OurReader::Location begin,
|
||||||
OurReader::Location end) {
|
OurReader::Location end) {
|
||||||
JSONCPP_STRING normalized;
|
String normalized;
|
||||||
normalized.reserve(static_cast<size_t>(end - begin));
|
normalized.reserve(static_cast<size_t>(end - begin));
|
||||||
OurReader::Location current = begin;
|
OurReader::Location current = begin;
|
||||||
while (current != end) {
|
while (current != end) {
|
||||||
@ -1353,7 +1345,7 @@ void OurReader::addComment(Location begin,
|
|||||||
Location end,
|
Location end,
|
||||||
CommentPlacement placement) {
|
CommentPlacement placement) {
|
||||||
assert(collectComments_);
|
assert(collectComments_);
|
||||||
const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
|
const String& normalized = normalizeEOL(begin, end);
|
||||||
if (placement == commentAfterOnSameLine) {
|
if (placement == commentAfterOnSameLine) {
|
||||||
assert(lastValue_ != nullptr);
|
assert(lastValue_ != nullptr);
|
||||||
lastValue_->setComment(normalized, placement);
|
lastValue_->setComment(normalized, placement);
|
||||||
@ -1439,7 +1431,7 @@ bool OurReader::readStringSingleQuote() {
|
|||||||
|
|
||||||
bool OurReader::readObject(Token& token) {
|
bool OurReader::readObject(Token& token) {
|
||||||
Token tokenName;
|
Token tokenName;
|
||||||
JSONCPP_STRING name;
|
String name;
|
||||||
Value init(objectValue);
|
Value init(objectValue);
|
||||||
currentValue().swapPayload(init);
|
currentValue().swapPayload(init);
|
||||||
currentValue().setOffsetStart(token.start_ - begin_);
|
currentValue().setOffsetStart(token.start_ - begin_);
|
||||||
@ -1472,7 +1464,7 @@ bool OurReader::readObject(Token& token) {
|
|||||||
if (name.length() >= (1U << 30))
|
if (name.length() >= (1U << 30))
|
||||||
throwRuntimeError("keylength >= 2^30");
|
throwRuntimeError("keylength >= 2^30");
|
||||||
if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
|
if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
|
||||||
JSONCPP_STRING msg = "Duplicate key: '" + name + "'";
|
String msg = "Duplicate key: '" + name + "'";
|
||||||
return addErrorAndRecover(msg, tokenName, tokenObjectEnd);
|
return addErrorAndRecover(msg, tokenName, tokenObjectEnd);
|
||||||
}
|
}
|
||||||
Value& value = currentValue()[name];
|
Value& value = currentValue()[name];
|
||||||
@ -1624,20 +1616,19 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
|
|||||||
fixNumericLocaleInput(buffer, buffer + length);
|
fixNumericLocaleInput(buffer, buffer + length);
|
||||||
count = sscanf(buffer, format, &value);
|
count = sscanf(buffer, format, &value);
|
||||||
} else {
|
} else {
|
||||||
JSONCPP_STRING buffer(token.start_, token.end_);
|
String buffer(token.start_, token.end_);
|
||||||
count = sscanf(buffer.c_str(), format, &value);
|
count = sscanf(buffer.c_str(), format, &value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count != 1)
|
if (count != 1)
|
||||||
return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
|
return addError(
|
||||||
"' is not a number.",
|
"'" + String(token.start_, token.end_) + "' is not a number.", token);
|
||||||
token);
|
|
||||||
decoded = value;
|
decoded = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OurReader::decodeString(Token& token) {
|
bool OurReader::decodeString(Token& token) {
|
||||||
JSONCPP_STRING decoded_string;
|
String decoded_string;
|
||||||
if (!decodeString(token, decoded_string))
|
if (!decodeString(token, decoded_string))
|
||||||
return false;
|
return false;
|
||||||
Value decoded(decoded_string);
|
Value decoded(decoded_string);
|
||||||
@ -1647,7 +1638,7 @@ bool OurReader::decodeString(Token& token) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OurReader::decodeString(Token& token, JSONCPP_STRING& decoded) {
|
bool OurReader::decodeString(Token& token, String& decoded) {
|
||||||
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
|
decoded.reserve(static_cast<size_t>(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 '"'
|
||||||
@ -1754,9 +1745,7 @@ bool OurReader::decodeUnicodeEscapeSequence(Token& token,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OurReader::addError(const JSONCPP_STRING& message,
|
bool OurReader::addError(const String& message, Token& token, Location extra) {
|
||||||
Token& token,
|
|
||||||
Location extra) {
|
|
||||||
ErrorInfo info;
|
ErrorInfo info;
|
||||||
info.token_ = token;
|
info.token_ = token;
|
||||||
info.message_ = message;
|
info.message_ = message;
|
||||||
@ -1778,7 +1767,7 @@ bool OurReader::recoverFromError(TokenType skipUntilToken) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OurReader::addErrorAndRecover(const JSONCPP_STRING& message,
|
bool OurReader::addErrorAndRecover(const String& message,
|
||||||
Token& token,
|
Token& token,
|
||||||
TokenType skipUntilToken) {
|
TokenType skipUntilToken) {
|
||||||
addError(message, token);
|
addError(message, token);
|
||||||
@ -1816,7 +1805,7 @@ void OurReader::getLocationLineAndColumn(Location location,
|
|||||||
++line;
|
++line;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {
|
String OurReader::getLocationLineAndColumn(Location location) const {
|
||||||
int line, column;
|
int line, column;
|
||||||
getLocationLineAndColumn(location, line, column);
|
getLocationLineAndColumn(location, line, column);
|
||||||
char buffer[18 + 16 + 16 + 1];
|
char buffer[18 + 16 + 16 + 1];
|
||||||
@ -1824,8 +1813,8 @@ JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
|
String OurReader::getFormattedErrorMessages() const {
|
||||||
JSONCPP_STRING formattedMessage;
|
String formattedMessage;
|
||||||
for (const auto& error : errors_) {
|
for (const auto& error : errors_) {
|
||||||
formattedMessage +=
|
formattedMessage +=
|
||||||
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
|
||||||
@ -1849,7 +1838,7 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
|
|||||||
return allErrors;
|
return allErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message) {
|
bool OurReader::pushError(const Value& value, const String& message) {
|
||||||
ptrdiff_t length = end_ - begin_;
|
ptrdiff_t length = end_ - begin_;
|
||||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
|
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
|
||||||
return false;
|
return false;
|
||||||
@ -1866,7 +1855,7 @@ bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OurReader::pushError(const Value& value,
|
bool OurReader::pushError(const Value& value,
|
||||||
const JSONCPP_STRING& message,
|
const String& message,
|
||||||
const Value& extra) {
|
const Value& extra) {
|
||||||
ptrdiff_t length = end_ - begin_;
|
ptrdiff_t length = end_ - begin_;
|
||||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
|
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
|
||||||
@ -1896,7 +1885,7 @@ public:
|
|||||||
bool parse(char const* beginDoc,
|
bool parse(char const* beginDoc,
|
||||||
char const* endDoc,
|
char const* endDoc,
|
||||||
Value* root,
|
Value* root,
|
||||||
JSONCPP_STRING* errs) override {
|
String* errs) override {
|
||||||
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
|
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
|
||||||
if (errs) {
|
if (errs) {
|
||||||
*errs = reader_.getFormattedErrorMessages();
|
*errs = reader_.getFormattedErrorMessages();
|
||||||
@ -1926,7 +1915,7 @@ CharReader* CharReaderBuilder::newCharReader() const {
|
|||||||
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
|
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
|
||||||
return new OurCharReader(collectComments, features);
|
return new OurCharReader(collectComments, features);
|
||||||
}
|
}
|
||||||
static void getValidReaderKeys(std::set<JSONCPP_STRING>* valid_keys) {
|
static void getValidReaderKeys(std::set<String>* valid_keys) {
|
||||||
valid_keys->clear();
|
valid_keys->clear();
|
||||||
valid_keys->insert("collectComments");
|
valid_keys->insert("collectComments");
|
||||||
valid_keys->insert("allowComments");
|
valid_keys->insert("allowComments");
|
||||||
@ -1944,19 +1933,19 @@ bool CharReaderBuilder::validate(Json::Value* invalid) const {
|
|||||||
if (!invalid)
|
if (!invalid)
|
||||||
invalid = &my_invalid; // so we do not need to test for NULL
|
invalid = &my_invalid; // so we do not need to test for NULL
|
||||||
Json::Value& inv = *invalid;
|
Json::Value& inv = *invalid;
|
||||||
std::set<JSONCPP_STRING> valid_keys;
|
std::set<String> valid_keys;
|
||||||
getValidReaderKeys(&valid_keys);
|
getValidReaderKeys(&valid_keys);
|
||||||
Value::Members keys = settings_.getMemberNames();
|
Value::Members keys = settings_.getMemberNames();
|
||||||
size_t n = keys.size();
|
size_t n = keys.size();
|
||||||
for (size_t i = 0; i < n; ++i) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
JSONCPP_STRING const& key = keys[i];
|
String const& key = keys[i];
|
||||||
if (valid_keys.find(key) == valid_keys.end()) {
|
if (valid_keys.find(key) == valid_keys.end()) {
|
||||||
inv[key] = settings_[key];
|
inv[key] = settings_[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return inv.empty();
|
return inv.empty();
|
||||||
}
|
}
|
||||||
Value& CharReaderBuilder::operator[](const JSONCPP_STRING& key) {
|
Value& CharReaderBuilder::operator[](const String& key) {
|
||||||
return settings_[key];
|
return settings_[key];
|
||||||
}
|
}
|
||||||
// static
|
// static
|
||||||
@ -1993,12 +1982,12 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
|
|||||||
// global functions
|
// global functions
|
||||||
|
|
||||||
bool parseFromStream(CharReader::Factory const& fact,
|
bool parseFromStream(CharReader::Factory const& fact,
|
||||||
JSONCPP_ISTREAM& sin,
|
IStream& sin,
|
||||||
Value* root,
|
Value* root,
|
||||||
JSONCPP_STRING* errs) {
|
String* errs) {
|
||||||
JSONCPP_OSTRINGSTREAM ssin;
|
OStringStream ssin;
|
||||||
ssin << sin.rdbuf();
|
ssin << sin.rdbuf();
|
||||||
JSONCPP_STRING doc = ssin.str();
|
String doc = ssin.str();
|
||||||
char const* begin = doc.data();
|
char const* begin = doc.data();
|
||||||
char const* end = begin + doc.size();
|
char const* end = begin + doc.size();
|
||||||
// Note that we do not actually need a null-terminator.
|
// Note that we do not actually need a null-terminator.
|
||||||
@ -2006,9 +1995,9 @@ bool parseFromStream(CharReader::Factory const& fact,
|
|||||||
return reader->parse(begin, end, root, errs);
|
return reader->parse(begin, end, root, errs);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) {
|
IStream& operator>>(IStream& sin, Value& root) {
|
||||||
CharReaderBuilder b;
|
CharReaderBuilder b;
|
||||||
JSONCPP_STRING errs;
|
String errs;
|
||||||
bool ok = parseFromStream(b, sin, &root, &errs);
|
bool ok = parseFromStream(b, sin, &root, &errs);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
throwRuntimeError(errs);
|
throwRuntimeError(errs);
|
||||||
|
@ -36,8 +36,8 @@ static inline char getDecimalPoint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a unicode code-point to UTF-8.
|
/// Converts a unicode code-point to UTF-8.
|
||||||
static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
|
static inline String codePointToUTF8(unsigned int cp) {
|
||||||
JSONCPP_STRING result;
|
String result;
|
||||||
|
|
||||||
// based on description from http://en.wikipedia.org/wiki/UTF-8
|
// based on description from http://en.wikipedia.org/wiki/UTF-8
|
||||||
|
|
||||||
|
@ -217,15 +217,15 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); }
|
|||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
Exception::Exception(JSONCPP_STRING msg) : msg_(std::move(msg)) {}
|
Exception::Exception(String msg) : msg_(std::move(msg)) {}
|
||||||
Exception::~Exception() JSONCPP_NOEXCEPT {}
|
Exception::~Exception() JSONCPP_NOEXCEPT {}
|
||||||
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
|
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
|
||||||
RuntimeError::RuntimeError(JSONCPP_STRING const& msg) : Exception(msg) {}
|
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
|
||||||
LogicError::LogicError(JSONCPP_STRING const& msg) : Exception(msg) {}
|
LogicError::LogicError(String const& msg) : Exception(msg) {}
|
||||||
JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg) {
|
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
|
||||||
throw RuntimeError(msg);
|
throw RuntimeError(msg);
|
||||||
}
|
}
|
||||||
JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg) {
|
JSONCPP_NORETURN void throwLogicError(String const& msg) {
|
||||||
throw LogicError(msg);
|
throw LogicError(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,7 +452,7 @@ Value::Value(const char* begin, const char* end) {
|
|||||||
duplicateAndPrefixStringValue(begin, static_cast<unsigned>(end - begin));
|
duplicateAndPrefixStringValue(begin, static_cast<unsigned>(end - begin));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Value(const JSONCPP_STRING& value) {
|
Value::Value(const String& value) {
|
||||||
initBasic(stringValue, true);
|
initBasic(stringValue, true);
|
||||||
value_.string_ = duplicateAndPrefixStringValue(
|
value_.string_ = duplicateAndPrefixStringValue(
|
||||||
value.data(), static_cast<unsigned>(value.length()));
|
value.data(), static_cast<unsigned>(value.length()));
|
||||||
@ -684,7 +684,7 @@ bool Value::getString(char const** begin, char const** end) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING Value::asString() const {
|
String Value::asString() const {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case nullValue:
|
case nullValue:
|
||||||
return "";
|
return "";
|
||||||
@ -695,7 +695,7 @@ JSONCPP_STRING Value::asString() const {
|
|||||||
char const* this_str;
|
char const* this_str;
|
||||||
decodePrefixedString(this->allocated_, this->value_.string_, &this_len,
|
decodePrefixedString(this->allocated_, this->value_.string_, &this_len,
|
||||||
&this_str);
|
&this_str);
|
||||||
return JSONCPP_STRING(this_str, this_len);
|
return String(this_str, this_len);
|
||||||
}
|
}
|
||||||
case booleanValue:
|
case booleanValue:
|
||||||
return value_.bool_ ? "true" : "false";
|
return value_.bool_ ? "true" : "false";
|
||||||
@ -1172,7 +1172,7 @@ const Value& Value::operator[](const char* key) const {
|
|||||||
return nullSingleton();
|
return nullSingleton();
|
||||||
return *found;
|
return *found;
|
||||||
}
|
}
|
||||||
Value const& Value::operator[](const JSONCPP_STRING& key) const {
|
Value const& Value::operator[](const String& key) const {
|
||||||
Value const* found = find(key.data(), key.data() + key.length());
|
Value const* found = find(key.data(), key.data() + key.length());
|
||||||
if (!found)
|
if (!found)
|
||||||
return nullSingleton();
|
return nullSingleton();
|
||||||
@ -1183,7 +1183,7 @@ Value& Value::operator[](const char* key) {
|
|||||||
return resolveReference(key, key + strlen(key));
|
return resolveReference(key, key + strlen(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value& Value::operator[](const JSONCPP_STRING& key) {
|
Value& Value::operator[](const String& key) {
|
||||||
return resolveReference(key.data(), key.data() + key.length());
|
return resolveReference(key.data(), key.data() + key.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1220,7 +1220,7 @@ Value Value::get(char const* begin,
|
|||||||
Value Value::get(char const* key, Value const& defaultValue) const {
|
Value Value::get(char const* key, Value const& defaultValue) const {
|
||||||
return get(key, key + strlen(key), defaultValue);
|
return get(key, key + strlen(key), defaultValue);
|
||||||
}
|
}
|
||||||
Value Value::get(JSONCPP_STRING const& key, Value const& defaultValue) const {
|
Value Value::get(String const& key, Value const& defaultValue) const {
|
||||||
return get(key.data(), key.data() + key.length(), defaultValue);
|
return get(key.data(), key.data() + key.length(), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1245,7 +1245,7 @@ bool Value::removeMember(const char* begin, const char* end, Value* removed) {
|
|||||||
bool Value::removeMember(const char* key, Value* removed) {
|
bool Value::removeMember(const char* key, Value* removed) {
|
||||||
return removeMember(key, key + strlen(key), removed);
|
return removeMember(key, key + strlen(key), removed);
|
||||||
}
|
}
|
||||||
bool Value::removeMember(JSONCPP_STRING const& key, Value* removed) {
|
bool Value::removeMember(String const& key, Value* removed) {
|
||||||
return removeMember(key.data(), key.data() + key.length(), removed);
|
return removeMember(key.data(), key.data() + key.length(), removed);
|
||||||
}
|
}
|
||||||
void Value::removeMember(const char* key) {
|
void Value::removeMember(const char* key) {
|
||||||
@ -1257,9 +1257,7 @@ void Value::removeMember(const char* key) {
|
|||||||
CZString actualKey(key, unsigned(strlen(key)), CZString::noDuplication);
|
CZString actualKey(key, unsigned(strlen(key)), CZString::noDuplication);
|
||||||
value_.map_->erase(actualKey);
|
value_.map_->erase(actualKey);
|
||||||
}
|
}
|
||||||
void Value::removeMember(const JSONCPP_STRING& key) {
|
void Value::removeMember(const String& key) { removeMember(key.c_str()); }
|
||||||
removeMember(key.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Value::removeIndex(ArrayIndex index, Value* removed) {
|
bool Value::removeIndex(ArrayIndex index, Value* removed) {
|
||||||
if (type_ != arrayValue) {
|
if (type_ != arrayValue) {
|
||||||
@ -1299,7 +1297,7 @@ bool Value::isMember(char const* begin, char const* end) const {
|
|||||||
bool Value::isMember(char const* key) const {
|
bool Value::isMember(char const* key) const {
|
||||||
return isMember(key, key + strlen(key));
|
return isMember(key, key + strlen(key));
|
||||||
}
|
}
|
||||||
bool Value::isMember(JSONCPP_STRING const& key) const {
|
bool Value::isMember(String const& key) const {
|
||||||
return isMember(key.data(), key.data() + key.length());
|
return isMember(key.data(), key.data() + key.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1320,7 +1318,7 @@ Value::Members Value::getMemberNames() const {
|
|||||||
ObjectValues::const_iterator it = value_.map_->begin();
|
ObjectValues::const_iterator it = value_.map_->begin();
|
||||||
ObjectValues::const_iterator itEnd = value_.map_->end();
|
ObjectValues::const_iterator itEnd = value_.map_->end();
|
||||||
for (; it != itEnd; ++it) {
|
for (; it != itEnd; ++it) {
|
||||||
members.push_back(JSONCPP_STRING((*it).first.data(), (*it).first.length()));
|
members.push_back(String((*it).first.data(), (*it).first.length()));
|
||||||
}
|
}
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
@ -1491,8 +1489,7 @@ void Value::setComment(const char* comment, CommentPlacement placement) {
|
|||||||
setComment(comment, strlen(comment), placement);
|
setComment(comment, strlen(comment), placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setComment(const JSONCPP_STRING& comment,
|
void Value::setComment(const String& comment, CommentPlacement placement) {
|
||||||
CommentPlacement placement) {
|
|
||||||
setComment(comment.c_str(), comment.length(), placement);
|
setComment(comment.c_str(), comment.length(), placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1500,7 +1497,7 @@ bool Value::hasComment(CommentPlacement placement) const {
|
|||||||
return comments_ != nullptr && comments_[placement].comment_ != nullptr;
|
return comments_ != nullptr && comments_[placement].comment_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING Value::getComment(CommentPlacement placement) const {
|
String Value::getComment(CommentPlacement placement) const {
|
||||||
if (hasComment(placement))
|
if (hasComment(placement))
|
||||||
return comments_[placement].comment_;
|
return comments_[placement].comment_;
|
||||||
return "";
|
return "";
|
||||||
@ -1514,10 +1511,10 @@ ptrdiff_t Value::getOffsetStart() const { return start_; }
|
|||||||
|
|
||||||
ptrdiff_t Value::getOffsetLimit() const { return limit_; }
|
ptrdiff_t Value::getOffsetLimit() const { return limit_; }
|
||||||
|
|
||||||
JSONCPP_STRING Value::toStyledString() const {
|
String Value::toStyledString() const {
|
||||||
StreamWriterBuilder builder;
|
StreamWriterBuilder builder;
|
||||||
|
|
||||||
JSONCPP_STRING out = this->hasComment(commentBefore) ? "\n" : "";
|
String out = this->hasComment(commentBefore) ? "\n" : "";
|
||||||
out += Json::writeString(builder, *this);
|
out += Json::writeString(builder, *this);
|
||||||
out += '\n';
|
out += '\n';
|
||||||
|
|
||||||
@ -1587,13 +1584,13 @@ PathArgument::PathArgument(ArrayIndex index)
|
|||||||
PathArgument::PathArgument(const char* key)
|
PathArgument::PathArgument(const char* key)
|
||||||
: key_(key), index_(), kind_(kindKey) {}
|
: key_(key), index_(), kind_(kindKey) {}
|
||||||
|
|
||||||
PathArgument::PathArgument(const JSONCPP_STRING& key)
|
PathArgument::PathArgument(const String& key)
|
||||||
: key_(key.c_str()), index_(), kind_(kindKey) {}
|
: key_(key.c_str()), index_(), kind_(kindKey) {}
|
||||||
|
|
||||||
// class Path
|
// class Path
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Path::Path(const JSONCPP_STRING& path,
|
Path::Path(const String& path,
|
||||||
const PathArgument& a1,
|
const PathArgument& a1,
|
||||||
const PathArgument& a2,
|
const PathArgument& a2,
|
||||||
const PathArgument& a3,
|
const PathArgument& a3,
|
||||||
@ -1609,7 +1606,7 @@ Path::Path(const JSONCPP_STRING& path,
|
|||||||
makePath(path, in);
|
makePath(path, in);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
|
void Path::makePath(const 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();
|
||||||
auto itInArg = in.begin();
|
auto itInArg = in.begin();
|
||||||
@ -1635,12 +1632,12 @@ void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
|
|||||||
const char* beginName = current;
|
const char* beginName = current;
|
||||||
while (current != end && !strchr("[.", *current))
|
while (current != end && !strchr("[.", *current))
|
||||||
++current;
|
++current;
|
||||||
args_.push_back(JSONCPP_STRING(beginName, current));
|
args_.push_back(String(beginName, current));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Path::addPathInArg(const JSONCPP_STRING& /*path*/,
|
void Path::addPathInArg(const String& /*path*/,
|
||||||
const InArgs& in,
|
const InArgs& in,
|
||||||
InArgs::const_iterator& itInArg,
|
InArgs::const_iterator& itInArg,
|
||||||
PathArgument::Kind kind) {
|
PathArgument::Kind kind) {
|
||||||
@ -1653,7 +1650,7 @@ void Path::addPathInArg(const JSONCPP_STRING& /*path*/,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Path::invalidPath(const JSONCPP_STRING& /*path*/, int /*location*/) {
|
void Path::invalidPath(const String& /*path*/, int /*location*/) {
|
||||||
// Error: invalid path.
|
// Error: invalid path.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +84,13 @@ UInt ValueIteratorBase::index() const {
|
|||||||
return Value::UInt(-1);
|
return Value::UInt(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING ValueIteratorBase::name() const {
|
String ValueIteratorBase::name() const {
|
||||||
char const* keey;
|
char const* keey;
|
||||||
char const* end;
|
char const* end;
|
||||||
keey = memberName(&end);
|
keey = memberName(&end);
|
||||||
if (!keey)
|
if (!keey)
|
||||||
return JSONCPP_STRING();
|
return String();
|
||||||
return JSONCPP_STRING(keey, end);
|
return String(keey, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* ValueIteratorBase::memberName() const {
|
char const* ValueIteratorBase::memberName() const {
|
||||||
|
@ -89,7 +89,7 @@ typedef std::unique_ptr<StreamWriter> StreamWriterPtr;
|
|||||||
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
|
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JSONCPP_STRING valueToString(LargestInt value) {
|
String valueToString(LargestInt value) {
|
||||||
UIntToStringBuffer buffer;
|
UIntToStringBuffer buffer;
|
||||||
char* current = buffer + sizeof(buffer);
|
char* current = buffer + sizeof(buffer);
|
||||||
if (value == Value::minLargestInt) {
|
if (value == Value::minLargestInt) {
|
||||||
@ -105,7 +105,7 @@ JSONCPP_STRING valueToString(LargestInt value) {
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING valueToString(LargestUInt value) {
|
String valueToString(LargestUInt value) {
|
||||||
UIntToStringBuffer buffer;
|
UIntToStringBuffer buffer;
|
||||||
char* current = buffer + sizeof(buffer);
|
char* current = buffer + sizeof(buffer);
|
||||||
uintToString(value, current);
|
uintToString(value, current);
|
||||||
@ -115,21 +115,17 @@ JSONCPP_STRING valueToString(LargestUInt value) {
|
|||||||
|
|
||||||
#if defined(JSON_HAS_INT64)
|
#if defined(JSON_HAS_INT64)
|
||||||
|
|
||||||
JSONCPP_STRING valueToString(Int value) {
|
String valueToString(Int value) { return valueToString(LargestInt(value)); }
|
||||||
return valueToString(LargestInt(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONCPP_STRING valueToString(UInt value) {
|
String valueToString(UInt value) { return valueToString(LargestUInt(value)); }
|
||||||
return valueToString(LargestUInt(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // # if defined(JSON_HAS_INT64)
|
#endif // # if defined(JSON_HAS_INT64)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
JSONCPP_STRING valueToString(double value,
|
String valueToString(double value,
|
||||||
bool useSpecialFloats,
|
bool useSpecialFloats,
|
||||||
unsigned int precision,
|
unsigned int precision,
|
||||||
PrecisionType precisionType) {
|
PrecisionType precisionType) {
|
||||||
// Print into the buffer. We need not request the alternative representation
|
// Print into the buffer. We need not request the alternative representation
|
||||||
// that always has a decimal point because JSON doesn't distinguish the
|
// that always has a decimal point because JSON doesn't distinguish the
|
||||||
// concepts of reals and integers.
|
// concepts of reals and integers.
|
||||||
@ -140,7 +136,7 @@ JSONCPP_STRING valueToString(double value,
|
|||||||
[isnan(value) ? 0 : (value < 0) ? 1 : 2];
|
[isnan(value) ? 0 : (value < 0) ? 1 : 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING buffer(size_t(36), '\0');
|
String buffer(size_t(36), '\0');
|
||||||
while (true) {
|
while (true) {
|
||||||
int len = jsoncpp_snprintf(
|
int len = jsoncpp_snprintf(
|
||||||
&*buffer.begin(), buffer.size(),
|
&*buffer.begin(), buffer.size(),
|
||||||
@ -172,13 +168,13 @@ JSONCPP_STRING valueToString(double value,
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
JSONCPP_STRING valueToString(double value,
|
String valueToString(double value,
|
||||||
unsigned int precision,
|
unsigned int precision,
|
||||||
PrecisionType precisionType) {
|
PrecisionType precisionType) {
|
||||||
return valueToString(value, false, precision, precisionType);
|
return valueToString(value, false, precision, precisionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING valueToString(bool value) { return value ? "true" : "false"; }
|
String valueToString(bool value) { return value ? "true" : "false"; }
|
||||||
|
|
||||||
static bool isAnyCharRequiredQuoting(char const* s, size_t n) {
|
static bool isAnyCharRequiredQuoting(char const* s, size_t n) {
|
||||||
assert(s || !n);
|
assert(s || !n);
|
||||||
@ -260,10 +256,10 @@ static const char hex2[] = "000102030405060708090a0b0c0d0e0f"
|
|||||||
"e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
|
"e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
|
||||||
"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
|
"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
|
||||||
|
|
||||||
static JSONCPP_STRING toHex16Bit(unsigned int x) {
|
static String toHex16Bit(unsigned int x) {
|
||||||
const unsigned int hi = (x >> 8) & 0xff;
|
const unsigned int hi = (x >> 8) & 0xff;
|
||||||
const unsigned int lo = x & 0xff;
|
const unsigned int lo = x & 0xff;
|
||||||
JSONCPP_STRING result(4, ' ');
|
String result(4, ' ');
|
||||||
result[0] = hex2[2 * hi];
|
result[0] = hex2[2 * hi];
|
||||||
result[1] = hex2[2 * hi + 1];
|
result[1] = hex2[2 * hi + 1];
|
||||||
result[2] = hex2[2 * lo];
|
result[2] = hex2[2 * lo];
|
||||||
@ -271,17 +267,17 @@ static JSONCPP_STRING toHex16Bit(unsigned int x) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSONCPP_STRING valueToQuotedStringN(const char* value, unsigned length) {
|
static String valueToQuotedStringN(const char* value, unsigned length) {
|
||||||
if (value == nullptr)
|
if (value == nullptr)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
if (!isAnyCharRequiredQuoting(value, length))
|
if (!isAnyCharRequiredQuoting(value, length))
|
||||||
return JSONCPP_STRING("\"") + value + "\"";
|
return String("\"") + value + "\"";
|
||||||
// We have to walk value and escape any special characters.
|
// We have to walk value and escape any special characters.
|
||||||
// Appending to JSONCPP_STRING is not efficient, but this should be rare.
|
// Appending to String is not efficient, but this should be rare.
|
||||||
// (Note: forward slashes are *not* rare, but I am not escaping them.)
|
// (Note: forward slashes are *not* rare, but I am not escaping them.)
|
||||||
JSONCPP_STRING::size_type maxsize = length * 2 + 3; // allescaped+quotes+NULL
|
String::size_type maxsize = length * 2 + 3; // allescaped+quotes+NULL
|
||||||
JSONCPP_STRING result;
|
String result;
|
||||||
result.reserve(maxsize); // to avoid lots of mallocs
|
result.reserve(maxsize); // to avoid lots of mallocs
|
||||||
result += "\"";
|
result += "\"";
|
||||||
char const* end = value + length;
|
char const* end = value + length;
|
||||||
@ -340,7 +336,7 @@ static JSONCPP_STRING valueToQuotedStringN(const char* value, unsigned length) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING valueToQuotedString(const char* value) {
|
String valueToQuotedString(const char* value) {
|
||||||
return valueToQuotedStringN(value, static_cast<unsigned int>(strlen(value)));
|
return valueToQuotedStringN(value, static_cast<unsigned int>(strlen(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +357,7 @@ void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
|
|||||||
|
|
||||||
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
|
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
|
||||||
|
|
||||||
JSONCPP_STRING FastWriter::write(const Value& root) {
|
String FastWriter::write(const Value& root) {
|
||||||
document_.clear();
|
document_.clear();
|
||||||
writeValue(root);
|
writeValue(root);
|
||||||
if (!omitEndingLineFeed_)
|
if (!omitEndingLineFeed_)
|
||||||
@ -410,7 +406,7 @@ void FastWriter::writeValue(const Value& value) {
|
|||||||
Value::Members members(value.getMemberNames());
|
Value::Members members(value.getMemberNames());
|
||||||
document_ += '{';
|
document_ += '{';
|
||||||
for (auto it = members.begin(); it != members.end(); ++it) {
|
for (auto it = members.begin(); it != members.end(); ++it) {
|
||||||
const JSONCPP_STRING& name = *it;
|
const String& name = *it;
|
||||||
if (it != members.begin())
|
if (it != members.begin())
|
||||||
document_ += ',';
|
document_ += ',';
|
||||||
document_ += valueToQuotedStringN(name.data(),
|
document_ += valueToQuotedStringN(name.data(),
|
||||||
@ -428,7 +424,7 @@ void FastWriter::writeValue(const Value& value) {
|
|||||||
|
|
||||||
StyledWriter::StyledWriter() = default;
|
StyledWriter::StyledWriter() = default;
|
||||||
|
|
||||||
JSONCPP_STRING StyledWriter::write(const Value& root) {
|
String StyledWriter::write(const Value& root) {
|
||||||
document_.clear();
|
document_.clear();
|
||||||
addChildValues_ = false;
|
addChildValues_ = false;
|
||||||
indentString_.clear();
|
indentString_.clear();
|
||||||
@ -479,7 +475,7 @@ void StyledWriter::writeValue(const Value& value) {
|
|||||||
indent();
|
indent();
|
||||||
auto it = members.begin();
|
auto it = members.begin();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const JSONCPP_STRING& name = *it;
|
const 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()));
|
||||||
@ -569,7 +565,7 @@ bool StyledWriter::isMultilineArray(const Value& value) {
|
|||||||
return isMultiLine;
|
return isMultiLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::pushValue(const JSONCPP_STRING& value) {
|
void StyledWriter::pushValue(const String& value) {
|
||||||
if (addChildValues_)
|
if (addChildValues_)
|
||||||
childValues_.push_back(value);
|
childValues_.push_back(value);
|
||||||
else
|
else
|
||||||
@ -587,14 +583,12 @@ void StyledWriter::writeIndent() {
|
|||||||
document_ += indentString_;
|
document_ += indentString_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::writeWithIndent(const JSONCPP_STRING& value) {
|
void StyledWriter::writeWithIndent(const String& value) {
|
||||||
writeIndent();
|
writeIndent();
|
||||||
document_ += value;
|
document_ += value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledWriter::indent() {
|
void StyledWriter::indent() { indentString_ += String(indentSize_, ' '); }
|
||||||
indentString_ += JSONCPP_STRING(indentSize_, ' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
void StyledWriter::unindent() {
|
void StyledWriter::unindent() {
|
||||||
assert(indentString_.size() >= indentSize_);
|
assert(indentString_.size() >= indentSize_);
|
||||||
@ -607,8 +601,8 @@ void StyledWriter::writeCommentBeforeValue(const Value& root) {
|
|||||||
|
|
||||||
document_ += '\n';
|
document_ += '\n';
|
||||||
writeIndent();
|
writeIndent();
|
||||||
const JSONCPP_STRING& comment = root.getComment(commentBefore);
|
const String& comment = root.getComment(commentBefore);
|
||||||
JSONCPP_STRING::const_iterator iter = comment.begin();
|
String::const_iterator iter = comment.begin();
|
||||||
while (iter != comment.end()) {
|
while (iter != comment.end()) {
|
||||||
document_ += *iter;
|
document_ += *iter;
|
||||||
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
|
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
|
||||||
@ -640,11 +634,11 @@ bool StyledWriter::hasCommentForValue(const Value& value) {
|
|||||||
// Class StyledStreamWriter
|
// Class StyledStreamWriter
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
StyledStreamWriter::StyledStreamWriter(JSONCPP_STRING indentation)
|
StyledStreamWriter::StyledStreamWriter(String indentation)
|
||||||
: document_(nullptr), indentation_(std::move(indentation)),
|
: document_(nullptr), indentation_(std::move(indentation)),
|
||||||
addChildValues_(), indented_(false) {}
|
addChildValues_(), indented_(false) {}
|
||||||
|
|
||||||
void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
|
void StyledStreamWriter::write(OStream& out, const Value& root) {
|
||||||
document_ = &out;
|
document_ = &out;
|
||||||
addChildValues_ = false;
|
addChildValues_ = false;
|
||||||
indentString_.clear();
|
indentString_.clear();
|
||||||
@ -699,7 +693,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
|
|||||||
indent();
|
indent();
|
||||||
auto it = members.begin();
|
auto it = members.begin();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const JSONCPP_STRING& name = *it;
|
const 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()));
|
||||||
@ -792,7 +786,7 @@ bool StyledStreamWriter::isMultilineArray(const Value& value) {
|
|||||||
return isMultiLine;
|
return isMultiLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::pushValue(const JSONCPP_STRING& value) {
|
void StyledStreamWriter::pushValue(const String& value) {
|
||||||
if (addChildValues_)
|
if (addChildValues_)
|
||||||
childValues_.push_back(value);
|
childValues_.push_back(value);
|
||||||
else
|
else
|
||||||
@ -807,7 +801,7 @@ void StyledStreamWriter::writeIndent() {
|
|||||||
*document_ << '\n' << indentString_;
|
*document_ << '\n' << indentString_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::writeWithIndent(const JSONCPP_STRING& value) {
|
void StyledStreamWriter::writeWithIndent(const String& value) {
|
||||||
if (!indented_)
|
if (!indented_)
|
||||||
writeIndent();
|
writeIndent();
|
||||||
*document_ << value;
|
*document_ << value;
|
||||||
@ -827,8 +821,8 @@ void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
|
|||||||
|
|
||||||
if (!indented_)
|
if (!indented_)
|
||||||
writeIndent();
|
writeIndent();
|
||||||
const JSONCPP_STRING& comment = root.getComment(commentBefore);
|
const String& comment = root.getComment(commentBefore);
|
||||||
JSONCPP_STRING::const_iterator iter = comment.begin();
|
String::const_iterator iter = comment.begin();
|
||||||
while (iter != comment.end()) {
|
while (iter != comment.end()) {
|
||||||
*document_ << *iter;
|
*document_ << *iter;
|
||||||
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
|
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
|
||||||
@ -870,61 +864,60 @@ struct CommentStyle {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BuiltStyledStreamWriter : public StreamWriter {
|
struct BuiltStyledStreamWriter : public StreamWriter {
|
||||||
BuiltStyledStreamWriter(JSONCPP_STRING indentation,
|
BuiltStyledStreamWriter(String indentation,
|
||||||
CommentStyle::Enum cs,
|
CommentStyle::Enum cs,
|
||||||
JSONCPP_STRING colonSymbol,
|
String colonSymbol,
|
||||||
JSONCPP_STRING nullSymbol,
|
String nullSymbol,
|
||||||
JSONCPP_STRING endingLineFeedSymbol,
|
String endingLineFeedSymbol,
|
||||||
bool useSpecialFloats,
|
bool useSpecialFloats,
|
||||||
unsigned int precision,
|
unsigned int precision,
|
||||||
PrecisionType precisionType);
|
PrecisionType precisionType);
|
||||||
int write(Value const& root, JSONCPP_OSTREAM* sout) override;
|
int write(Value const& root, OStream* sout) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue(Value const& value);
|
void writeValue(Value const& value);
|
||||||
void writeArrayValue(Value const& value);
|
void writeArrayValue(Value const& value);
|
||||||
bool isMultilineArray(Value const& value);
|
bool isMultilineArray(Value const& value);
|
||||||
void pushValue(JSONCPP_STRING const& value);
|
void pushValue(String const& value);
|
||||||
void writeIndent();
|
void writeIndent();
|
||||||
void writeWithIndent(JSONCPP_STRING const& value);
|
void writeWithIndent(String const& value);
|
||||||
void indent();
|
void indent();
|
||||||
void unindent();
|
void unindent();
|
||||||
void writeCommentBeforeValue(Value const& root);
|
void writeCommentBeforeValue(Value const& root);
|
||||||
void writeCommentAfterValueOnSameLine(Value const& root);
|
void writeCommentAfterValueOnSameLine(Value const& root);
|
||||||
static bool hasCommentForValue(const Value& value);
|
static bool hasCommentForValue(const Value& value);
|
||||||
|
|
||||||
typedef std::vector<JSONCPP_STRING> ChildValues;
|
typedef std::vector<String> ChildValues;
|
||||||
|
|
||||||
ChildValues childValues_;
|
ChildValues childValues_;
|
||||||
JSONCPP_STRING indentString_;
|
String indentString_;
|
||||||
unsigned int rightMargin_;
|
unsigned int rightMargin_;
|
||||||
JSONCPP_STRING indentation_;
|
String indentation_;
|
||||||
CommentStyle::Enum cs_;
|
CommentStyle::Enum cs_;
|
||||||
JSONCPP_STRING colonSymbol_;
|
String colonSymbol_;
|
||||||
JSONCPP_STRING nullSymbol_;
|
String nullSymbol_;
|
||||||
JSONCPP_STRING endingLineFeedSymbol_;
|
String endingLineFeedSymbol_;
|
||||||
bool addChildValues_ : 1;
|
bool addChildValues_ : 1;
|
||||||
bool indented_ : 1;
|
bool indented_ : 1;
|
||||||
bool useSpecialFloats_ : 1;
|
bool useSpecialFloats_ : 1;
|
||||||
unsigned int precision_;
|
unsigned int precision_;
|
||||||
PrecisionType precisionType_;
|
PrecisionType precisionType_;
|
||||||
};
|
};
|
||||||
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
|
BuiltStyledStreamWriter::BuiltStyledStreamWriter(String indentation,
|
||||||
JSONCPP_STRING indentation,
|
CommentStyle::Enum cs,
|
||||||
CommentStyle::Enum cs,
|
String colonSymbol,
|
||||||
JSONCPP_STRING colonSymbol,
|
String nullSymbol,
|
||||||
JSONCPP_STRING nullSymbol,
|
String endingLineFeedSymbol,
|
||||||
JSONCPP_STRING endingLineFeedSymbol,
|
bool useSpecialFloats,
|
||||||
bool useSpecialFloats,
|
unsigned int precision,
|
||||||
unsigned int precision,
|
PrecisionType precisionType)
|
||||||
PrecisionType precisionType)
|
|
||||||
: rightMargin_(74), indentation_(std::move(indentation)), cs_(cs),
|
: rightMargin_(74), indentation_(std::move(indentation)), cs_(cs),
|
||||||
colonSymbol_(std::move(colonSymbol)), nullSymbol_(std::move(nullSymbol)),
|
colonSymbol_(std::move(colonSymbol)), nullSymbol_(std::move(nullSymbol)),
|
||||||
endingLineFeedSymbol_(std::move(endingLineFeedSymbol)),
|
endingLineFeedSymbol_(std::move(endingLineFeedSymbol)),
|
||||||
addChildValues_(false), indented_(false),
|
addChildValues_(false), indented_(false),
|
||||||
useSpecialFloats_(useSpecialFloats), precision_(precision),
|
useSpecialFloats_(useSpecialFloats), precision_(precision),
|
||||||
precisionType_(precisionType) {}
|
precisionType_(precisionType) {}
|
||||||
int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout) {
|
int BuiltStyledStreamWriter::write(Value const& root, OStream* sout) {
|
||||||
sout_ = sout;
|
sout_ = sout;
|
||||||
addChildValues_ = false;
|
addChildValues_ = false;
|
||||||
indented_ = true;
|
indented_ = true;
|
||||||
@ -980,7 +973,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
|
|||||||
indent();
|
indent();
|
||||||
auto it = members.begin();
|
auto it = members.begin();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
JSONCPP_STRING const& name = *it;
|
String const& name = *it;
|
||||||
Value const& childValue = value[name];
|
Value const& childValue = value[name];
|
||||||
writeCommentBeforeValue(childValue);
|
writeCommentBeforeValue(childValue);
|
||||||
writeWithIndent(valueToQuotedStringN(
|
writeWithIndent(valueToQuotedStringN(
|
||||||
@ -1078,7 +1071,7 @@ bool BuiltStyledStreamWriter::isMultilineArray(Value const& value) {
|
|||||||
return isMultiLine;
|
return isMultiLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltStyledStreamWriter::pushValue(JSONCPP_STRING const& value) {
|
void BuiltStyledStreamWriter::pushValue(String const& value) {
|
||||||
if (addChildValues_)
|
if (addChildValues_)
|
||||||
childValues_.push_back(value);
|
childValues_.push_back(value);
|
||||||
else
|
else
|
||||||
@ -1097,7 +1090,7 @@ void BuiltStyledStreamWriter::writeIndent() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltStyledStreamWriter::writeWithIndent(JSONCPP_STRING const& value) {
|
void BuiltStyledStreamWriter::writeWithIndent(String const& value) {
|
||||||
if (!indented_)
|
if (!indented_)
|
||||||
writeIndent();
|
writeIndent();
|
||||||
*sout_ << value;
|
*sout_ << value;
|
||||||
@ -1119,8 +1112,8 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
|
|||||||
|
|
||||||
if (!indented_)
|
if (!indented_)
|
||||||
writeIndent();
|
writeIndent();
|
||||||
const JSONCPP_STRING& comment = root.getComment(commentBefore);
|
const String& comment = root.getComment(commentBefore);
|
||||||
JSONCPP_STRING::const_iterator iter = comment.begin();
|
String::const_iterator iter = comment.begin();
|
||||||
while (iter != comment.end()) {
|
while (iter != comment.end()) {
|
||||||
*sout_ << *iter;
|
*sout_ << *iter;
|
||||||
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
|
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
|
||||||
@ -1160,9 +1153,9 @@ StreamWriter::Factory::~Factory() = default;
|
|||||||
StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); }
|
StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); }
|
||||||
StreamWriterBuilder::~StreamWriterBuilder() = default;
|
StreamWriterBuilder::~StreamWriterBuilder() = default;
|
||||||
StreamWriter* StreamWriterBuilder::newStreamWriter() const {
|
StreamWriter* StreamWriterBuilder::newStreamWriter() const {
|
||||||
JSONCPP_STRING indentation = settings_["indentation"].asString();
|
String indentation = settings_["indentation"].asString();
|
||||||
JSONCPP_STRING cs_str = settings_["commentStyle"].asString();
|
String cs_str = settings_["commentStyle"].asString();
|
||||||
JSONCPP_STRING pt_str = settings_["precisionType"].asString();
|
String pt_str = settings_["precisionType"].asString();
|
||||||
bool eyc = settings_["enableYAMLCompatibility"].asBool();
|
bool eyc = settings_["enableYAMLCompatibility"].asBool();
|
||||||
bool dnp = settings_["dropNullPlaceholders"].asBool();
|
bool dnp = settings_["dropNullPlaceholders"].asBool();
|
||||||
bool usf = settings_["useSpecialFloats"].asBool();
|
bool usf = settings_["useSpecialFloats"].asBool();
|
||||||
@ -1183,24 +1176,24 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const {
|
|||||||
} else {
|
} else {
|
||||||
throwRuntimeError("precisionType must be 'significant' or 'decimal'");
|
throwRuntimeError("precisionType must be 'significant' or 'decimal'");
|
||||||
}
|
}
|
||||||
JSONCPP_STRING colonSymbol = " : ";
|
String colonSymbol = " : ";
|
||||||
if (eyc) {
|
if (eyc) {
|
||||||
colonSymbol = ": ";
|
colonSymbol = ": ";
|
||||||
} else if (indentation.empty()) {
|
} else if (indentation.empty()) {
|
||||||
colonSymbol = ":";
|
colonSymbol = ":";
|
||||||
}
|
}
|
||||||
JSONCPP_STRING nullSymbol = "null";
|
String nullSymbol = "null";
|
||||||
if (dnp) {
|
if (dnp) {
|
||||||
nullSymbol.clear();
|
nullSymbol.clear();
|
||||||
}
|
}
|
||||||
if (pre > 17)
|
if (pre > 17)
|
||||||
pre = 17;
|
pre = 17;
|
||||||
JSONCPP_STRING endingLineFeedSymbol;
|
String endingLineFeedSymbol;
|
||||||
return new BuiltStyledStreamWriter(indentation, cs, colonSymbol, nullSymbol,
|
return new BuiltStyledStreamWriter(indentation, cs, colonSymbol, nullSymbol,
|
||||||
endingLineFeedSymbol, usf, pre,
|
endingLineFeedSymbol, usf, pre,
|
||||||
precisionType);
|
precisionType);
|
||||||
}
|
}
|
||||||
static void getValidWriterKeys(std::set<JSONCPP_STRING>* valid_keys) {
|
static void getValidWriterKeys(std::set<String>* valid_keys) {
|
||||||
valid_keys->clear();
|
valid_keys->clear();
|
||||||
valid_keys->insert("indentation");
|
valid_keys->insert("indentation");
|
||||||
valid_keys->insert("commentStyle");
|
valid_keys->insert("commentStyle");
|
||||||
@ -1215,19 +1208,19 @@ bool StreamWriterBuilder::validate(Json::Value* invalid) const {
|
|||||||
if (!invalid)
|
if (!invalid)
|
||||||
invalid = &my_invalid; // so we do not need to test for NULL
|
invalid = &my_invalid; // so we do not need to test for NULL
|
||||||
Json::Value& inv = *invalid;
|
Json::Value& inv = *invalid;
|
||||||
std::set<JSONCPP_STRING> valid_keys;
|
std::set<String> valid_keys;
|
||||||
getValidWriterKeys(&valid_keys);
|
getValidWriterKeys(&valid_keys);
|
||||||
Value::Members keys = settings_.getMemberNames();
|
Value::Members keys = settings_.getMemberNames();
|
||||||
size_t n = keys.size();
|
size_t n = keys.size();
|
||||||
for (size_t i = 0; i < n; ++i) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
JSONCPP_STRING const& key = keys[i];
|
String const& key = keys[i];
|
||||||
if (valid_keys.find(key) == valid_keys.end()) {
|
if (valid_keys.find(key) == valid_keys.end()) {
|
||||||
inv[key] = settings_[key];
|
inv[key] = settings_[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return inv.empty();
|
return inv.empty();
|
||||||
}
|
}
|
||||||
Value& StreamWriterBuilder::operator[](const JSONCPP_STRING& key) {
|
Value& StreamWriterBuilder::operator[](const String& key) {
|
||||||
return settings_[key];
|
return settings_[key];
|
||||||
}
|
}
|
||||||
// static
|
// static
|
||||||
@ -1243,15 +1236,14 @@ void StreamWriterBuilder::setDefaults(Json::Value* settings) {
|
|||||||
//! [StreamWriterBuilderDefaults]
|
//! [StreamWriterBuilderDefaults]
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING writeString(StreamWriter::Factory const& factory,
|
String writeString(StreamWriter::Factory const& factory, Value const& root) {
|
||||||
Value const& root) {
|
OStringStream sout;
|
||||||
JSONCPP_OSTRINGSTREAM sout;
|
|
||||||
StreamWriterPtr const writer(factory.newStreamWriter());
|
StreamWriterPtr const writer(factory.newStreamWriter());
|
||||||
writer->write(root, &sout);
|
writer->write(root, &sout);
|
||||||
return sout.str();
|
return sout.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM& sout, Value const& root) {
|
OStream& operator<<(OStream& sout, Value const& root) {
|
||||||
StreamWriterBuilder builder;
|
StreamWriterBuilder builder;
|
||||||
StreamWriterPtr const writer(builder.newStreamWriter());
|
StreamWriterPtr const writer(builder.newStreamWriter());
|
||||||
writer->write(root, &sout);
|
writer->write(root, &sout);
|
||||||
|
@ -80,7 +80,7 @@ TestResult::TestResult() {
|
|||||||
predicateStackTail_ = &rootPredicateNode_;
|
predicateStackTail_ = &rootPredicateNode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestResult::setTestName(const JSONCPP_STRING& name) { name_ = name; }
|
void TestResult::setTestName(const Json::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) {
|
||||||
@ -150,7 +150,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
|
||||||
for (const auto& failure : failures_) {
|
for (const auto& failure : failures_) {
|
||||||
JSONCPP_STRING indent(failure.nestingLevel_ * 2, ' ');
|
Json::String indent(failure.nestingLevel_ * 2, ' ');
|
||||||
if (failure.file_) {
|
if (failure.file_) {
|
||||||
printf("%s%s(%u): ", indent.c_str(), failure.file_, failure.line_);
|
printf("%s%s(%u): ", indent.c_str(), failure.file_, failure.line_);
|
||||||
}
|
}
|
||||||
@ -160,19 +160,18 @@ void TestResult::printFailure(bool printTestName) const {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
if (!failure.message_.empty()) {
|
if (!failure.message_.empty()) {
|
||||||
JSONCPP_STRING reindented = indentText(failure.message_, indent + " ");
|
Json::String reindented = indentText(failure.message_, indent + " ");
|
||||||
printf("%s\n", reindented.c_str());
|
printf("%s\n", reindented.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING TestResult::indentText(const JSONCPP_STRING& text,
|
Json::String TestResult::indentText(const Json::String& text, const Json::String& indent) {
|
||||||
const JSONCPP_STRING& indent) {
|
Json::String reindented;
|
||||||
JSONCPP_STRING reindented;
|
Json::String::size_type lastIndex = 0;
|
||||||
JSONCPP_STRING::size_type lastIndex = 0;
|
|
||||||
while (lastIndex < text.size()) {
|
while (lastIndex < text.size()) {
|
||||||
JSONCPP_STRING::size_type nextIndex = text.find('\n', lastIndex);
|
Json::String::size_type nextIndex = text.find('\n', lastIndex);
|
||||||
if (nextIndex == JSONCPP_STRING::npos) {
|
if (nextIndex == Json::String::npos) {
|
||||||
nextIndex = text.size() - 1;
|
nextIndex = text.size() - 1;
|
||||||
}
|
}
|
||||||
reindented += indent;
|
reindented += indent;
|
||||||
@ -182,7 +181,7 @@ JSONCPP_STRING TestResult::indentText(const JSONCPP_STRING& text,
|
|||||||
return reindented;
|
return reindented;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResult& TestResult::addToLastFailure(const JSONCPP_STRING& message) {
|
TestResult& TestResult::addToLastFailure(const Json::String& message) {
|
||||||
if (messageTarget_ != nullptr) {
|
if (messageTarget_ != nullptr) {
|
||||||
messageTarget_->message_ += message;
|
messageTarget_->message_ += message;
|
||||||
}
|
}
|
||||||
@ -225,9 +224,9 @@ Runner& Runner::add(TestCaseFactory factory) {
|
|||||||
|
|
||||||
size_t Runner::testCount() const { return tests_.size(); }
|
size_t Runner::testCount() const { return tests_.size(); }
|
||||||
|
|
||||||
JSONCPP_STRING Runner::testNameAt(size_t index) const {
|
Json::String Runner::testNameAt(size_t index) const {
|
||||||
TestCase* test = tests_[index]();
|
TestCase* test = tests_[index]();
|
||||||
JSONCPP_STRING name = test->testName();
|
Json::String name = test->testName();
|
||||||
delete test;
|
delete test;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -284,7 +283,7 @@ bool Runner::runAllTest(bool printSummary) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Runner::testIndex(const JSONCPP_STRING& testName, size_t& indexOut) const {
|
bool Runner::testIndex(const Json::String& testName, size_t& indexOut) const {
|
||||||
const size_t count = testCount();
|
const size_t count = testCount();
|
||||||
for (size_t index = 0; index < count; ++index) {
|
for (size_t index = 0; index < count; ++index) {
|
||||||
if (testNameAt(index) == testName) {
|
if (testNameAt(index) == testName) {
|
||||||
@ -303,10 +302,10 @@ 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<JSONCPP_STRING> TestNames;
|
// typedef std::deque<String> TestNames;
|
||||||
Runner subrunner;
|
Runner subrunner;
|
||||||
for (int index = 1; index < argc; ++index) {
|
for (int index = 1; index < argc; ++index) {
|
||||||
JSONCPP_STRING opt = argv[index];
|
Json::String opt = argv[index];
|
||||||
if (opt == "--list-tests") {
|
if (opt == "--list-tests") {
|
||||||
listTests();
|
listTests();
|
||||||
return 0;
|
return 0;
|
||||||
@ -406,21 +405,19 @@ void Runner::printUsage(const char* appName) {
|
|||||||
// Assertion functions
|
// Assertion functions
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
JSONCPP_STRING ToJsonString(const char* toConvert) {
|
Json::String ToJsonString(const char* toConvert) { return Json::String(toConvert); }
|
||||||
return JSONCPP_STRING(toConvert);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONCPP_STRING ToJsonString(JSONCPP_STRING in) { return in; }
|
Json::String ToJsonString(Json::String in) { return in; }
|
||||||
|
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
#if JSONCPP_USING_SECURE_MEMORY
|
||||||
JSONCPP_STRING ToJsonString(std::string in) {
|
Json::String ToJsonString(std::string in) {
|
||||||
return JSONCPP_STRING(in.data(), in.data() + in.length());
|
return Json::String(in.data(), in.data() + in.length());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TestResult& checkStringEqual(TestResult& result,
|
TestResult& checkStringEqual(TestResult& result,
|
||||||
const JSONCPP_STRING& expected,
|
const Json::String& expected,
|
||||||
const JSONCPP_STRING& actual,
|
const Json::String& actual,
|
||||||
const char* file,
|
const char* file,
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
const char* expr) {
|
const char* expr) {
|
||||||
|
@ -32,8 +32,8 @@ class Failure {
|
|||||||
public:
|
public:
|
||||||
const char* file_;
|
const char* file_;
|
||||||
unsigned int line_;
|
unsigned int line_;
|
||||||
JSONCPP_STRING expr_;
|
Json::String expr_;
|
||||||
JSONCPP_STRING message_;
|
Json::String message_;
|
||||||
unsigned int nestingLevel_;
|
unsigned int nestingLevel_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public:
|
|||||||
/// \internal Implementation detail for predicate macros
|
/// \internal Implementation detail for predicate macros
|
||||||
PredicateContext* predicateStackTail_;
|
PredicateContext* predicateStackTail_;
|
||||||
|
|
||||||
void setTestName(const JSONCPP_STRING& name);
|
void setTestName(const Json::String& name);
|
||||||
|
|
||||||
/// Adds an assertion failure.
|
/// Adds an assertion failure.
|
||||||
TestResult&
|
TestResult&
|
||||||
@ -82,7 +82,7 @@ public:
|
|||||||
|
|
||||||
// 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) {
|
||||||
JSONCPP_OSTRINGSTREAM oss;
|
Json::OStringStream oss;
|
||||||
oss.precision(16);
|
oss.precision(16);
|
||||||
oss.setf(std::ios_base::floatfield);
|
oss.setf(std::ios_base::floatfield);
|
||||||
oss << value;
|
oss << value;
|
||||||
@ -96,18 +96,17 @@ public:
|
|||||||
TestResult& operator<<(Json::UInt64 value);
|
TestResult& operator<<(Json::UInt64 value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TestResult& addToLastFailure(const JSONCPP_STRING& message);
|
TestResult& addToLastFailure(const Json::String& message);
|
||||||
/// 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 JSONCPP_STRING indentText(const JSONCPP_STRING& text,
|
static Json::String indentText(const Json::String& text, const Json::String& indent);
|
||||||
const JSONCPP_STRING& indent);
|
|
||||||
|
|
||||||
typedef std::deque<Failure> Failures;
|
typedef std::deque<Failure> Failures;
|
||||||
Failures failures_;
|
Failures failures_;
|
||||||
JSONCPP_STRING name_;
|
Json::String name_;
|
||||||
PredicateContext rootPredicateNode_;
|
PredicateContext rootPredicateNode_;
|
||||||
PredicateContext::Id lastUsedPredicateId_{ 0 };
|
PredicateContext::Id lastUsedPredicateId_{ 0 };
|
||||||
/// Failure which is the target of the messages added using operator <<
|
/// Failure which is the target of the messages added using operator <<
|
||||||
@ -154,7 +153,7 @@ public:
|
|||||||
size_t testCount() const;
|
size_t testCount() const;
|
||||||
|
|
||||||
/// Returns the name of the test case at the specified index
|
/// Returns the name of the test case at the specified index
|
||||||
JSONCPP_STRING testNameAt(size_t index) const;
|
Json::String testNameAt(size_t 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(size_t index, TestResult& result) const;
|
void runTestAt(size_t index, TestResult& result) const;
|
||||||
@ -167,7 +166,7 @@ private: // prevents copy construction and assignment
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void listTests() const;
|
void listTests() const;
|
||||||
bool testIndex(const JSONCPP_STRING& testName, size_t& indexOut) const;
|
bool testIndex(const Json::String& testName, size_t& indexOut) const;
|
||||||
static void preventDialogOnCrash();
|
static void preventDialogOnCrash();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -190,15 +189,15 @@ TestResult& checkEqual(TestResult& result,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING ToJsonString(const char* toConvert);
|
Json::String ToJsonString(const char* toConvert);
|
||||||
JSONCPP_STRING ToJsonString(JSONCPP_STRING in);
|
Json::String ToJsonString(Json::String in);
|
||||||
#if JSONCPP_USING_SECURE_MEMORY
|
#if JSONCPP_USING_SECURE_MEMORY
|
||||||
JSONCPP_STRING ToJsonString(std::string in);
|
Json::String ToJsonString(std::string in);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TestResult& checkStringEqual(TestResult& result,
|
TestResult& checkStringEqual(TestResult& result,
|
||||||
const JSONCPP_STRING& expected,
|
const Json::String& expected,
|
||||||
const JSONCPP_STRING& actual,
|
const Json::String& actual,
|
||||||
const char* file,
|
const char* file,
|
||||||
unsigned int line,
|
unsigned int line,
|
||||||
const char* expr);
|
const char* expr);
|
||||||
|
@ -110,21 +110,20 @@ struct ValueTest : JsonTest::TestCase {
|
|||||||
|
|
||||||
/// 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 JSONCPP_STRING normalizeFloatingPointStr(const JSONCPP_STRING& s);
|
static Json::String normalizeFloatingPointStr(const Json::String& s);
|
||||||
};
|
};
|
||||||
|
|
||||||
JSONCPP_STRING ValueTest::normalizeFloatingPointStr(const JSONCPP_STRING& s) {
|
Json::String ValueTest::normalizeFloatingPointStr(const Json::String& s) {
|
||||||
JSONCPP_STRING::size_type index = s.find_last_of("eE");
|
Json::String::size_type index = s.find_last_of("eE");
|
||||||
if (index != JSONCPP_STRING::npos) {
|
if (index != Json::String::npos) {
|
||||||
JSONCPP_STRING::size_type hasSign =
|
Json::String::size_type hasSign =
|
||||||
(s[index + 1] == '+' || s[index + 1] == '-') ? 1 : 0;
|
(s[index + 1] == '+' || s[index + 1] == '-') ? 1 : 0;
|
||||||
JSONCPP_STRING::size_type exponentStartIndex = index + 1 + hasSign;
|
Json::String::size_type exponentStartIndex = index + 1 + hasSign;
|
||||||
JSONCPP_STRING normalized = s.substr(0, exponentStartIndex);
|
Json::String normalized = s.substr(0, exponentStartIndex);
|
||||||
JSONCPP_STRING::size_type indexDigit =
|
Json::String::size_type indexDigit = s.find_first_not_of('0', exponentStartIndex);
|
||||||
s.find_first_not_of('0', exponentStartIndex);
|
Json::String exponent = "0";
|
||||||
JSONCPP_STRING exponent = "0";
|
if (indexDigit != Json::String::npos) // There is an exponent different
|
||||||
if (indexDigit != JSONCPP_STRING::npos) // There is an exponent different
|
// from 0
|
||||||
// from 0
|
|
||||||
{
|
{
|
||||||
exponent = s.substr(indexDigit);
|
exponent = s.substr(indexDigit);
|
||||||
}
|
}
|
||||||
@ -1601,7 +1600,7 @@ JSONTEST_FIXTURE(ValueTest, offsetAccessors) {
|
|||||||
JSONTEST_FIXTURE(ValueTest, StaticString) {
|
JSONTEST_FIXTURE(ValueTest, StaticString) {
|
||||||
char mutant[] = "hello";
|
char mutant[] = "hello";
|
||||||
Json::StaticString ss(mutant);
|
Json::StaticString ss(mutant);
|
||||||
JSONCPP_STRING regular(mutant);
|
Json::String regular(mutant);
|
||||||
mutant[1] = 'a';
|
mutant[1] = 'a';
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("hallo", ss.c_str());
|
JSONTEST_ASSERT_STRING_EQUAL("hallo", ss.c_str());
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("hello", regular.c_str());
|
JSONTEST_ASSERT_STRING_EQUAL("hello", regular.c_str());
|
||||||
@ -1623,16 +1622,16 @@ JSONTEST_FIXTURE(ValueTest, StaticString) {
|
|||||||
|
|
||||||
JSONTEST_FIXTURE(ValueTest, CommentBefore) {
|
JSONTEST_FIXTURE(ValueTest, CommentBefore) {
|
||||||
Json::Value val; // fill val
|
Json::Value val; // fill val
|
||||||
val.setComment(JSONCPP_STRING("// this comment should appear before"),
|
val.setComment(Json::String("// this comment should appear before"),
|
||||||
Json::commentBefore);
|
Json::commentBefore);
|
||||||
Json::StreamWriterBuilder wbuilder;
|
Json::StreamWriterBuilder wbuilder;
|
||||||
wbuilder.settings_["commentStyle"] = "All";
|
wbuilder.settings_["commentStyle"] = "All";
|
||||||
{
|
{
|
||||||
char const expected[] = "// this comment should appear before\nnull";
|
char const expected[] = "// this comment should appear before\nnull";
|
||||||
JSONCPP_STRING result = Json::writeString(wbuilder, val);
|
Json::String result = Json::writeString(wbuilder, val);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||||
JSONCPP_STRING res2 = val.toStyledString();
|
Json::String res2 = val.toStyledString();
|
||||||
JSONCPP_STRING exp2 = "\n";
|
Json::String exp2 = "\n";
|
||||||
exp2 += expected;
|
exp2 += expected;
|
||||||
exp2 += "\n";
|
exp2 += "\n";
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
|
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
|
||||||
@ -1641,10 +1640,10 @@ JSONTEST_FIXTURE(ValueTest, CommentBefore) {
|
|||||||
val.swapPayload(other);
|
val.swapPayload(other);
|
||||||
{
|
{
|
||||||
char const expected[] = "// this comment should appear before\n\"hello\"";
|
char const expected[] = "// this comment should appear before\n\"hello\"";
|
||||||
JSONCPP_STRING result = Json::writeString(wbuilder, val);
|
Json::String result = Json::writeString(wbuilder, val);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||||
JSONCPP_STRING res2 = val.toStyledString();
|
Json::String res2 = val.toStyledString();
|
||||||
JSONCPP_STRING exp2 = "\n";
|
Json::String exp2 = "\n";
|
||||||
exp2 += expected;
|
exp2 += expected;
|
||||||
exp2 += "\n";
|
exp2 += "\n";
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
|
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
|
||||||
@ -1655,10 +1654,10 @@ JSONTEST_FIXTURE(ValueTest, CommentBefore) {
|
|||||||
// Json::CommentPlacement::commentBefore); Assignment over-writes comments.
|
// Json::CommentPlacement::commentBefore); Assignment over-writes comments.
|
||||||
{
|
{
|
||||||
char const expected[] = "\"hello\"";
|
char const expected[] = "\"hello\"";
|
||||||
JSONCPP_STRING result = Json::writeString(wbuilder, val);
|
Json::String result = Json::writeString(wbuilder, val);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||||
JSONCPP_STRING res2 = val.toStyledString();
|
Json::String res2 = val.toStyledString();
|
||||||
JSONCPP_STRING exp2 = "";
|
Json::String exp2 = "";
|
||||||
exp2 += expected;
|
exp2 += expected;
|
||||||
exp2 += "\n";
|
exp2 += "\n";
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
|
JSONTEST_ASSERT_STRING_EQUAL(exp2, res2);
|
||||||
@ -1667,7 +1666,7 @@ JSONTEST_FIXTURE(ValueTest, CommentBefore) {
|
|||||||
|
|
||||||
JSONTEST_FIXTURE(ValueTest, zeroes) {
|
JSONTEST_FIXTURE(ValueTest, zeroes) {
|
||||||
char const cstr[] = "h\0i";
|
char const cstr[] = "h\0i";
|
||||||
JSONCPP_STRING binary(cstr, sizeof(cstr)); // include trailing 0
|
Json::String binary(cstr, sizeof(cstr)); // include trailing 0
|
||||||
JSONTEST_ASSERT_EQUAL(4U, binary.length());
|
JSONTEST_ASSERT_EQUAL(4U, binary.length());
|
||||||
Json::StreamWriterBuilder b;
|
Json::StreamWriterBuilder b;
|
||||||
{
|
{
|
||||||
@ -1693,7 +1692,7 @@ JSONTEST_FIXTURE(ValueTest, zeroes) {
|
|||||||
|
|
||||||
JSONTEST_FIXTURE(ValueTest, zeroesInKeys) {
|
JSONTEST_FIXTURE(ValueTest, zeroesInKeys) {
|
||||||
char const cstr[] = "h\0i";
|
char const cstr[] = "h\0i";
|
||||||
JSONCPP_STRING binary(cstr, sizeof(cstr)); // include trailing 0
|
Json::String binary(cstr, sizeof(cstr)); // include trailing 0
|
||||||
JSONTEST_ASSERT_EQUAL(4U, binary.length());
|
JSONTEST_ASSERT_EQUAL(4U, binary.length());
|
||||||
{
|
{
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
@ -1724,8 +1723,8 @@ JSONTEST_FIXTURE(ValueTest, specialFloats) {
|
|||||||
b.settings_["useSpecialFloats"] = true;
|
b.settings_["useSpecialFloats"] = true;
|
||||||
|
|
||||||
Json::Value v = std::numeric_limits<double>::quiet_NaN();
|
Json::Value v = std::numeric_limits<double>::quiet_NaN();
|
||||||
JSONCPP_STRING expected = "NaN";
|
Json::String expected = "NaN";
|
||||||
JSONCPP_STRING result = Json::writeString(b, v);
|
Json::String result = Json::writeString(b, v);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||||
|
|
||||||
v = std::numeric_limits<double>::infinity();
|
v = std::numeric_limits<double>::infinity();
|
||||||
@ -1744,8 +1743,8 @@ JSONTEST_FIXTURE(ValueTest, precision) {
|
|||||||
b.settings_["precision"] = 5;
|
b.settings_["precision"] = 5;
|
||||||
|
|
||||||
Json::Value v = 100.0 / 3;
|
Json::Value v = 100.0 / 3;
|
||||||
JSONCPP_STRING expected = "33.333";
|
Json::String expected = "33.333";
|
||||||
JSONCPP_STRING result = Json::writeString(b, v);
|
Json::String result = Json::writeString(b, v);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
JSONTEST_ASSERT_STRING_EQUAL(expected, result);
|
||||||
|
|
||||||
v = 0.25000000;
|
v = 0.25000000;
|
||||||
@ -1820,15 +1819,15 @@ JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSONTEST_FIXTURE(StreamWriterTest, writeZeroes) {
|
JSONTEST_FIXTURE(StreamWriterTest, writeZeroes) {
|
||||||
JSONCPP_STRING binary("hi", 3); // include trailing 0
|
Json::String binary("hi", 3); // include trailing 0
|
||||||
JSONTEST_ASSERT_EQUAL(3, binary.length());
|
JSONTEST_ASSERT_EQUAL(3, binary.length());
|
||||||
JSONCPP_STRING expected("\"hi\\u0000\""); // unicoded zero
|
Json::String expected("\"hi\\u0000\""); // unicoded zero
|
||||||
Json::StreamWriterBuilder b;
|
Json::StreamWriterBuilder b;
|
||||||
{
|
{
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
root = binary;
|
root = binary;
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(binary, root.asString());
|
JSONTEST_ASSERT_STRING_EQUAL(binary, root.asString());
|
||||||
JSONCPP_STRING out = Json::writeString(b, root);
|
Json::String out = Json::writeString(b, root);
|
||||||
JSONTEST_ASSERT_EQUAL(expected.size(), out.size());
|
JSONTEST_ASSERT_EQUAL(expected.size(), out.size());
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, out);
|
JSONTEST_ASSERT_STRING_EQUAL(expected, out);
|
||||||
}
|
}
|
||||||
@ -1836,7 +1835,7 @@ JSONTEST_FIXTURE(StreamWriterTest, writeZeroes) {
|
|||||||
Json::Value root;
|
Json::Value root;
|
||||||
root["top"] = binary;
|
root["top"] = binary;
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(binary, root["top"].asString());
|
JSONTEST_ASSERT_STRING_EQUAL(binary, root["top"].asString());
|
||||||
JSONCPP_STRING out = Json::writeString(b, root["top"]);
|
Json::String out = Json::writeString(b, root["top"]);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, out);
|
JSONTEST_ASSERT_STRING_EQUAL(expected, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1937,7 +1936,7 @@ struct CharReaderTest : JsonTest::TestCase {};
|
|||||||
JSONTEST_FIXTURE(CharReaderTest, parseWithNoErrors) {
|
JSONTEST_FIXTURE(CharReaderTest, parseWithNoErrors) {
|
||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
char const doc[] = "{ \"property\" : \"value\" }";
|
char const doc[] = "{ \"property\" : \"value\" }";
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
@ -1949,7 +1948,7 @@ JSONTEST_FIXTURE(CharReaderTest, parseWithNoErrors) {
|
|||||||
JSONTEST_FIXTURE(CharReaderTest, parseWithNoErrorsTestingOffsets) {
|
JSONTEST_FIXTURE(CharReaderTest, parseWithNoErrorsTestingOffsets) {
|
||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
char const doc[] = "{ \"property\" : [\"value\", \"value2\"], \"obj\" : "
|
char const doc[] = "{ \"property\" : [\"value\", \"value2\"], \"obj\" : "
|
||||||
"{ \"nested\" : 123, \"bool\" : true}, \"null\" : "
|
"{ \"nested\" : 123, \"bool\" : true}, \"null\" : "
|
||||||
@ -1963,7 +1962,7 @@ JSONTEST_FIXTURE(CharReaderTest, parseWithNoErrorsTestingOffsets) {
|
|||||||
JSONTEST_FIXTURE(CharReaderTest, parseWithOneError) {
|
JSONTEST_FIXTURE(CharReaderTest, parseWithOneError) {
|
||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
char const doc[] = "{ \"property\" :: \"value\" }";
|
char const doc[] = "{ \"property\" :: \"value\" }";
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
@ -1977,7 +1976,7 @@ JSONTEST_FIXTURE(CharReaderTest, parseWithOneError) {
|
|||||||
JSONTEST_FIXTURE(CharReaderTest, parseChineseWithOneError) {
|
JSONTEST_FIXTURE(CharReaderTest, parseChineseWithOneError) {
|
||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
char const doc[] = "{ \"pr佐藤erty\" :: \"value\" }";
|
char const doc[] = "{ \"pr佐藤erty\" :: \"value\" }";
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
@ -1991,7 +1990,7 @@ JSONTEST_FIXTURE(CharReaderTest, parseChineseWithOneError) {
|
|||||||
JSONTEST_FIXTURE(CharReaderTest, parseWithDetailError) {
|
JSONTEST_FIXTURE(CharReaderTest, parseWithDetailError) {
|
||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
char const doc[] = "{ \"property\" : \"v\\alue\" }";
|
char const doc[] = "{ \"property\" : \"v\\alue\" }";
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
@ -2009,7 +2008,7 @@ JSONTEST_FIXTURE(CharReaderTest, parseWithStackLimit) {
|
|||||||
{
|
{
|
||||||
b.settings_["stackLimit"] = 2;
|
b.settings_["stackLimit"] = 2;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(ok);
|
JSONTEST_ASSERT(ok);
|
||||||
JSONTEST_ASSERT(errs.empty());
|
JSONTEST_ASSERT(errs.empty());
|
||||||
@ -2019,7 +2018,7 @@ JSONTEST_FIXTURE(CharReaderTest, parseWithStackLimit) {
|
|||||||
{
|
{
|
||||||
b.settings_["stackLimit"] = 1;
|
b.settings_["stackLimit"] = 1;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
JSONTEST_ASSERT_THROWS(
|
JSONTEST_ASSERT_THROWS(
|
||||||
reader->parse(doc, doc + std::strlen(doc), &root, &errs));
|
reader->parse(doc, doc + std::strlen(doc), &root, &errs));
|
||||||
delete reader;
|
delete reader;
|
||||||
@ -2036,7 +2035,7 @@ JSONTEST_FIXTURE(CharReaderStrictModeTest, dupKeys) {
|
|||||||
{
|
{
|
||||||
b.strictMode(&b.settings_);
|
b.strictMode(&b.settings_);
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(!ok);
|
JSONTEST_ASSERT(!ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 41\n"
|
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 41\n"
|
||||||
@ -2056,7 +2055,7 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue164) {
|
|||||||
{
|
{
|
||||||
b.settings_["failIfExtra"] = false;
|
b.settings_["failIfExtra"] = false;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(ok);
|
JSONTEST_ASSERT(ok);
|
||||||
JSONTEST_ASSERT(errs.empty());
|
JSONTEST_ASSERT(errs.empty());
|
||||||
@ -2066,7 +2065,7 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue164) {
|
|||||||
{
|
{
|
||||||
b.settings_["failIfExtra"] = true;
|
b.settings_["failIfExtra"] = true;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(!ok);
|
JSONTEST_ASSERT(!ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(errs,
|
JSONTEST_ASSERT_STRING_EQUAL(errs,
|
||||||
@ -2079,7 +2078,7 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue164) {
|
|||||||
b.settings_["failIfExtra"] = false;
|
b.settings_["failIfExtra"] = false;
|
||||||
b.strictMode(&b.settings_);
|
b.strictMode(&b.settings_);
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(!ok);
|
JSONTEST_ASSERT(!ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(errs,
|
JSONTEST_ASSERT_STRING_EQUAL(errs,
|
||||||
@ -2096,7 +2095,7 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue107) {
|
|||||||
char const doc[] = "1:2:3";
|
char const doc[] = "1:2:3";
|
||||||
b.settings_["failIfExtra"] = true;
|
b.settings_["failIfExtra"] = true;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(!ok);
|
JSONTEST_ASSERT(!ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 2\n"
|
JSONTEST_ASSERT_STRING_EQUAL("* Line 1, Column 2\n"
|
||||||
@ -2112,7 +2111,7 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, commentAfterObject) {
|
|||||||
char const doc[] = "{ \"property\" : \"value\" } //trailing\n//comment\n";
|
char const doc[] = "{ \"property\" : \"value\" } //trailing\n//comment\n";
|
||||||
b.settings_["failIfExtra"] = true;
|
b.settings_["failIfExtra"] = true;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(ok);
|
JSONTEST_ASSERT(ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
@ -2126,7 +2125,7 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, commentAfterArray) {
|
|||||||
char const doc[] = "[ \"property\" , \"value\" ] //trailing\n//comment\n";
|
char const doc[] = "[ \"property\" , \"value\" ] //trailing\n//comment\n";
|
||||||
b.settings_["failIfExtra"] = true;
|
b.settings_["failIfExtra"] = true;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(ok);
|
JSONTEST_ASSERT(ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
@ -2139,7 +2138,7 @@ JSONTEST_FIXTURE(CharReaderFailIfExtraTest, commentAfterBool) {
|
|||||||
char const doc[] = " true /*trailing\ncomment*/";
|
char const doc[] = " true /*trailing\ncomment*/";
|
||||||
b.settings_["failIfExtra"] = true;
|
b.settings_["failIfExtra"] = true;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
|
||||||
JSONTEST_ASSERT(ok);
|
JSONTEST_ASSERT(ok);
|
||||||
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
JSONTEST_ASSERT_STRING_EQUAL("", errs);
|
||||||
@ -2152,7 +2151,7 @@ JSONTEST_FIXTURE(CharReaderAllowDropNullTest, issue178) {
|
|||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
b.settings_["allowDroppedNullPlaceholders"] = true;
|
b.settings_["allowDroppedNullPlaceholders"] = true;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
{
|
{
|
||||||
char const doc[] = "{\"a\":,\"b\":true}";
|
char const doc[] = "{\"a\":,\"b\":true}";
|
||||||
@ -2274,7 +2273,7 @@ JSONTEST_FIXTURE(CharReaderAllowSingleQuotesTest, issue182) {
|
|||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
b.settings_["allowSingleQuotes"] = true;
|
b.settings_["allowSingleQuotes"] = true;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
{
|
{
|
||||||
char const doc[] = "{'a':true,\"b\":true}";
|
char const doc[] = "{'a':true,\"b\":true}";
|
||||||
@ -2303,7 +2302,7 @@ JSONTEST_FIXTURE(CharReaderAllowZeroesTest, issue176) {
|
|||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
b.settings_["allowSingleQuotes"] = true;
|
b.settings_["allowSingleQuotes"] = true;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
{
|
{
|
||||||
char const doc[] = "{'a':true,\"b\":true}";
|
char const doc[] = "{'a':true,\"b\":true}";
|
||||||
@ -2332,7 +2331,7 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
|
|||||||
Json::CharReaderBuilder b;
|
Json::CharReaderBuilder b;
|
||||||
b.settings_["allowSpecialFloats"] = true;
|
b.settings_["allowSpecialFloats"] = true;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
JSONCPP_STRING errs;
|
Json::String errs;
|
||||||
Json::CharReader* reader(b.newCharReader());
|
Json::CharReader* reader(b.newCharReader());
|
||||||
{
|
{
|
||||||
char const doc[] = "{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity}";
|
char const doc[] = "{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity}";
|
||||||
@ -2351,7 +2350,7 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
|
|||||||
struct TestData {
|
struct TestData {
|
||||||
int line;
|
int line;
|
||||||
bool ok;
|
bool ok;
|
||||||
JSONCPP_STRING in;
|
Json::String in;
|
||||||
};
|
};
|
||||||
const TestData test_data[] = {
|
const TestData test_data[] = {
|
||||||
{ __LINE__, true, "{\"a\":9}" }, //
|
{ __LINE__, true, "{\"a\":9}" }, //
|
||||||
@ -2426,7 +2425,7 @@ JSONTEST_FIXTURE(IteratorTest, distance) {
|
|||||||
json["k1"] = "a";
|
json["k1"] = "a";
|
||||||
json["k2"] = "b";
|
json["k2"] = "b";
|
||||||
int dist = 0;
|
int dist = 0;
|
||||||
JSONCPP_STRING str;
|
Json::String str;
|
||||||
for (Json::ValueIterator it = json.begin(); it != json.end(); ++it) {
|
for (Json::ValueIterator it = json.begin(); it != json.end(); ++it) {
|
||||||
dist = it - json.begin();
|
dist = it - json.begin();
|
||||||
str = it->asString().c_str();
|
str = it->asString().c_str();
|
||||||
@ -2480,19 +2479,19 @@ JSONTEST_FIXTURE(IteratorTest, const) {
|
|||||||
Json::Value value;
|
Json::Value value;
|
||||||
|
|
||||||
for (int i = 9; i < 12; ++i) {
|
for (int i = 9; i < 12; ++i) {
|
||||||
JSONCPP_OSTRINGSTREAM out;
|
Json::OStringStream out;
|
||||||
out << std::setw(2) << i;
|
out << std::setw(2) << i;
|
||||||
JSONCPP_STRING str = out.str();
|
Json::String str = out.str();
|
||||||
value[str] = str;
|
value[str] = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_OSTRINGSTREAM out;
|
Json::OStringStream out;
|
||||||
// in old code, this will get a compile error
|
// in old code, this will get a compile error
|
||||||
Json::Value::const_iterator iter = value.begin();
|
Json::Value::const_iterator iter = value.begin();
|
||||||
for (; iter != value.end(); ++iter) {
|
for (; iter != value.end(); ++iter) {
|
||||||
out << *iter << ',';
|
out << *iter << ',';
|
||||||
}
|
}
|
||||||
JSONCPP_STRING expected = "\" 9\",\"10\",\"11\",";
|
Json::String expected = "\" 9\",\"10\",\"11\",";
|
||||||
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
|
JSONTEST_ASSERT_STRING_EQUAL(expected, out.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user