Merge pull request #435 from cdunn2001/JSONCPP_STRING

JSONCPP_STRING etc.
This commit is contained in:
Christopher Dunn 2016-03-06 12:43:47 -06:00
commit 1b5e61d008
12 changed files with 86 additions and 80 deletions

View File

@ -25,7 +25,7 @@
# define JSON_FAIL_MESSAGE(message) \ # define JSON_FAIL_MESSAGE(message) \
{ \ { \
std::ostringstream oss; oss << message; \ JSONCPP_OSTRINGSTREAM oss; oss << message; \
Json::throwLogicError(oss.str()); \ Json::throwLogicError(oss.str()); \
abort(); \ abort(); \
} }
@ -38,7 +38,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) \
{ \ { \
std::ostringstream oss; oss << message; \ JSONCPP_OSTRINGSTREAM oss; oss << message; \
assert(false && oss.str().c_str()); \ assert(false && oss.str().c_str()); \
abort(); \ abort(); \
} }

View File

@ -6,6 +6,7 @@
#ifndef JSON_CONFIG_H_INCLUDED #ifndef JSON_CONFIG_H_INCLUDED
#define JSON_CONFIG_H_INCLUDED #define JSON_CONFIG_H_INCLUDED
#include <stddef.h> #include <stddef.h>
#include <string> //typdef String
/// 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
@ -138,6 +139,11 @@ 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)
#define JSONCPP_STRING std::string
#define JSONCPP_OSTRINGSTREAM std::ostringstream
#define JSONCPP_OSTREAM std::ostream
#define JSONCPP_ISTRINGSTREAM std::istringstream
#define JSONCPP_ISTREAM std::istream
} // end namespace Json } // end namespace Json
#endif // JSON_CONFIG_H_INCLUDED #endif // JSON_CONFIG_H_INCLUDED

View File

@ -99,7 +99,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(std::istream& is, Value& root, bool collectComments = true); bool parse(JSONCPP_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.
@ -366,7 +366,7 @@ public:
*/ */
bool JSON_API parseFromStream( bool JSON_API parseFromStream(
CharReader::Factory const&, CharReader::Factory const&,
std::istream&, JSONCPP_ISTREAM&,
Value* root, std::string* errs); Value* root, std::string* errs);
/** \brief Read from 'sin' into 'root'. /** \brief Read from 'sin' into 'root'.
@ -393,7 +393,7 @@ bool JSON_API parseFromStream(
\throw std::exception on parse error. \throw std::exception on parse error.
\see Json::operator<<() \see Json::operator<<()
*/ */
JSON_API std::istream& operator>>(std::istream&, Value&); JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
} // namespace Json } // namespace Json

View File

