Skip to content

Commit 1b5e61d

Browse files
committed
Merge pull request open-source-parsers#435 from cdunn2001/JSONCPP_STRING
JSONCPP_STRING etc.
2 parents 1b8e3b7 + b84e0c1 commit 1b5e61d

File tree

12 files changed

+86
-80
lines changed

12 files changed

+86
-80
lines changed

include/json/assertions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# define JSON_FAIL_MESSAGE(message) \
2727
{ \
28-
std::ostringstream oss; oss << message; \
28+
JSONCPP_OSTRINGSTREAM oss; oss << message; \
2929
Json::throwLogicError(oss.str()); \
3030
abort(); \
3131
}
@@ -38,7 +38,7 @@
3838
// release builds we abort, for a core-dump or debugger.
3939
# define JSON_FAIL_MESSAGE(message) \
4040
{ \
41-
std::ostringstream oss; oss << message; \
41+
JSONCPP_OSTRINGSTREAM oss; oss << message; \
4242
assert(false && oss.str().c_str()); \
4343
abort(); \
4444
}

include/json/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef JSON_CONFIG_H_INCLUDED
77
#define JSON_CONFIG_H_INCLUDED
88
#include <stddef.h>
9+
#include <string> //typdef String
910

1011
/// If defined, indicates that json library is embedded in CppTL library.
1112
//# define JSON_IN_CPPTL 1
@@ -138,6 +139,11 @@ typedef Int64 LargestInt;
138139
typedef UInt64 LargestUInt;
139140
#define JSON_HAS_INT64
140141
#endif // if defined(JSON_NO_INT64)
142+
#define JSONCPP_STRING std::string
143+
#define JSONCPP_OSTRINGSTREAM std::ostringstream
144+
#define JSONCPP_OSTREAM std::ostream
145+
#define JSONCPP_ISTRINGSTREAM std::istringstream
146+
#define JSONCPP_ISTREAM std::istream
141147
} // end namespace Json
142148

143149
#endif // JSON_CONFIG_H_INCLUDED

include/json/reader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class JSON_API Reader {
9999

100100
/// \brief Parse from input stream.
101101
/// \see Json::operator>>(std::istream&, Json::Value&).
102-
bool parse(std::istream& is, Value& root, bool collectComments = true);
102+
bool parse(JSONCPP_ISTREAM& is, Value& root, bool collectComments = true);
103103

104104
/** \brief Returns a user friendly string that list errors in the parsed
105105
* document.
@@ -366,7 +366,7 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
366366
*/
367367
bool JSON_API parseFromStream(
368368
CharReader::Factory const&,
369-
std::istream&,
369+
JSONCPP_ISTREAM&,
370370
Value* root, std::string* errs);
371371

372372
/** \brief Read from 'sin' into 'root'.
@@ -393,7 +393,7 @@ bool JSON_API parseFromStream(
393393
\throw std::exception on parse error.
394394
\see Json::operator<<()
395395
*/
396-
JSON_API std::istream& operator>>(std::istream&, Value&);
396+
JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
397397

398398
} // namespace Json
399399

