@@ -104,8 +104,6 @@ extern "C" {
104104 } while (0 )
105105#endif
106106
107-
108-
109107#ifdef _MSC_VER
110108#define SNPRINTF _snprintf_s
111109#pragma warning(push)
@@ -119,14 +117,6 @@ extern "C" {
119117
120118namespace picojson {
121119
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-
130120enum {
131121 null_type,
132122 boolean_type,
@@ -147,13 +137,7 @@ struct null {};
147137class value {
148138public:
149139 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;
157141 union _storage {
158142 bool boolean_;
159143 double number_;
@@ -177,7 +161,7 @@ class value {
177161 explicit value (int64_t i);
178162#endif
179163 explicit value (double n);
180- explicit value (string_view s);
164+ explicit value (const std::string & s);
181165 explicit value (const array &a);
182166 explicit value (const object &o);
183167#if PICOJSON_USE_RVALUE_REFERENCE
@@ -204,12 +188,12 @@ class value {
204188#endif
205189 bool evaluate_as_boolean () const ;
206190 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 ;
208192 value &get (const size_t idx);
209- value &get (string_view key);
193+ value &get (const std::string & key);
210194
211195 bool contains (const size_t idx) const ;
212- bool contains (string_view key) const ;
196+ bool contains (const std::string & key) const ;
213197 std::string to_str () const ;
214198 template <typename Iter> void serialize (Iter os, bool prettify = false ) const ;
215199 std::string serialize (bool prettify = false ) const ;
@@ -225,7 +209,8 @@ class value {
225209typedef value::array array;
226210typedef value::object object;
227211
228- inline value::value () : type_(null_type), u_() {}
212+ inline value::value () : type_(null_type), u_() {
213+ }
229214
230215inline value::value (int type, bool ) : type_(type), u_() {
231216 switch (type) {
@@ -272,7 +257,7 @@ inline value::value(double n) : type_(number_type), u_() {
272257 u_.number_ = n;
273258}
274259
275- inline value::value (string_view s) : type_(string_type), u_() {
260+ inline value::value (const std::string & s) : type_(string_type), u_() {
276261 u_.string_ = new std::string (s);
277262}
278263
@@ -467,14 +452,14 @@ inline value &value::get(const size_t idx) {
467452 return idx < u_.array_ ->size () ? (*u_.array_ )[idx] : s_null;
468453}
469454
470- inline const value &value::get (string_view key) const {
455+ inline const value &value::get (const std::string & key) const {
471456 static value s_null;
472457 PICOJSON_ASSERT (is<object>());
473458 object::const_iterator i = u_.object_ ->find (key);
474459 return i != u_.object_ ->end () ? i->second : s_null;
475460}
476461
477- inline value &value::get (string_view key) {
462+ inline value &value::get (const std::string & key) {
478463 static value s_null;
479464 PICOJSON_ASSERT (is<object>());
480465 object::iterator i = u_.object_ ->find (key);
@@ -486,7 +471,7 @@ inline bool value::contains(const size_t idx) const {
486471 return idx < u_.array_ ->size ();
487472}
488473
489- inline bool value::contains (string_view key) const {
474+ inline bool value::contains (const std::string & key) const {
490475 PICOJSON_ASSERT (is<object>());
491476 object::const_iterator i = u_.object_ ->find (key);
492477 return i != u_.object_ ->end ();
@@ -537,7 +522,7 @@ inline std::string value::to_str() const {
537522 return std::string ();
538523}
539524
540- template <typename Iter> void copy (string_view s, Iter oi) {
525+ template <typename Iter> void copy (const std::string & s, Iter oi) {
541526 std::copy (s.begin (), s.end (), oi);
542527}
543528
@@ -571,7 +556,7 @@ template <typename Iter> struct serialize_str_char {
571556 }
572557};
573558
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) {
575560 *oi++ = ' "' ;
576561 serialize_str_char<Iter> process_char = {oi};
577562 std::for_each (s.begin (), s.end (), process_char);
@@ -718,8 +703,8 @@ template <typename Iter> class input {
718703 }
719704 return true ;
720705 }
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) {
723708 if (getc () != *pi) {
724709 ungetc ();
725710 return false ;
@@ -1139,7 +1124,7 @@ template <typename Iter> inline Iter parse(value &out, const Iter &first, const
11391124 return _parse (ctx, first, last, err);
11401125}
11411126
1142- inline std::string parse (value &out, string_view s) {
1127+ inline std::string parse (value &out, const std::string & s) {
11431128 std::string err;
11441129 parse (out, s.begin (), s.end (), &err);
11451130 return err;
@@ -1154,7 +1139,7 @@ inline std::string parse(value &out, std::istream &is) {
11541139template <typename T> struct last_error_t { static std::string s; };
11551140template <typename T> std::string last_error_t <T>::s;
11561141
1157- inline void set_last_error (string_view s) {
1142+ inline void set_last_error (const std::string & s) {
11581143 last_error_t <bool >::s = s;
11591144}
11601145
0 commit comments