@ -39,11 +39,11 @@ namespace Json {
*/ */
class JSON_API Exception : public std::exception { class JSON_API Exception : public std::exception {
public: public:
Exception(std::string const& msg); Exception(JSONCPP_STRING const& msg);
~Exception() throw() override; ~Exception() throw() override;
char const* what() const throw() override; char const* what() const throw() override;
protected: protected:
std::string msg_; JSONCPP_STRING msg_;
}; };
/** Exceptions which the user cannot easily avoid. /** Exceptions which the user cannot easily avoid.
@ -54,7 +54,7 @@ protected:
*/ */
class JSON_API RuntimeError : public Exception { class JSON_API RuntimeError : public Exception {
public: public:
RuntimeError(std::string const& msg); RuntimeError(JSONCPP_STRING const& msg);
}; };
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
@ -65,13 +65,13 @@ public:
*/ */
class JSON_API LogicError : public Exception { class JSON_API LogicError : public Exception {
public: public:
LogicError(std::string const& msg); LogicError(JSONCPP_STRING const& msg);
}; };
/// used internally /// used internally
void throwRuntimeError(std::string const& msg); void throwRuntimeError(JSONCPP_STRING const& msg);
/// used internally /// used internally
void throwLogicError(std::string const& msg); void throwLogicError(JSONCPP_STRING const& msg);
/** \brief Type of the value held by a Value object. /** \brief Type of the value held by a Value object.
*/ */
@ -162,7 +162,7 @@ private:
class JSON_API Value { class JSON_API Value {
friend class ValueIteratorBase; friend class ValueIteratorBase;
public: public:
typedef std::vector<std::string> Members; typedef std::vector<JSONCPP_STRING> Members;
typedef ValueIterator iterator; typedef ValueIterator iterator;
typedef ValueConstIterator const_iterator; typedef ValueConstIterator const_iterator;
typedef Json::UInt UInt; typedef Json::UInt UInt;
@ -290,7 +290,7 @@ Json::Value obj_value(Json::objectValue); // {}
* \endcode * \endcode
*/ */
Value(const StaticString& value); Value(const StaticString& value);
Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too. Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded zeroes too.
#ifdef JSON_USE_CPPTL #ifdef JSON_USE_CPPTL
Value(const CppTL::ConstString& value); Value(const CppTL::ConstString& value);
#endif #endif
@ -323,7 +323,7 @@ Json::Value obj_value(Json::objectValue); // {}
int compare(const Value& other) const; int compare(const Value& other) const;
const char* asCString() const; ///< Embedded zeroes could cause you trouble! const char* asCString() const; ///< Embedded zeroes could cause you trouble!
std::string asString() const; ///< Embedded zeroes are possible. JSONCPP_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.)
*/ */
@ -427,11 +427,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 std::string& key); Value& operator[](const JSONCPP_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 std::string& key) const; const Value& operator[](const JSONCPP_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.
@ -462,7 +462,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 std::string& key, const Value& defaultValue) const; Value get(const JSONCPP_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
@ -487,7 +487,7 @@ Json::Value obj_value(Json::objectValue); // {}
/// Same as removeMember(const char*) /// Same as removeMember(const char*)
/// \param key may contain embedded nulls. /// \param key may contain embedded nulls.
/// \deprecated /// \deprecated
Value removeMember(const std::string& key); Value removeMember(const JSONCPP_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);
@ -497,8 +497,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(std::string const& key, Value* removed); bool removeMember(JSONCPP_STRING const& key, Value* removed);
/// Same as removeMember(std::string const& key, Value* removed) /// Same as removeMember(JSONCPP_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.
@ -513,8 +513,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 std::string& key) const; bool isMember(const JSONCPP_STRING& key) const;
/// Same as isMember(std::string const& key)const /// Same as isMember(JSONCPP_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.
@ -534,17 +534,17 @@ Json::Value obj_value(Json::objectValue); // {}
//# endif //# endif
/// \deprecated Always pass len. /// \deprecated Always pass len.
JSONCPP_DEPRECATED("Use setComment(std::string const&) instead.") JSONCPP_DEPRECATED("Use setComment(JSONCPP_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 std::string& comment, CommentPlacement placement); void setComment(const JSONCPP_STRING& comment, CommentPlacement placement);
bool hasComment(CommentPlacement placement) const; bool hasComment(CommentPlacement placement) const;
/// Include delimiters and embedded newlines. /// Include delimiters and embedded newlines.
std::string getComment(CommentPlacement placement) const; JSONCPP_STRING getComment(CommentPlacement placement) const;
std::string toStyledString() const; JSONCPP_STRING toStyledString() const;
const_iterator begin() const; const_iterator begin() const;
const_iterator end() const; const_iterator end() const;
@ -612,7 +612,7 @@ public:
PathArgument(); PathArgument();
PathArgument(ArrayIndex index); PathArgument(ArrayIndex index);
PathArgument(const char* key); PathArgument(const char* key);
PathArgument(const std::string& key); PathArgument(const JSONCPP_STRING& key);
private: private:
enum Kind { enum Kind {
@ -620,7 +620,7 @@ private:
kindIndex, kindIndex,
kindKey kindKey
}; };
std::string key_; JSONCPP_STRING key_;
ArrayIndex index_; ArrayIndex index_;
Kind kind_; Kind kind_;
}; };
@ -638,7 +638,7 @@ private:
*/ */
class JSON_API Path { class JSON_API Path {
public: public:
Path(const std::string& path, Path(const JSONCPP_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(),
@ -655,12 +655,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 std::string& path, const InArgs& in); void makePath(const JSONCPP_STRING& path, const InArgs& in);
void addPathInArg(const std::string& path, void addPathInArg(const JSONCPP_STRING& path,
const InArgs& in, const InArgs& in,
InArgs::const_iterator& itInArg, InArgs::const_iterator& itInArg,
PathArgument::Kind kind); PathArgument::Kind kind);
void invalidPath(const std::string& path, int location); void invalidPath(const JSONCPP_STRING& path, int location);
Args args_; Args args_;
}; };
@ -693,7 +693,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.
std::string name() const; JSONCPP_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.

View File

@ -39,7 +39,7 @@ Usage:
*/ */
class JSON_API StreamWriter { class JSON_API StreamWriter {
protected: protected:
std::ostream* sout_; // not owned; will not delete JSONCPP_OSTREAM* sout_; // not owned; will not delete
public: public:
StreamWriter(); StreamWriter();
virtual ~StreamWriter(); virtual ~StreamWriter();
@ -49,7 +49,7 @@ public:
\return zero on success (For now, we always return zero, so check the stream instead.) \return zero on success (For now, we always return zero, so check the stream instead.)
\throw std::exception possibly, depending on configuration \throw std::exception possibly, depending on configuration
*/ */
virtual int write(Value const& root, std::ostream* sout) = 0; virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;
/** \brief A simple abstract factory. /** \brief A simple abstract factory.
*/ */
@ -281,7 +281,7 @@ public:
* \note There is no point in deriving from Writer, since write() should not * \note There is no point in deriving from Writer, since write() should not
* return a value. * return a value.
*/ */
void write(std::ostream& out, const Value& root); void write(JSONCPP_OSTREAM& out, const Value& root);
private: private:
void writeValue(const Value& value); void writeValue(const Value& value);
@ -300,7 +300,7 @@ private:
typedef std::vector<std::string> ChildValues; typedef std::vector<std::string> ChildValues;
ChildValues childValues_; ChildValues childValues_;
std::ostream* document_; JSONCPP_OSTREAM* document_;
std::string indentString_; std::string indentString_;
unsigned int rightMargin_; unsigned int rightMargin_;
std::string indentation_; std::string indentation_;
@ -320,7 +320,7 @@ std::string JSON_API valueToQuotedString(const char* value);
/// \brief Output using the StyledStreamWriter. /// \brief Output using the StyledStreamWriter.
/// \see Json::operator>>() /// \see Json::operator>>()
JSON_API std::ostream& operator<<(std::ostream&, const Value& root); JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
} // namespace Json } // namespace Json

View File

@ -178,7 +178,7 @@ static std::string useStyledStreamWriter(
Json::Value const& root) Json::Value const& root)
{ {
Json::StyledStreamWriter writer; Json::StyledStreamWriter writer;
std::ostringstream sout; JSONCPP_OSTRINGSTREAM sout;
writer.write(sout, root); writer.write(sout, root);
return sout.str(); return sout.str();
} }

View File

@ -617,7 +617,7 @@ 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;
std::string buffer(token.start_, token.end_); std::string buffer(token.start_, token.end_);
std::istringstream is(buffer); JSONCPP_ISTRINGSTREAM is(buffer);
if (!(is >> value)) if (!(is >> value))
return addError("'" + std::string(token.start_, token.end_) + return addError("'" + std::string(token.start_, token.end_) +
"' is not a number.", "' is not a number.",
@ -2007,10 +2007,10 @@ void CharReaderBuilder::setDefaults(Json::Value* settings)
// global functions // global functions
bool parseFromStream( bool parseFromStream(
CharReader::Factory const& fact, std::istream& sin, CharReader::Factory const& fact, JSONCPP_ISTREAM& sin,
Value* root, std::string* errs) Value* root, std::string* errs)
{ {
std::ostringstream ssin; JSONCPP_OSTRINGSTREAM ssin;
ssin << sin.rdbuf(); ssin << sin.rdbuf();
std::string doc = ssin.str(); std::string doc = ssin.str();
char const* begin = doc.data(); char const* begin = doc.data();
@ -2020,7 +2020,7 @@ bool parseFromStream(
return reader->parse(begin, end, root, errs); return reader->parse(begin, end, root, errs);
} }
std::istream& operator>>(std::istream& sin, Value& root) { JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) {
CharReaderBuilder b; CharReaderBuilder b;
std::string errs; std::string errs;
bool ok = parseFromStream(b, sin, &root, &errs); bool ok = parseFromStream(b, sin, &root, &errs);

View File

@ -155,7 +155,7 @@ static inline void releaseStringValue(char* value) { free(value); }
namespace Json { namespace Json {
Exception::Exception(std::string const& msg) Exception::Exception(JSONCPP_STRING const& msg)
: msg_(msg) : msg_(msg)
{} {}
Exception::~Exception() throw() Exception::~Exception() throw()
@ -164,17 +164,17 @@ char const* Exception::what() const throw()
{ {
return msg_.c_str(); return msg_.c_str();
} }
RuntimeError::RuntimeError(std::string const& msg) RuntimeError::RuntimeError(JSONCPP_STRING const& msg)
: Exception(msg) : Exception(msg)
{} {}
LogicError::LogicError(std::string const& msg) LogicError::LogicError(JSONCPP_STRING const& msg)
: Exception(msg) : Exception(msg)
{} {}
void throwRuntimeError(std::string const& msg) void throwRuntimeError(JSONCPP_STRING const& msg)
{ {
throw RuntimeError(msg); throw RuntimeError(msg);
} }
void throwLogicError(std::string const& msg) void throwLogicError(JSONCPP_STRING const& msg)
{ {
throw LogicError(msg); throw LogicError(msg);
} }
@ -368,7 +368,7 @@ Value::Value(const char* beginValue, const char* endValue) {
duplicateAndPrefixStringValue(beginValue, static_cast<unsigned>(endValue - beginValue)); duplicateAndPrefixStringValue(beginValue, static_cast<unsigned>(endValue - beginValue));
} }
Value::Value(const std::string& value) { Value::Value(const JSONCPP_STRING& value) {
initBasic(stringValue, true); initBasic(stringValue, true);
value_.string_ = value_.string_ =
duplicateAndPrefixStringValue(value.data(), static_cast<unsigned>(value.length())); duplicateAndPrefixStringValue(value.data(), static_cast<unsigned>(value.length()));
@ -618,7 +618,7 @@ bool Value::getString(char const** str, char const** cend) const {
return true; return true;
} }
std::string Value::asString() const { JSONCPP_STRING Value::asString() const {
switch (type_) { switch (type_) {
case nullValue: case nullValue:
return ""; return "";
@ -628,7 +628,7 @@ std::string Value::asString() const {
unsigned this_len; unsigned this_len;
char const* this_str; char const* this_str;
decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str); decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
return std::string(this_str, this_len); return JSONCPP_STRING(this_str, this_len);
} }
case booleanValue: case booleanValue:
return value_.bool_ ? "true" : "false"; return value_.bool_ ? "true" : "false";
@ -1038,7 +1038,7 @@ const Value& Value::operator[](const char* key) const
if (!found) return nullRef; if (!found) return nullRef;
return *found; return *found;
} }
Value const& Value::operator[](std::string const& key) const Value const& Value::operator[](JSONCPP_STRING const& key) const
{ {
Value const* found = find(key.data(), key.data() + key.length()); Value const* found = find(key.data(), key.data() + key.length());
if (!found) return nullRef; if (!found) return nullRef;
@ -1049,7 +1049,7 @@ Value& Value::operator[](const char* key) {
return resolveReference(key, key + strlen(key)); return resolveReference(key, key + strlen(key));
} }
Value& Value::operator[](const std::string& key) { Value& Value::operator[](const JSONCPP_STRING& key) {
return resolveReference(key.data(), key.data() + key.length()); return resolveReference(key.data(), key.data() + key.length());
} }
@ -1080,7 +1080,7 @@ 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(std::string const& key, Value const& defaultValue) const Value Value::get(JSONCPP_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);
} }
@ -1103,7 +1103,7 @@ 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(std::string const& key, Value* removed) bool Value::removeMember(JSONCPP_STRING const& key, Value* removed)
{ {
return removeMember(key.data(), key.data() + key.length(), removed); return removeMember(key.data(), key.data() + key.length(), removed);
} }
@ -1118,7 +1118,7 @@ Value Value::removeMember(const char* key)
removeMember(key, key + strlen(key), &removed); removeMember(key, key + strlen(key), &removed);
return removed; // still null if removeMember() did nothing return removed; // still null if removeMember() did nothing
} }
Value Value::removeMember(const std::string& key) Value Value::removeMember(const JSONCPP_STRING& key)
{ {
return removeMember(key.c_str()); return removeMember(key.c_str());
} }
@ -1162,7 +1162,7 @@ bool Value::isMember(char const* key) const
{ {
return isMember(key, key + strlen(key)); return isMember(key, key + strlen(key));
} }
bool Value::isMember(std::string const& key) const bool Value::isMember(JSONCPP_STRING const& key) const
{ {
return isMember(key.data(), key.data() + key.length()); return isMember(key.data(), key.data() + key.length());
} }
@ -1184,7 +1184,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(std::string((*it).first.data(), members.push_back(JSONCPP_STRING((*it).first.data(),
(*it).first.length())); (*it).first.length()));
} }
return members; return members;
@ -1326,7 +1326,7 @@ void Value::setComment(const char* comment, CommentPlacement placement) {
setComment(comment, strlen(comment), placement); setComment(comment, strlen(comment), placement);
} }
void Value::setComment(const std::string& comment, CommentPlacement placement) { void Value::setComment(const JSONCPP_STRING& comment, CommentPlacement placement) {
setComment(comment.c_str(), comment.length(), placement); setComment(comment.c_str(), comment.length(), placement);
} }
@ -1334,7 +1334,7 @@ bool Value::hasComment(CommentPlacement placement) const {
return comments_ != 0 && comments_[placement].comment_ != 0; return comments_ != 0 && comments_[placement].comment_ != 0;
} }
std::string Value::getComment(CommentPlacement placement) const { JSONCPP_STRING Value::getComment(CommentPlacement placement) const {
if (hasComment(placement)) if (hasComment(placement))
return comments_[placement].comment_; return comments_[placement].comment_;
return ""; return "";
@ -1348,7 +1348,7 @@ ptrdiff_t Value::getOffsetStart() const { return start_; }
ptrdiff_t Value::getOffsetLimit() const { return limit_; } ptrdiff_t Value::getOffsetLimit() const { return limit_; }
std::string Value::toStyledString() const { JSONCPP_STRING Value::toStyledString() const {
StyledWriter writer; StyledWriter writer;
return writer.write(*this); return writer.write(*this);
} }
@ -1416,13 +1416,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 std::string& key) PathArgument::PathArgument(const JSONCPP_STRING& key)
: key_(key.c_str()), index_(), kind_(kindKey) {} : key_(key.c_str()), index_(), kind_(kindKey) {}
// class Path // class Path
// ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////
Path::Path(const std::string& path, Path::Path(const JSONCPP_STRING& path,
const PathArgument& a1, const PathArgument& a1,
const PathArgument& a2, const PathArgument& a2,
const PathArgument& a3, const PathArgument& a3,
@ -1437,7 +1437,7 @@ Path::Path(const std::string& path,
makePath(path, in); makePath(path, in);
} }
void Path::makePath(const std::string& path, const InArgs& in) { void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
const char* current = path.c_str(); const char* current = path.c_str();
const char* end = current + path.length(); const char* end = current + path.length();
InArgs::const_iterator itInArg = in.begin(); InArgs::const_iterator itInArg = in.begin();
@ -1463,12 +1463,12 @@ void Path::makePath(const std::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(std::string(beginName, current)); args_.push_back(JSONCPP_STRING(beginName, current));
} }
} }
} }
void Path::addPathInArg(const std::string& /*path*/, void Path::addPathInArg(const JSONCPP_STRING& /*path*/,
const InArgs& in, const InArgs& in,
InArgs::const_iterator& itInArg, InArgs::const_iterator& itInArg,
PathArgument::Kind kind) { PathArgument::Kind kind) {
@ -1481,7 +1481,7 @@ void Path::addPathInArg(const std::string& /*path*/,
} }
} }
void Path::invalidPath(const std::string& /*path*/, int /*location*/) { void Path::invalidPath(const JSONCPP_STRING& /*path*/, int /*location*/) {
// Error: invalid path. // Error: invalid path.
} }

