Skip to content

Commit de5b792

Browse files
committed
JSONCPP_STRING
1 parent 1b8e3b7 commit de5b792

File tree

4 files changed

+61
-55
lines changed

4 files changed

+61
-55
lines changed

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/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.

0 commit comments

Comments
 (0)