@@ -181,6 +181,12 @@ class JSON_API Value {
181
181
typedef Json::LargestInt LargestInt;
182
182
typedef Json::LargestUInt LargestUInt;
183
183
typedef Json::ArrayIndex ArrayIndex;
184
+ typedef std::vector<char , _Alloc> StringData;
185
+ #if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
186
+ typedef std::unique_ptr<StringData> StringDataPtr;
187
+ #else
188
+ typedef std::auto_ptr<StringData> StringDataPtr;
189
+ #endif
184
190
185
191
static const Value& null; // /< We regret this reference to a global instance; prefer the simpler Value().
186
192
static const Value& nullRef; // /< just a kludge for binary-compatibility; same as null
@@ -209,6 +215,23 @@ class JSON_API Value {
209
215
210
216
private:
211
217
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
218
+ class StringValueHolder {
219
+ public:
220
+ StringValueHolder ();
221
+ StringValueHolder (StringDataPtr&& value);
222
+ StringValueHolder (char * value);
223
+ ~StringValueHolder ();
224
+ char * GetString ();
225
+ const char * GetString () const ;
226
+ void SetString (StringDataPtr&& value);
227
+ void SetString (char * value);
228
+ bool IsRaw () const ;
229
+
230
+ private:
231
+ char * valueStringRaw_ = nullptr ; // the value that was passed in, this does not belong to value
232
+ StringDataPtr valueStringCopy_; // a copy of the value that was passed in
233
+ bool raw_ = true ;
234
+ };
212
235
class CZString {
213
236
public:
214
237
enum DuplicationPolicy {
@@ -240,7 +263,7 @@ class JSON_API Value {
240
263
unsigned length_: 30 ; // 1GB max
241
264
};
242
265
243
- char const * cstr_; // actually, a prefixed string, unless policy is noDup
266
+ StringValueHolder cstr_; // The string that's being stored
244
267
union {
245
268
ArrayIndex index_;
246
269
StringStorage storage_;
@@ -578,7 +601,7 @@ Json::Value obj_value(Json::objectValue); // {}
578
601
579
602
void setComment (const char * text, size_t len);
580
603
581
- char * comment_;
604
+ StringValueHolder comment_;
582
605
};
583
606
584
607
// struct MemberNamesTransform
@@ -595,9 +618,9 @@ Json::Value obj_value(Json::objectValue); // {}
595
618
LargestUInt uint_;
596
619
double real_;
597
620
bool bool_;
598
- char * string_; // actually ptr to unsigned, followed by str, unless !allocated_
599
621
ObjectValues* map_;
600
622
} value_;
623
+ StringValueHolder stringValue_;
601
624
ValueType type_ : 8 ;
602
625
unsigned int allocated_ : 1 ; // Notes: if declared as bool, bitfield is useless.
603
626
// If not allocated_, string_ must be null-terminated.
0 commit comments