View File

@ -92,12 +92,12 @@ UInt ValueIteratorBase::index() const {
return Value::UInt(-1); return Value::UInt(-1);
} }
std::string ValueIteratorBase::name() const { JSONCPP_STRING ValueIteratorBase::name() const {
char const* keey; char const* keey;
char const* end; char const* end;
keey = memberName(&end); keey = memberName(&end);
if (!keey) return std::string(); if (!keey) return JSONCPP_STRING();
return std::string(keey, end); return JSONCPP_STRING(keey, end);
} }
char const* ValueIteratorBase::memberName() const { char const* ValueIteratorBase::memberName() const {

View File

@ -217,7 +217,7 @@ std::string valueToQuotedString(const char* value) {
// sequence from occurring. // sequence from occurring.
default: default:
if (isControlCharacter(*c)) { if (isControlCharacter(*c)) {
std::ostringstream oss; JSONCPP_OSTRINGSTREAM oss;
oss << "\\u" << std::hex << std::uppercase << std::setfill('0') oss << "\\u" << std::hex << std::uppercase << std::setfill('0')
<< std::setw(4) << static_cast<int>(*c); << std::setw(4) << static_cast<int>(*c);
result += oss.str(); result += oss.str();
@ -295,7 +295,7 @@ static std::string valueToQuotedStringN(const char* value, unsigned length) {
// sequence from occurring. // sequence from occurring.
default: default:
if ((isControlCharacter(*c)) || (*c == 0)) { if ((isControlCharacter(*c)) || (*c == 0)) {
std::ostringstream oss; JSONCPP_OSTRINGSTREAM oss;
oss << "\\u" << std::hex << std::uppercase << std::setfill('0') oss << "\\u" << std::hex << std::uppercase << std::setfill('0')
<< std::setw(4) << static_cast<int>(*c); << std::setw(4) << static_cast<int>(*c);
result += oss.str(); result += oss.str();
@ -608,7 +608,7 @@ StyledStreamWriter::StyledStreamWriter(std::string indentation)
: document_(NULL), rightMargin_(74), indentation_(indentation), : document_(NULL), rightMargin_(74), indentation_(indentation),
addChildValues_() {} addChildValues_() {}
void StyledStreamWriter::write(std::ostream& out, const Value& root) { void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
document_ = &out; document_ = &out;
addChildValues_ = false; addChildValues_ = false;
indentString_ = ""; indentString_ = "";
@ -839,7 +839,7 @@ struct BuiltStyledStreamWriter : public StreamWriter
std::string const& endingLineFeedSymbol, std::string const& endingLineFeedSymbol,
bool useSpecialFloats, bool useSpecialFloats,
unsigned int precision); unsigned int precision);
int write(Value const& root, std::ostream* sout) override; int write(Value const& root, JSONCPP_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);
@ -888,7 +888,7 @@ BuiltStyledStreamWriter::BuiltStyledStreamWriter(
, precision_(precision) , precision_(precision)
{ {
} }
int BuiltStyledStreamWriter::write(Value const& root, std::ostream* sout) int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout)
{ {
sout_ = sout; sout_ = sout;
addChildValues_ = false; addChildValues_ = false;
@ -1200,13 +1200,13 @@ void StreamWriterBuilder::setDefaults(Json::Value* settings)
} }
std::string writeString(StreamWriter::Factory const& builder, Value const& root) { std::string writeString(StreamWriter::Factory const& builder, Value const& root) {
std::ostringstream sout; JSONCPP_OSTRINGSTREAM sout;
StreamWriterPtr const writer(builder.newStreamWriter()); StreamWriterPtr const writer(builder.newStreamWriter());
writer->write(root, &sout); writer->write(root, &sout);
return sout.str(); return sout.str();
} }
std::ostream& operator<<(std::ostream& sout, Value const& root) { JSONCPP_OSTREAM& operator<<(JSONCPP_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);

View File

@ -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) {
std::ostringstream oss; JSONCPP_OSTRINGSTREAM oss;
oss.precision(16); oss.precision(16);
oss.setf(std::ios_base::floatfield); oss.setf(std::ios_base::floatfield);
oss << value; oss << value;

View File

@ -2480,13 +2480,13 @@ JSONTEST_FIXTURE(IteratorTest, const) {
for(int i = 9; i < 12; ++i) for(int i = 9; i < 12; ++i)
{ {
std::ostringstream out; JSONCPP_OSTRINGSTREAM out;
out << std::setw(2) << i; out << std::setw(2) << i;
std::string str = out.str(); std::string str = out.str();
value[str] = str; value[str] = str;
} }
std::ostringstream out; JSONCPP_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)