@@ -242,6 +242,27 @@ namespace json
242242 // / <returns>A JSON number value</returns>
243243 static _ASYNCRTIMP value __cdecl number (int32_t value);
244244
245+ // / <summary>
246+ // / Creates a number value
247+ // / </summary>
248+ // / <param name="value">The C++ value to create a JSON value from</param>
249+ // / <returns>A JSON number value</returns>
250+ static _ASYNCRTIMP value __cdecl number (uint32_t value);
251+
252+ // / <summary>
253+ // / Creates a number value
254+ // / </summary>
255+ // / <param name="value">The C++ value to create a JSON value from</param>
256+ // / <returns>A JSON number value</returns>
257+ static _ASYNCRTIMP value __cdecl number (int64_t value);
258+
259+ // / <summary>
260+ // / Creates a number value
261+ // / </summary>
262+ // / <param name="value">The C++ value to create a JSON value from</param>
263+ // / <returns>A JSON number value</returns>
264+ static _ASYNCRTIMP value __cdecl number (uint64_t value);
265+
245266 // / <summary>
246267 // / Creates a Boolean value
247268 // / </summary>
@@ -543,6 +564,18 @@ namespace json
543564 CASABLANCA_DEPRECATED (" This API is deprecated and will be removed in a future release, use json::value::at() instead." )
544565 value get (const utility::string_t &key) const ;
545566
567+ // / <summary>
568+ // / Erases an element of a JSON array. Throws if index is out of bounds.
569+ // / </summary>
570+ // / <param name="index">The index of the element to erase in the JSON array.</param>
571+ _ASYNCRTIMP void erase (size_t index);
572+
573+ // / <summary>
574+ // / Erases an element of a JSON object. Throws if the key doesn't exist.
575+ // / </summary>
576+ // / <param name="key">The key of the element to erase in the JSON object.</param>
577+ _ASYNCRTIMP void erase (const utility::string_t &key);
578+
546579 // / <summary>
547580 // / Accesses an element of a JSON array. Throws when index out of bounds.
548581 // / </summary>
@@ -841,6 +874,30 @@ namespace json
841874 return m_elements.crend ();
842875 }
843876
877+ // / <summary>
878+ // / Deletes an element of the JSON array.
879+ // / </summary>
880+ // / <param name="position">A const_iterator to the element to delete.</param>
881+ // / <returns>Iterator to the new location of the element following the erased element.</returns>
882+ // / <remarks>GCC doesn't support erase with const_iterator on vector yet. In the future this should be changed.</remarks>
883+ iterator erase (iterator position)
884+ {
885+ return m_elements.erase (position);
886+ }
887+
888+ // / <summary>
889+ // / Deletes the element at an index of the JSON array.
890+ // / </summary>
891+ // / <param name="index">The index of the element to delete.</param>
892+ void erase (size_type index)
893+ {
894+ if (index >= m_elements.size ())
895+ {
896+ throw json_exception (_XPLATSTR (" index out of bounds" ));
897+ }
898+ m_elements.erase (m_elements.begin () + index);
899+ }
900+
844901 // / <summary>
845902 // / Accesses an element of a JSON array. Throws when index out of bounds.
846903 // / </summary>
@@ -1031,6 +1088,32 @@ namespace json
10311088 return m_elements.crend ();
10321089 }
10331090
1091+ // / <summary>
1092+ // / Deletes an element of the JSON object.
1093+ // / </summary>
1094+ // / <param name="position">A const_iterator to the element to delete.</param>
1095+ // / <returns>Iterator to the new location of the element following the erased element.</returns>
1096+ // / <remarks>GCC doesn't support erase with const_iterator on vector yet. In the future this should be changed.</remarks>
1097+ iterator erase (iterator position)
1098+ {
1099+ return m_elements.erase (position);
1100+ }
1101+
1102+ // / <summary>
1103+ // / Deletes an element of the JSON object. If the key doesn't exist, this method throws.
1104+ // / </summary>
1105+ // / <param name="key">The key of an element in the JSON object.</param>
1106+ void erase (const utility::string_t &key)
1107+ {
1108+ auto iter = find_by_key (key);
1109+ if (iter == m_elements.end ())
1110+ {
1111+ throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1112+ }
1113+
1114+ m_elements.erase (iter);
1115+ }
1116+
10341117 // / <summary>
10351118 // / Accesses an element of a JSON object. If the key doesn't exist, this method throws.
10361119 // / </summary>
@@ -1039,9 +1122,10 @@ namespace json
10391122 json::value& at (const utility::string_t & key)
10401123 {
10411124 auto iter = find_by_key (key);
1042-
1043- if (iter == m_elements. end () || key != (iter-> first ))
1125+ if (iter == m_elements. end ())
1126+ {
10441127 throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1128+ }
10451129
10461130 return iter->second ;
10471131 }
@@ -1054,9 +1138,10 @@ namespace json
10541138 const json::value& at (const utility::string_t & key) const
10551139 {
10561140 auto iter = find_by_key (key);
1057-
1058- if (iter == m_elements. end () || key != (iter-> first ))
1141+ if (iter == m_elements. end ())
1142+ {
10591143 throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1144+ }
10601145
10611146 return iter->second ;
10621147 }
@@ -1068,10 +1153,12 @@ namespace json
10681153 // / <returns>If the key exists, a reference to the value kept in the field, otherwise a newly created null value that will be stored for the given key.</returns>
10691154 json::value& operator [](const utility::string_t & key)
10701155 {
1071- auto iter = find_by_key (key);
1156+ auto iter = find_insert_location (key);
10721157
1073- if (iter == m_elements.end () || key != (iter->first ))
1158+ if (iter == m_elements.end () || key != iter->first )
1159+ {
10741160 return m_elements.insert (iter, std::pair<utility::string_t , value>(key, value ()))->second ;
1161+ }
10751162
10761163 return iter->second ;
10771164 }
@@ -1083,7 +1170,7 @@ namespace json
10831170 // / <returns>A const iterator to the value kept in the field.</returns>
10841171 const_iterator find (const utility::string_t & key) const
10851172 {
1086- return find_internal (key);
1173+ return find_by_key (key);
10871174 }
10881175
10891176 // / <summary>
@@ -1114,7 +1201,7 @@ namespace json
11141201 return p1.first < key;
11151202 }
11161203
1117- storage_type::const_iterator find_by_key (const utility::string_t & key) const
1204+ storage_type::iterator find_insert_location (const utility::string_t & key)
11181205 {
11191206 if (m_keep_order)
11201207 {
@@ -1129,7 +1216,7 @@ namespace json
11291216 }
11301217 }
11311218
1132- storage_type::iterator find_by_key (const utility::string_t & key)
1219+ storage_type::const_iterator find_by_key (const utility::string_t & key) const
11331220 {
11341221 if (m_keep_order)
11351222 {
@@ -1140,37 +1227,22 @@ namespace json
11401227 }
11411228 else
11421229 {
1143- return std::lower_bound (m_elements.begin (), m_elements.end (), key, compare_with_key);
1230+ auto iter = std::lower_bound (m_elements.begin (), m_elements.end (), key, compare_with_key);
1231+ if (iter != m_elements.end () && key != iter->first )
1232+ {
1233+ return m_elements.end ();
1234+ }
1235+ return iter;
11441236 }
11451237 }
11461238
1147- const json::value& at_internal (const utility::string_t & key) const
1148- {
1149- auto iter = find_by_key (key);
1150-
1151- if (iter == m_elements.end () || key != (iter->first ))
1152- throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1153-
1154- return iter->second ;
1155- }
1156-
1157- const_iterator find_internal (const utility::string_t & key) const
1158- {
1159- auto iter = find_by_key (key);
1160-
1161- if (iter != m_elements.end () && key != (iter->first ))
1162- return m_elements.end ();
1163-
1164- return iter;
1165- }
1166-
1167- iterator find_internal (const utility::string_t & key)
1239+ storage_type::iterator find_by_key (const utility::string_t & key)
11681240 {
1169- auto iter = find_by_key (key);
1170-
1171- if (iter != m_elements. end () && key != (iter-> first ))
1241+ auto iter = find_insert_location (key);
1242+ if (iter != m_elements. end () && key != iter-> first )
1243+ {
11721244 return m_elements.end ();
1173-
1245+ }
11741246 return iter;
11751247 }
11761248
0 commit comments