@@ -714,7 +714,11 @@ namespace json
714
714
private:
715
715
std::string _message;
716
716
public:
717
- json_exception (const utility::char_t * const &message) : _message(utility::conversions::to_utf8string(message)) { }
717
+ json_exception (const char * const message) : _message(message) { }
718
+ #ifdef _UTF16_STRINGS
719
+ json_exception (const wchar_t * const message) : _message(utility::conversions::utf16_to_utf8(message)) { }
720
+ #endif // _UTF16_STRINGS
721
+ json_exception (std::string&& message) : _message(std::move(message)) { }
718
722
719
723
// Must be narrow string because it derives from std::exception
720
724
const char * what () const CPPREST_NOEXCEPT
@@ -930,7 +934,7 @@ namespace json
930
934
{
931
935
if (index >= m_elements.size ())
932
936
{
933
- throw json_exception (_XPLATSTR ( " index out of bounds" ) );
937
+ throw json_exception (" index out of bounds" );
934
938
}
935
939
m_elements.erase (m_elements.begin () + index);
936
940
}
@@ -943,7 +947,7 @@ namespace json
943
947
json::value& at (size_type index)
944
948
{
945
949
if (index >= m_elements.size ())
946
- throw json_exception (_XPLATSTR ( " index out of bounds" ) );
950
+ throw json_exception (" index out of bounds" );
947
951
948
952
return m_elements[index];
949
953
}
@@ -956,7 +960,7 @@ namespace json
956
960
const json::value& at (size_type index) const
957
961
{
958
962
if (index >= m_elements.size ())
959
- throw json_exception (_XPLATSTR ( " index out of bounds" ) );
963
+ throw json_exception (" index out of bounds" );
960
964
961
965
return m_elements[index];
962
966
}
@@ -1145,7 +1149,7 @@ namespace json
1145
1149
auto iter = find_by_key (key);
1146
1150
if (iter == m_elements.end ())
1147
1151
{
1148
- throw web::json::json_exception (_XPLATSTR ( " Key not found" ) );
1152
+ throw web::json::json_exception (" Key not found" );
1149
1153
}
1150
1154
1151
1155
m_elements.erase (iter);
@@ -1161,7 +1165,7 @@ namespace json
1161
1165
auto iter = find_by_key (key);
1162
1166
if (iter == m_elements.end ())
1163
1167
{
1164
- throw web::json::json_exception (_XPLATSTR ( " Key not found" ) );
1168
+ throw web::json::json_exception (" Key not found" );
1165
1169
}
1166
1170
1167
1171
return iter->second ;
@@ -1177,7 +1181,7 @@ namespace json
1177
1181
auto iter = find_by_key (key);
1178
1182
if (iter == m_elements.end ())
1179
1183
{
1180
- throw web::json::json_exception (_XPLATSTR ( " Key not found" ) );
1184
+ throw web::json::json_exception (" Key not found" );
1181
1185
}
1182
1186
1183
1187
return iter->second ;
@@ -1464,14 +1468,14 @@ namespace json
1464
1468
virtual std::unique_ptr<_Value> _copy_value () = 0;
1465
1469
1466
1470
virtual bool has_field (const utility::string_t &) const { return false ; }
1467
- virtual value get_field (const utility::string_t &) const { throw json_exception (_XPLATSTR ( " not an object" ) ); }
1468
- virtual value get_element (array::size_type) const { throw json_exception (_XPLATSTR ( " not an array" ) ); }
1471
+ virtual value get_field (const utility::string_t &) const { throw json_exception (" not an object" ); }
1472
+ virtual value get_element (array::size_type) const { throw json_exception (" not an array" ); }
1469
1473
1470
- virtual value &index (const utility::string_t &) { throw json_exception (_XPLATSTR ( " not an object" ) ); }
1471
- virtual value &index (array::size_type) { throw json_exception (_XPLATSTR ( " not an array" ) ); }
1474
+ virtual value &index (const utility::string_t &) { throw json_exception (" not an object" ); }
1475
+ virtual value &index (array::size_type) { throw json_exception (" not an array" ); }
1472
1476
1473
- virtual const value &cnst_index (const utility::string_t &) const { throw json_exception (_XPLATSTR ( " not an object" ) ); }
1474
- virtual const value &cnst_index (array::size_type) const { throw json_exception (_XPLATSTR ( " not an array" ) ); }
1477
+ virtual const value &cnst_index (const utility::string_t &) const { throw json_exception (" not an object" ); }
1478
+ virtual const value &cnst_index (array::size_type) const { throw json_exception (" not an array" ); }
1475
1479
1476
1480
// Common function used for serialization to strings and streams.
1477
1481
virtual void serialize_impl (std::string& str) const
@@ -1494,18 +1498,18 @@ namespace json
1494
1498
1495
1499
virtual json::value::value_type type () const { return json::value::Null; }
1496
1500
1497
- virtual bool is_integer () const { throw json_exception (_XPLATSTR ( " not a number" ) ); }
1498
- virtual bool is_double () const { throw json_exception (_XPLATSTR ( " not a number" ) ); }
1499
-
1500
- virtual const json::number& as_number () { throw json_exception (_XPLATSTR ( " not a number" ) ); }
1501
- virtual double as_double () const { throw json_exception (_XPLATSTR ( " not a number" ) ); }
1502
- virtual int as_integer () const { throw json_exception (_XPLATSTR ( " not a number" ) ); }
1503
- virtual bool as_bool () const { throw json_exception (_XPLATSTR ( " not a boolean" ) ); }
1504
- virtual json::array& as_array () { throw json_exception (_XPLATSTR ( " not an array" ) ); }
1505
- virtual const json::array& as_array () const { throw json_exception (_XPLATSTR ( " not an array" ) ); }
1506
- virtual json::object& as_object () { throw json_exception (_XPLATSTR ( " not an object" ) ); }
1507
- virtual const json::object& as_object () const { throw json_exception (_XPLATSTR ( " not an object" ) ); }
1508
- virtual const utility::string_t & as_string () const { throw json_exception (_XPLATSTR ( " not a string" ) ); }
1501
+ virtual bool is_integer () const { throw json_exception (" not a number" ); }
1502
+ virtual bool is_double () const { throw json_exception (" not a number" ); }
1503
+
1504
+ virtual const json::number& as_number () { throw json_exception (" not a number" ); }
1505
+ virtual double as_double () const { throw json_exception (" not a number" ); }
1506
+ virtual int as_integer () const { throw json_exception (" not a number" ); }
1507
+ virtual bool as_bool () const { throw json_exception (" not a boolean" ); }
1508
+ virtual json::array& as_array () { throw json_exception (" not an array" ); }
1509
+ virtual const json::array& as_array () const { throw json_exception (" not an array" ); }
1510
+ virtual json::object& as_object () { throw json_exception (" not an object" ); }
1511
+ virtual const json::object& as_object () const { throw json_exception (" not an object" ); }
1512
+ virtual const utility::string_t & as_string () const { throw json_exception (" not a string" ); }
1509
1513
1510
1514
virtual size_t size () const { return 0 ; }
1511
1515
0 commit comments