include/json/value.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ namespace Json {
3939
*/
4040
class JSON_API Exception : public std::exception {
4141
public:
42-
Exception(std::string const& msg);
42+
Exception(JSONCPP_STRING const& msg);
4343
~Exception() throw() override;
4444
char const* what() const throw() override;
4545
protected:
46-
std::string msg_;
46+
JSONCPP_STRING msg_;
4747
};
4848

4949
/** Exceptions which the user cannot easily avoid.
@@ -54,7 +54,7 @@ class JSON_API Exception : public std::exception {
5454
*/
5555
class JSON_API RuntimeError : public Exception {
5656
public:
57-
RuntimeError(std::string const& msg);
57+
RuntimeError(JSONCPP_STRING const& msg);
5858
};
5959

6060
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
@@ -65,13 +65,13 @@ class JSON_API RuntimeError : public Exception {
6565
*/
6666
class JSON_API LogicError : public Exception {
6767
public:
68-
LogicError(std::string const& msg);
68+
LogicError(JSONCPP_STRING const& msg);
6969
};
7070

7171
/// used internally
72-
void throwRuntimeError(std::string const& msg);
72+
void throwRuntimeError(JSONCPP_STRING const& msg);
7373
/// used internally
74-
void throwLogicError(std::string const& msg);
74+
void throwLogicError(JSONCPP_STRING const& msg);
7575

7676
/** \brief Type of the value held by a Value object.
7777
*/
@@ -162,7 +162,7 @@ class JSON_API StaticString {
162162
class JSON_API Value {
163163
friend class ValueIteratorBase;
164164
public:
165-
typedef std::vector<std::string> Members;
165+
typedef std::vector<JSONCPP_STRING> Members;
166166
typedef ValueIterator iterator;
167167
typedef ValueConstIterator const_iterator;
168168
typedef Json::UInt UInt;
@@ -290,7 +290,7 @@ Json::Value obj_value(Json::objectValue); // {}
290290
* \endcode
291291
*/
292292
Value(const StaticString& value);
293-
Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too.
293+
Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded zeroes too.
294294
#ifdef JSON_USE_CPPTL
295295
Value(const CppTL::ConstString& value);
296296
#endif
@@ -323,7 +323,7 @@ Json::Value obj_value(Json::objectValue); // {}
323323
int compare(const Value& other) const;
324324

325325
const char* asCString() const; ///< Embedded zeroes could cause you trouble!
326-
std::string asString() const; ///< Embedded zeroes are possible.
326+
JSONCPP_STRING asString() const; ///< Embedded zeroes are possible.
327327
/** Get raw char* of string-value.
328328
* \return false if !string. (Seg-fault if str or end are NULL.)
329329
*/
@@ -427,11 +427,11 @@ Json::Value obj_value(Json::objectValue); // {}
427427
const Value& operator[](const char* key) const;
428428
/// Access an object value by name, create a null member if it does not exist.
429429
/// \param key may contain embedded nulls.
430-
Value& operator[](const std::string& key);
430+
Value& operator[](const JSONCPP_STRING& key);
431431
/// Access an object value by name, returns null if there is no member with
432432
/// that name.
433433
/// \param key may contain embedded nulls.
434-
const Value& operator[](const std::string& key) const;
434+
const Value& operator[](const JSONCPP_STRING& key) const;
435435
/** \brief Access an object value by name, create a null member if it does not
436436
exist.
437437
@@ -462,7 +462,7 @@ Json::Value obj_value(Json::objectValue); // {}
462462
/// Return the member named key if it exist, defaultValue otherwise.
463463
/// \note deep copy
464464
/// \param key may contain embedded nulls.
465-
Value get(const std::string& key, const Value& defaultValue) const;
465+
Value get(const JSONCPP_STRING& key, const Value& defaultValue) const;
466466
#ifdef JSON_USE_CPPTL
467467
/// Return the member named key if it exist, defaultValue otherwise.
468468
/// \note deep copy
@@ -487,7 +487,7 @@ Json::Value obj_value(Json::objectValue); // {}
487487
/// Same as removeMember(const char*)
488488
/// \param key may contain embedded nulls.
489489
/// \deprecated
490-
Value removeMember(const std::string& key);
490+
Value removeMember(const JSONCPP_STRING& key);
491491
/// Same as removeMember(const char* begin, const char* end, Value* removed),
492492
/// but 'key' is null-terminated.
493493
bool removeMember(const char* key, Value* removed);
@@ -497,8 +497,8 @@ Json::Value obj_value(Json::objectValue); // {}
497497
\param key may contain embedded nulls.
498498
\return true iff removed (no exceptions)
499499
*/
500-
bool removeMember(std::string const& key, Value* removed);
501-
/// Same as removeMember(std::string const& key, Value* removed)
500+
bool removeMember(JSONCPP_STRING const& key, Value* removed);
501+
/// Same as removeMember(JSONCPP_STRING const& key, Value* removed)
502502
bool removeMember(const char* begin, const char* end, Value* removed);
503503
/** \brief Remove the indexed array element.
504504
@@ -513,8 +513,8 @@ Json::Value obj_value(Json::objectValue); // {}
513513
bool isMember(const char* key) const;
514514
/// Return true if the object has a member named key.
515515
/// \param key may contain embedded nulls.
516-
bool isMember(const std::string& key) const;
517-
/// Same as isMember(std::string const& key)const
516+
bool isMember(const JSONCPP_STRING& key) const;
517+
/// Same as isMember(JSONCPP_STRING const& key)const
518518
bool isMember(const char* begin, const char* end) const;
519519
#ifdef JSON_USE_CPPTL
520520
/// Return true if the object has a member named key.
@@ -534,17 +534,17 @@ Json::Value obj_value(Json::objectValue); // {}
534534
//# endif
535535

536536
/// \deprecated Always pass len.
537-
JSONCPP_DEPRECATED("Use setComment(std::string const&) instead.")
537+
JSONCPP_DEPRECATED("Use setComment(JSONCPP_STRING const&) instead.")
538538
void setComment(const char* comment, CommentPlacement placement);
539539
/// Comments must be //... or /* ... */
540540
void setComment(const char* comment, size_t len, CommentPlacement placement);
541541
/// Comments must be //... or /* ... */
542-
void setComment(const std::string& comment, CommentPlacement placement);
542+
void setComment(const JSONCPP_STRING& comment, CommentPlacement placement);
543543
bool hasComment(CommentPlacement placement) const;
544544
/// Include delimiters and embedded newlines.
545-
std::string getComment(CommentPlacement placement) const;
545+
JSONCPP_STRING getComment(CommentPlacement placement) const;
546546

547-
std::string toStyledString() const;
547+
JSONCPP_STRING toStyledString() const;
548548

549549
const_iterator begin() const;
550550
const_iterator end() const;
@@ -612,15 +612,15 @@ class JSON_API PathArgument {
612612
PathArgument();
613613
PathArgument(ArrayIndex index);
614614
PathArgument(const char* key);
615-
PathArgument(const std::string& key);
615+
PathArgument(const JSONCPP_STRING& key);
616616

617617
private:
618618
enum Kind {
619619
kindNone = 0,
620620
kindIndex,
621621
kindKey
622622
};
623-
std::string key_;
623+
JSONCPP_STRING key_;
624624
ArrayIndex index_;
625625
Kind kind_;
626626
};
@@ -638,7 +638,7 @@ class JSON_API PathArgument {
638638
*/
639639
class JSON_API Path {
640640
public:
641-
Path(const std::string& path,
641+
Path(const JSONCPP_STRING& path,
642642
const PathArgument& a1 = PathArgument(),
643643
const PathArgument& a2 = PathArgument(),
644644
const PathArgument& a3 = PathArgument(),
@@ -655,12 +655,12 @@ class JSON_API Path {
655655
typedef std::vector<const PathArgument*> InArgs;
656656
typedef std::vector<PathArgument> Args;
657657

658-
void makePath(const std::string& path, const InArgs& in);
659-
void addPathInArg(const std::string& path,
658+
void makePath(const JSONCPP_STRING& path, const InArgs& in);
659+
void addPathInArg(const JSONCPP_STRING& path,
660660
const InArgs& in,
661661
InArgs::const_iterator& itInArg,
662662
PathArgument::Kind kind);
663-
void invalidPath(const std::string& path, int location);
663+
void invalidPath(const JSONCPP_STRING& path, int location);
664664

665665
Args args_;
666666
};
@@ -693,7 +693,7 @@ class JSON_API ValueIteratorBase {
693693
/// Return the member name of the referenced Value, or "" if it is not an
694694
/// objectValue.
695695
/// \note Avoid `c_str()` on result, as embedded zeroes are possible.
696-
std::string name() const;
696+
JSONCPP_STRING name() const;
697697

698698
/// Return the member name of the referenced Value. "" if it is not an
699699
/// objectValue.

include/json/writer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Value;
3939
*/
4040
class JSON_API StreamWriter {
4141
protected:
42-
std::ostream* sout_; // not owned; will not delete
42+
JSONCPP_OSTREAM* sout_; // not owned; will not delete
4343
public:
4444
StreamWriter();
4545
virtual ~StreamWriter();
@@ -49,7 +49,7 @@ class JSON_API StreamWriter {
4949
\return zero on success (For now, we always return zero, so check the stream instead.)
5050
\throw std::exception possibly, depending on configuration
5151
*/
52-
virtual int write(Value const& root, std::ostream* sout) = 0;
52+
virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;
5353

5454
/** \brief A simple abstract factory.
5555
*/
@@ -281,7 +281,7 @@ class JSON_API StyledStreamWriter {
281281
* \note There is no point in deriving from Writer, since write() should not
282282
* return a value.
283283
*/
284-
void write(std::ostream& out, const Value& root);
284+
void write(JSONCPP_OSTREAM& out, const Value& root);
285285

286286
private:
287287
void writeValue(const Value& value);
@@ -300,7 +300,7 @@ class JSON_API StyledStreamWriter {
300300
typedef std::vector<std::string> ChildValues;
301301

302302
ChildValues childValues_;
303-
std::ostream* document_;
303+
JSONCPP_OSTREAM* document_;
304304
std::string indentString_;
305305
unsigned int rightMargin_;
306306
std::string indentation_;
@@ -320,7 +320,7 @@ std::string JSON_API valueToQuotedString(const char* value);
320320

321321
/// \brief Output using the StyledStreamWriter.
322322
/// \see Json::operator>>()
323-
JSON_API std::ostream& operator<<(std::ostream&, const Value& root);
323+
JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
324324

325325
} // namespace Json
326326

src/jsontestrunner/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static std::string useStyledStreamWriter(
178178
Json::Value const& root)
179179
{
180180
Json::StyledStreamWriter writer;
181-
std::ostringstream sout;
181+
JSONCPP_OSTRINGSTREAM sout;
182182
writer.write(sout, root);
183183
return sout.str();
184184
}

src/lib_json/json_reader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ bool Reader::decodeDouble(Token& token) {
617617
bool Reader::decodeDouble(Token& token, Value& decoded) {
618618
double value = 0;
619619
std::string buffer(token.start_, token.end_);
620-
std::istringstream is(buffer);
620+
JSONCPP_ISTRINGSTREAM is(buffer);
621621
if (!(is >> value))
622622
return addError("'" + std::string(token.start_, token.end_) +
623623
"' is not a number.",
@@ -2007,10 +2007,10 @@ void CharReaderBuilder::setDefaults(Json::Value* settings)
20072007
// global functions
20082008

20092009
bool parseFromStream(
2010-
CharReader::Factory const& fact, std::istream& sin,
2010+
CharReader::Factory const& fact, JSONCPP_ISTREAM& sin,
20112011
Value* root, std::string* errs)
20122012
{
2013-
std::ostringstream ssin;
2013+
JSONCPP_OSTRINGSTREAM ssin;
20142014
ssin << sin.rdbuf();
20152015
std::string doc = ssin.str();
20162016
char const* begin = doc.data();
@@ -2020,7 +2020,7 @@ bool parseFromStream(
20202020
return reader->parse(begin, end, root, errs);
20212021
}
20222022

2023-
std::istream& operator>>(std::istream& sin, Value& root) {
2023+
JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) {
20242024
CharReaderBuilder b;
20252025
std::string errs;
20262026
bool ok = parseFromStream(b, sin, &root, &errs);

0 commit comments

Comments
 (0)