Added prop svn:eol-style native. Stripped carriage-returns on unix. Hopefully, this will work for Windows too now.
This commit is contained in:
parent
b2f720456e
commit
6d135cb5e3
@ -1,19 +1,19 @@
|
|||||||
#ifndef JSON_AUTOLINK_H_INCLUDED
|
#ifndef JSON_AUTOLINK_H_INCLUDED
|
||||||
# define JSON_AUTOLINK_H_INCLUDED
|
# define JSON_AUTOLINK_H_INCLUDED
|
||||||
|
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
||||||
# ifdef JSON_IN_CPPTL
|
# ifdef JSON_IN_CPPTL
|
||||||
# include <cpptl/cpptl_autolink.h>
|
# include <cpptl/cpptl_autolink.h>
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && !defined(JSON_IN_CPPTL)
|
# if !defined(JSON_NO_AUTOLINK) && !defined(JSON_DLL_BUILD) && !defined(JSON_IN_CPPTL)
|
||||||
# define CPPTL_AUTOLINK_NAME "json"
|
# define CPPTL_AUTOLINK_NAME "json"
|
||||||
# undef CPPTL_AUTOLINK_DLL
|
# undef CPPTL_AUTOLINK_DLL
|
||||||
# ifdef JSON_DLL
|
# ifdef JSON_DLL
|
||||||
# define CPPTL_AUTOLINK_DLL
|
# define CPPTL_AUTOLINK_DLL
|
||||||
# endif
|
# endif
|
||||||
# include "autolink.h"
|
# include "autolink.h"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif // JSON_AUTOLINK_H_INCLUDED
|
#endif // JSON_AUTOLINK_H_INCLUDED
|
||||||
|
@ -1,40 +1,40 @@
|
|||||||
#ifndef JSON_CONFIG_H_INCLUDED
|
#ifndef JSON_CONFIG_H_INCLUDED
|
||||||
# define JSON_CONFIG_H_INCLUDED
|
# define JSON_CONFIG_H_INCLUDED
|
||||||
|
|
||||||
/// 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
|
||||||
|
|
||||||
/// If defined, indicates that json may leverage CppTL library
|
/// If defined, indicates that json may leverage CppTL library
|
||||||
//# define JSON_USE_CPPTL 1
|
//# define JSON_USE_CPPTL 1
|
||||||
/// If defined, indicates that cpptl vector based map should be used instead of std::map
|
/// If defined, indicates that cpptl vector based map should be used instead of std::map
|
||||||
/// as Value container.
|
/// as Value container.
|
||||||
//# define JSON_USE_CPPTL_SMALLMAP 1
|
//# define JSON_USE_CPPTL_SMALLMAP 1
|
||||||
/// If defined, indicates that Json specific container should be used
|
/// If defined, indicates that Json specific container should be used
|
||||||
/// (hash table & simple deque container with customizable allocator).
|
/// (hash table & simple deque container with customizable allocator).
|
||||||
/// THIS FEATURE IS STILL EXPERIMENTAL!
|
/// THIS FEATURE IS STILL EXPERIMENTAL!
|
||||||
//# define JSON_VALUE_USE_INTERNAL_MAP 1
|
//# define JSON_VALUE_USE_INTERNAL_MAP 1
|
||||||
/// Force usage of standard new/malloc based allocator instead of memory pool based allocator.
|
/// Force usage of standard new/malloc based allocator instead of memory pool based allocator.
|
||||||
/// The memory pools allocator used optimization (initializing Value and ValueInternalLink
|
/// The memory pools allocator used optimization (initializing Value and ValueInternalLink
|
||||||
/// as if it was a POD) that may cause some validation tool to report errors.
|
/// as if it was a POD) that may cause some validation tool to report errors.
|
||||||
/// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined.
|
/// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined.
|
||||||
//# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
|
//# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
|
||||||
|
|
||||||
|
|
||||||
# ifdef JSON_IN_CPPTL
|
# ifdef JSON_IN_CPPTL
|
||||||
# include <cpptl/config.h>
|
# include <cpptl/config.h>
|
||||||
# ifndef JSON_USE_CPPTL
|
# ifndef JSON_USE_CPPTL
|
||||||
# define JSON_USE_CPPTL 1
|
# define JSON_USE_CPPTL 1
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifdef JSON_IN_CPPTL
|
# ifdef JSON_IN_CPPTL
|
||||||
# define JSON_API CPPTL_API
|
# define JSON_API CPPTL_API
|
||||||
# elif defined(JSON_DLL_BUILD)
|
# elif defined(JSON_DLL_BUILD)
|
||||||
# define JSON_API __declspec(dllexport)
|
# define JSON_API __declspec(dllexport)
|
||||||
# elif defined(JSON_DLL)
|
# elif defined(JSON_DLL)
|
||||||
# define JSON_API __declspec(dllimport)
|
# define JSON_API __declspec(dllimport)
|
||||||
# else
|
# else
|
||||||
# define JSON_API
|
# define JSON_API
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif // JSON_CONFIG_H_INCLUDED
|
#endif // JSON_CONFIG_H_INCLUDED
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
#ifndef JSON_FORWARDS_H_INCLUDED
|
#ifndef JSON_FORWARDS_H_INCLUDED
|
||||||
# define JSON_FORWARDS_H_INCLUDED
|
# define JSON_FORWARDS_H_INCLUDED
|
||||||
|
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
class FastWriter;
|
class FastWriter;
|
||||||
class Reader;
|
class Reader;
|
||||||
class StyledWriter;
|
class StyledWriter;
|
||||||
|
|
||||||
// value.h
|
// value.h
|
||||||
class StaticString;
|
class StaticString;
|
||||||
class Path;
|
class Path;
|
||||||
class PathArgument;
|
class PathArgument;
|
||||||
class Value;
|
class Value;
|
||||||
class ValueIteratorBase;
|
class ValueIteratorBase;
|
||||||
class ValueIterator;
|
class ValueIterator;
|
||||||
class ValueConstIterator;
|
class ValueConstIterator;
|
||||||
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
class ValueAllocator;
|
class ValueAllocator;
|
||||||
class ValueMapAllocator;
|
class ValueMapAllocator;
|
||||||
class ValueInternalLink;
|
class ValueInternalLink;
|
||||||
class ValueInternalArray;
|
class ValueInternalArray;
|
||||||
class ValueInternalMap;
|
class ValueInternalMap;
|
||||||
#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
|
|
||||||
#endif // JSON_FORWARDS_H_INCLUDED
|
#endif // JSON_FORWARDS_H_INCLUDED
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#ifndef JSON_JSON_H_INCLUDED
|
#ifndef JSON_JSON_H_INCLUDED
|
||||||
# define JSON_JSON_H_INCLUDED
|
# define JSON_JSON_H_INCLUDED
|
||||||
|
|
||||||
# include "autolink.h"
|
# include "autolink.h"
|
||||||
# include "value.h"
|
# include "value.h"
|
||||||
# include "reader.h"
|
# include "reader.h"
|
||||||
# include "writer.h"
|
# include "writer.h"
|
||||||
|
|
||||||
#endif // JSON_JSON_H_INCLUDED
|
#endif // JSON_JSON_H_INCLUDED
|
||||||
|
@ -1,182 +1,182 @@
|
|||||||
#ifndef CPPTL_JSON_READER_H_INCLUDED
|
#ifndef CPPTL_JSON_READER_H_INCLUDED
|
||||||
# define CPPTL_JSON_READER_H_INCLUDED
|
# define CPPTL_JSON_READER_H_INCLUDED
|
||||||
|
|
||||||
# include "forwards.h"
|
# include "forwards.h"
|
||||||
# include "value.h"
|
# include "value.h"
|
||||||
# include <deque>
|
# include <deque>
|
||||||
# include <stack>
|
# include <stack>
|
||||||
# include <string>
|
# include <string>
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
class Value;
|
class Value;
|
||||||
|
|
||||||
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a Value.
|
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a Value.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class JSON_API Reader
|
class JSON_API Reader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef char Char;
|
typedef char Char;
|
||||||
typedef const Char *Location;
|
typedef const Char *Location;
|
||||||
|
|
||||||
Reader();
|
Reader();
|
||||||
|
|
||||||
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
|
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
|
||||||
* \param document UTF-8 encoded string containing the document to read.
|
* \param document UTF-8 encoded string containing the document to read.
|
||||||
* \param root [out] Contains the root value of the document if it was
|
* \param root [out] Contains the root value of the document if it was
|
||||||
* successfully parsed.
|
* successfully parsed.
|
||||||
* \param collectComments \c true to collect comment and allow writing them back during
|
* \param collectComments \c true to collect comment and allow writing them back during
|
||||||
* serialization, \c false to discard comments.
|
* serialization, \c false to discard comments.
|
||||||
* \return \c true if the document was successfully parsed, \c false if an error occurred.
|
* \return \c true if the document was successfully parsed, \c false if an error occurred.
|
||||||
*/
|
*/
|
||||||
bool parse( const std::string &document,
|
bool parse( const std::string &document,
|
||||||
Value &root,
|
Value &root,
|
||||||
bool collectComments = true );
|
bool collectComments = true );
|
||||||
|
|
||||||
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
|
/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document.
|
||||||
* \param document UTF-8 encoded string containing the document to read.
|
* \param document UTF-8 encoded string containing the document to read.
|
||||||
* \param root [out] Contains the root value of the document if it was
|
* \param root [out] Contains the root value of the document if it was
|
||||||
* successfully parsed.
|
* successfully parsed.
|
||||||
* \param collectComments \c true to collect comment and allow writing them back during
|
* \param collectComments \c true to collect comment and allow writing them back during
|
||||||
* serialization, \c false to discard comments.
|
* serialization, \c false to discard comments.
|
||||||
* \return \c true if the document was successfully parsed, \c false if an error occurred.
|
* \return \c true if the document was successfully parsed, \c false if an error occurred.
|
||||||
*/
|
*/
|
||||||
bool parse( const char *beginDoc, const char *endDoc,
|
bool parse( const char *beginDoc, const char *endDoc,
|
||||||
Value &root,
|
Value &root,
|
||||||
bool collectComments = true );
|
bool collectComments = true );
|
||||||
|
|
||||||
/// \brief Parse from input stream.
|
/// \brief Parse from input stream.
|
||||||
/// \see Json::operator>>(std::istream&, Json::Value&).
|
/// \see Json::operator>>(std::istream&, Json::Value&).
|
||||||
bool parse( std::istream&,
|
bool parse( std::istream&,
|
||||||
Value &root,
|
Value &root,
|
||||||
bool collectComments = true );
|
bool collectComments = true );
|
||||||
|
|
||||||
/** \brief Returns a user friendly string that list errors in the parsed document.
|
/** \brief Returns a user friendly string that list errors in the parsed document.
|
||||||
* \return Formatted error message with the list of errors with their location in
|
* \return Formatted error message with the list of errors with their location in
|
||||||
* the parsed document. An empty string is returned if no error occurred
|
* the parsed document. An empty string is returned if no error occurred
|
||||||
* during parsing.
|
* during parsing.
|
||||||
*/
|
*/
|
||||||
std::string getFormatedErrorMessages() const;
|
std::string getFormatedErrorMessages() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum TokenType
|
enum TokenType
|
||||||
{
|
{
|
||||||
tokenEndOfStream = 0,
|
tokenEndOfStream = 0,
|
||||||
tokenObjectBegin,
|
tokenObjectBegin,
|
||||||
tokenObjectEnd,
|
tokenObjectEnd,
|
||||||
tokenArrayBegin,
|
tokenArrayBegin,
|
||||||
tokenArrayEnd,
|
tokenArrayEnd,
|
||||||
tokenString,
|
tokenString,
|
||||||
tokenNumber,
|
tokenNumber,
|
||||||
tokenTrue,
|
tokenTrue,
|
||||||
tokenFalse,
|
tokenFalse,
|
||||||
tokenNull,
|
tokenNull,
|
||||||
tokenArraySeparator,
|
tokenArraySeparator,
|
||||||
tokenMemberSeparator,
|
tokenMemberSeparator,
|
||||||
tokenComment,
|
tokenComment,
|
||||||
tokenError
|
tokenError
|
||||||
};
|
};
|
||||||
|
|
||||||
class Token
|
class Token
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TokenType type_;
|
TokenType type_;
|
||||||
Location start_;
|
Location start_;
|
||||||
Location end_;
|
Location end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ErrorInfo
|
class ErrorInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Token token_;
|
Token token_;
|
||||||
std::string message_;
|
std::string message_;
|
||||||
Location extra_;
|
Location extra_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::deque<ErrorInfo> Errors;
|
typedef std::deque<ErrorInfo> Errors;
|
||||||
|
|
||||||
bool expectToken( TokenType type, Token &token, const char *message );
|
bool expectToken( TokenType type, Token &token, const char *message );
|
||||||
bool readToken( Token &token );
|
bool readToken( Token &token );
|
||||||
void skipSpaces();
|
void skipSpaces();
|
||||||
bool match( Location pattern,
|
bool match( Location pattern,
|
||||||
int patternLength );
|
int patternLength );
|
||||||
bool readComment();
|
bool readComment();
|
||||||
bool readCStyleComment();
|
bool readCStyleComment();
|
||||||
bool readCppStyleComment();
|
bool readCppStyleComment();
|
||||||
bool readString();
|
bool readString();
|
||||||
void readNumber();
|
void readNumber();
|
||||||
bool readValue();
|
bool readValue();
|
||||||
bool readObject( Token &token );
|
bool readObject( Token &token );
|
||||||
bool readArray( Token &token );
|
bool readArray( Token &token );
|
||||||
bool decodeNumber( Token &token );
|
bool decodeNumber( Token &token );
|
||||||
bool decodeString( Token &token );
|
bool decodeString( Token &token );
|
||||||
bool decodeString( Token &token, std::string &decoded );
|
bool decodeString( Token &token, std::string &decoded );
|
||||||
bool decodeDouble( Token &token );
|
bool decodeDouble( Token &token );
|
||||||
bool decodeUnicodeEscapeSequence( Token &token,
|
bool decodeUnicodeEscapeSequence( Token &token,
|
||||||
Location ¤t,
|
Location ¤t,
|
||||||
Location end,
|
Location end,
|
||||||
unsigned int &unicode );
|
unsigned int &unicode );
|
||||||
bool addError( const std::string &message,
|
bool addError( const std::string &message,
|
||||||
Token &token,
|
Token &token,
|
||||||
Location extra = 0 );
|
Location extra = 0 );
|
||||||
bool recoverFromError( TokenType skipUntilToken );
|
bool recoverFromError( TokenType skipUntilToken );
|
||||||
bool addErrorAndRecover( const std::string &message,
|
bool addErrorAndRecover( const std::string &message,
|
||||||
Token &token,
|
Token &token,
|
||||||
TokenType skipUntilToken );
|
TokenType skipUntilToken );
|
||||||
void skipUntilSpace();
|
void skipUntilSpace();
|
||||||
Value ¤tValue();
|
Value ¤tValue();
|
||||||
Char getNextChar();
|
Char getNextChar();
|
||||||
void getLocationLineAndColumn( Location location,
|
void getLocationLineAndColumn( Location location,
|
||||||
int &line,
|
int &line,
|
||||||
int &column ) const;
|
int &column ) const;
|
||||||
std::string getLocationLineAndColumn( Location location ) const;
|
std::string getLocationLineAndColumn( Location location ) const;
|
||||||
void addComment( Location begin,
|
void addComment( Location begin,
|
||||||
Location end,
|
Location end,
|
||||||
CommentPlacement placement );
|
CommentPlacement placement );
|
||||||
void skipCommentTokens( Token &token );
|
void skipCommentTokens( Token &token );
|
||||||
|
|
||||||
typedef std::stack<Value *> Nodes;
|
typedef std::stack<Value *> Nodes;
|
||||||
Nodes nodes_;
|
Nodes nodes_;
|
||||||
Errors errors_;
|
Errors errors_;
|
||||||
std::string document_;
|
std::string document_;
|
||||||
Location begin_;
|
Location begin_;
|
||||||
Location end_;
|
Location end_;
|
||||||
Location current_;
|
Location current_;
|
||||||
Location lastValueEnd_;
|
Location lastValueEnd_;
|
||||||
Value *lastValue_;
|
Value *lastValue_;
|
||||||
std::string commentsBefore_;
|
std::string commentsBefore_;
|
||||||
bool collectComments_;
|
bool collectComments_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief Read from 'sin' into 'root'.
|
/** \brief Read from 'sin' into 'root'.
|
||||||
|
|
||||||
Always keep comments from the input JSON.
|
Always keep comments from the input JSON.
|
||||||
|
|
||||||
This can be used to read a file into a particular sub-object.
|
This can be used to read a file into a particular sub-object.
|
||||||
For example:
|
For example:
|
||||||
\code
|
\code
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
cin >> root["dir"]["file"];
|
cin >> root["dir"]["file"];
|
||||||
cout << root;
|
cout << root;
|
||||||
\endcode
|
\endcode
|
||||||
Result:
|
Result:
|
||||||
\verbatim
|
\verbatim
|
||||||
{
|
{
|
||||||
"dir": {
|
"dir": {
|
||||||
"file": {
|
"file": {
|
||||||
// The input stream JSON would be nested here.
|
// The input stream JSON would be nested here.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\endverbatim
|
\endverbatim
|
||||||
\throw std::exception on parse error.
|
\throw std::exception on parse error.
|
||||||
\see Json::operator<<()
|
\see Json::operator<<()
|
||||||
*/
|
*/
|
||||||
std::istream& operator>>( std::istream&, Value& );
|
std::istream& operator>>( std::istream&, Value& );
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
#endif // CPPTL_JSON_READER_H_INCLUDED
|
#endif // CPPTL_JSON_READER_H_INCLUDED
|
||||||
|
2098
include/json/value.h
2098
include/json/value.h
File diff suppressed because it is too large
Load Diff
@ -1,115 +1,115 @@
|
|||||||
#ifndef JSON_WRITER_H_INCLUDED
|
#ifndef JSON_WRITER_H_INCLUDED
|
||||||
# define JSON_WRITER_H_INCLUDED
|
# define JSON_WRITER_H_INCLUDED
|
||||||
|
|
||||||
# include "value.h"
|
# include "value.h"
|
||||||
# include <vector>
|
# include <vector>
|
||||||
# include <string>
|
# include <string>
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
class Value;
|
class Value;
|
||||||
|
|
||||||
/** \brief Abstract class for writers.
|
/** \brief Abstract class for writers.
|
||||||
*/
|
*/
|
||||||
class JSON_API Writer
|
class JSON_API Writer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Writer();
|
virtual ~Writer();
|
||||||
|
|
||||||
virtual std::string write( const Value &root ) = 0;
|
virtual std::string write( const Value &root ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format without formatting (not human friendly).
|
/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format without formatting (not human friendly).
|
||||||
*
|
*
|
||||||
* The JSON document is written in a single line. It is not intended for 'human' consumption,
|
* The JSON document is written in a single line. It is not intended for 'human' consumption,
|
||||||
* but may be usefull to support feature such as RPC where bandwith is limited.
|
* but may be usefull to support feature such as RPC where bandwith is limited.
|
||||||
* \sa Reader, Value
|
* \sa Reader, Value
|
||||||
*/
|
*/
|
||||||
class JSON_API FastWriter : public Writer
|
class JSON_API FastWriter : public Writer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FastWriter();
|
FastWriter();
|
||||||
|
|
||||||
void enableYAMLCompatibility();
|
void enableYAMLCompatibility();
|
||||||
|
|
||||||
public: // overridden from Writer
|
public: // overridden from Writer
|
||||||
virtual std::string write( const Value &root );
|
virtual std::string write( const Value &root );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue( const Value &value );
|
void writeValue( const Value &value );
|
||||||
|
|
||||||
std::string document_;
|
std::string document_;
|
||||||
bool yamlCompatiblityEnabled_;
|
bool yamlCompatiblityEnabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way.
|
/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a human friendly way.
|
||||||
*
|
*
|
||||||
* The rules for line break and indent are as follow:
|
* The rules for line break and indent are as follow:
|
||||||
* - Object value:
|
* - Object value:
|
||||||
* - if empty then print {} without indent and line break
|
* - if empty then print {} without indent and line break
|
||||||
* - if not empty the print '{', line break & indent, print one value per line
|
* - if not empty the print '{', line break & indent, print one value per line
|
||||||
* and then unindent and line break and print '}'.
|
* and then unindent and line break and print '}'.
|
||||||
* - Array value:
|
* - Array value:
|
||||||
* - if empty then print [] without indent and line break
|
* - if empty then print [] without indent and line break
|
||||||
* - if the array contains no object value, empty array or some other value types,
|
* - if the array contains no object value, empty array or some other value types,
|
||||||
* and all the values fit on one lines, then print the array on a single line.
|
* and all the values fit on one lines, then print the array on a single line.
|
||||||
* - otherwise, it the values do not fit on one line, or the array contains
|
* - otherwise, it the values do not fit on one line, or the array contains
|
||||||
* object or non empty array, then print one value per line.
|
* object or non empty array, then print one value per line.
|
||||||
*
|
*
|
||||||
* If the Value have comments then they are outputed according to their #CommentPlacement.
|
* If the Value have comments then they are outputed according to their #CommentPlacement.
|
||||||
*
|
*
|
||||||
* \sa Reader, Value, Value::setComment()
|
* \sa Reader, Value, Value::setComment()
|
||||||
*/
|
*/
|
||||||
class JSON_API StyledWriter
|
class JSON_API StyledWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StyledWriter();
|
StyledWriter();
|
||||||
virtual ~StyledWriter(){}
|
virtual ~StyledWriter(){}
|
||||||
|
|
||||||
public: // overridden from Writer
|
public: // overridden from Writer
|
||||||
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
|
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
|
||||||
* \param root Value to serialize.
|
* \param root Value to serialize.
|
||||||
* \return String containing the JSON document that represents the root value.
|
* \return String containing the JSON document that represents the root value.
|
||||||
*/
|
*/
|
||||||
virtual std::string write( const Value &root );
|
virtual std::string write( const Value &root );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeValue( const Value &value );
|
void writeValue( const Value &value );
|
||||||
void writeArrayValue( const Value &value );
|
void writeArrayValue( const Value &value );
|
||||||
bool isMultineArray( const Value &value );
|
bool isMultineArray( const Value &value );
|
||||||
void pushValue( const std::string &value );
|
void pushValue( const std::string &value );
|
||||||
void writeIndent();
|
void writeIndent();
|
||||||
void writeWithIndent( const std::string &value );
|
void writeWithIndent( const std::string &value );
|
||||||
void indent();
|
void indent();
|
||||||
void unindent();
|
void unindent();
|
||||||
void writeCommentBeforeValue( const Value &root );
|
void writeCommentBeforeValue( const Value &root );
|
||||||
void writeCommentAfterValueOnSameLine( const Value &root );
|
void writeCommentAfterValueOnSameLine( const Value &root );
|
||||||
bool hasCommentForValue( const Value &value );
|
bool hasCommentForValue( const Value &value );
|
||||||
static std::string normalizeEOL( const std::string &text );
|
static std::string normalizeEOL( const std::string &text );
|
||||||
|
|
||||||
typedef std::vector<std::string> ChildValues;
|
typedef std::vector<std::string> ChildValues;
|
||||||
|
|
||||||
ChildValues childValues_;
|
ChildValues childValues_;
|
||||||
std::string document_;
|
std::string document_;
|
||||||
std::string indentString_;
|
std::string indentString_;
|
||||||
int rightMargin_;
|
int rightMargin_;
|
||||||
int indentSize_;
|
int indentSize_;
|
||||||
bool addChildValues_;
|
bool addChildValues_;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string JSON_API valueToString( Value::Int value );
|
std::string JSON_API valueToString( Value::Int value );
|
||||||
std::string JSON_API valueToString( Value::UInt value );
|
std::string JSON_API valueToString( Value::UInt value );
|
||||||
std::string JSON_API valueToString( double value );
|
std::string JSON_API valueToString( double value );
|
||||||
std::string JSON_API valueToString( bool value );
|
std::string JSON_API valueToString( bool value );
|
||||||
std::string JSON_API valueToQuotedString( const char *value );
|
std::string JSON_API valueToQuotedString( const char *value );
|
||||||
|
|
||||||
/// \brief Output using the StyledWriter.
|
/// \brief Output using the StyledWriter.
|
||||||
/// \see Json::operator>>()
|
/// \see Json::operator>>()
|
||||||
std::ostream& operator<<( std::ostream&, const Value &root );
|
std::ostream& operator<<( std::ostream&, const Value &root );
|
||||||
|
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // JSON_WRITER_H_INCLUDED
|
#endif // JSON_WRITER_H_INCLUDED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user