@@ -104,8 +104,6 @@ extern "C" {
104
104
} while (0 )
105
105
#endif
106
106
107
-
108
-
109
107
#ifdef _MSC_VER
110
108
#define SNPRINTF _snprintf_s
111
109
#pragma warning(push)
@@ -119,14 +117,6 @@ extern "C" {
119
117
120
118
namespace picojson {
121
119
122
- // string_view
123
- #if __cplusplus >= 201703L
124
- #include < string_view>
125
- using string_view = std::string_view;
126
- #else
127
- using string_view = const std::string &;
128
- #endif
129
-
130
120
enum {
131
121
null_type,
132
122
boolean_type,
@@ -147,13 +137,7 @@ struct null {};
147
137
class value {
148
138
public:
149
139
typedef std::vector<value> array;
150
- typedef std::map<std::string, value
151
- #if __cplusplus >= 201703L
152
- // allow map to use transparent type for comparisons
153
- ,
154
- std::less<>
155
- #endif
156
- > object;
140
+ typedef std::map<std::string, value> object;
157
141
union _storage {
158
142
bool boolean_;
159
143
double number_;
@@ -177,7 +161,7 @@ class value {
177
161
explicit value (int64_t i);
178
162
#endif
179
163
explicit value (double n);
180
- explicit value (string_view s);
164
+ explicit value (const std::string & s);
181
165
explicit value (const array &a);
182
166
explicit value (const object &o);
183
167
#if PICOJSON_USE_RVALUE_REFERENCE
@@ -204,12 +188,12 @@ class value {
204
188
#endif
205
189
bool evaluate_as_boolean () const ;
206
190
const value &get (const size_t idx) const ;
207
- const value &get (string_view key) const ;
191
+ const value &get (const std::string & key) const ;
208
192
value &get (const size_t idx);
209
- value &get (string_view key);
193
+ value &get (const std::string & key);
210
194
211
195
bool contains (const size_t idx) const ;
212
- bool contains (string_view key) const ;
196
+ bool contains (const std::string & key) const ;
213
197
std::string to_str () const ;
214
198
template <typename Iter> void serialize (Iter os, bool prettify = false ) const ;
215
199
std::string serialize (bool prettify = false ) const ;
@@ -225,7 +209,8 @@ class value {
225
209
typedef value::array array;
226
210
typedef value::object object;
227
211
228
- inline value::value () : type_(null_type), u_() {}
212
+ inline value::value () : type_(null_type), u_() {
213
+ }
229
214
230
215
inline value::value (int type, bool ) : type_(type), u_() {
231
216
switch (type) {
@@ -272,7 +257,7 @@ inline value::value(double n) : type_(number_type), u_() {
272
257
u_.number_ = n;
273
258
}
274
259
275
- inline value::value (string_view s) : type_(string_type), u_() {
260
+ inline value::value (const std::string & s) : type_(string_type), u_() {
276
261
u_.string_ = new std::string (s);
277
262
}
278
263
@@ -467,14 +452,14 @@ inline value &value::get(const size_t idx) {
467
452
return idx < u_.array_ ->size () ? (*u_.array_ )[idx] : s_null;
468
453
}
469
454
470
- inline const value &value::get (string_view key) const {
455
+ inline const value &value::get (const std::string & key) const {
471
456
static value s_null;
472
457
PICOJSON_ASSERT (is<object>());
473
458
object::const_iterator i = u_.object_ ->find (key);
474
459
return i != u_.object_ ->end () ? i->second : s_null;
475
460
}
476
461
477
- inline value &value::get (string_view key) {
462
+ inline value &value::get (const std::string & key) {
478
463
static value s_null;
479
464
PICOJSON_ASSERT (is<object>());
480
465
object::iterator i = u_.object_ ->find (key);
@@ -486,7 +471,7 @@ inline bool value::contains(const size_t idx) const {
486
471
return idx < u_.array_ ->size ();
487
472
}
488
473
489
- inline bool value::contains (string_view key) const {
474
+ inline bool value::contains (const std::string & key) const {
490
475
PICOJSON_ASSERT (is<object>());
491
476
object::const_iterator i = u_.object_ ->find (key);
492
477
return i != u_.object_ ->end ();
@@ -537,7 +522,7 @@ inline std::string value::to_str() const {
537
522
return std::string ();
538
523
}
539
524
540
- template <typename Iter> void copy (string_view s, Iter oi) {
525
+ template <typename Iter> void copy (const std::string & s, Iter oi) {
541
526
std::copy (s.begin (), s.end (), oi);
542
527
}
543
528
@@ -571,7 +556,7 @@ template <typename Iter> struct serialize_str_char {
571
556
}
572
557
};
573
558
574
- template <typename Iter> void serialize_str (string_view s, Iter oi) {
559
+ template <typename Iter> void serialize_str (const std::string & s, Iter oi) {
575
560
*oi++ = ' "' ;
576
561
serialize_str_char<Iter> process_char = {oi};
577
562
std::for_each (s.begin (), s.end (), process_char);
@@ -718,8 +703,8 @@ template <typename Iter> class input {
718
703
}
719
704
return true ;
720
705
}
721
- bool match (string_view pattern) {
722
- for (auto pi (pattern.begin ()); pi != pattern.end (); ++pi) {
706
+ bool match (const std::string & pattern) {
707
+ for (std::string::const_iterator pi (pattern.begin ()); pi != pattern.end (); ++pi) {
723
708
if (getc () != *pi) {
724
709
ungetc ();
725
710
return false ;
@@ -1139,7 +1124,7 @@ template <typename Iter> inline Iter parse(value &out, const Iter &first, const
1139
1124
return _parse (ctx, first, last, err);
1140
1125
}
1141
1126
1142
- inline std::string parse (value &out, string_view s) {
1127
+ inline std::string parse (value &out, const std::string & s) {
1143
1128
std::string err;
1144
1129
parse (out, s.begin (), s.end (), &err);
1145
1130
return err;
@@ -1154,7 +1139,7 @@ inline std::string parse(value &out, std::istream &is) {
1154
1139
template <typename T> struct last_error_t { static std::string s; };
1155
1140
template <typename T> std::string last_error_t <T>::s;
1156
1141
1157
- inline void set_last_error (string_view s) {
1142
+ inline void set_last_error (const std::string & s) {
1158
1143
last_error_t <bool >::s = s;
1159
1144
}
1160
1145
0 commit comments