diff --git a/doc/ref/corelib/json/parse.md b/doc/ref/corelib/json/parse.md index 792ab020a6..ae2bb3ca26 100644 --- a/doc/ref/corelib/json/parse.md +++ b/doc/ref/corelib/json/parse.md @@ -8,64 +8,40 @@ static basic_json parse(const Source& source, static basic_json parse(const char_type* str, const basic_json_decode_options& options = basic_json_decode_options()); (2) -static basic_json parse(std::basic_istream& is, +static basic_json parse(const char_type* str, std::size_t length, const basic_json_decode_options& options = basic_json_decode_options()); (3) +static basic_json parse(std::basic_istream& is, + const basic_json_decode_options& options = basic_json_decode_options()); (4) + template static basic_json parse(InputIt first, InputIt last, - const basic_json_decode_options& options = basic_json_decode_options()); (4) + const basic_json_decode_options& options = basic_json_decode_options()); (5) template static basic_json parse(const allocator_set& alloc_set, const Source& source, - const basic_json_decode_options& options = basic_json_decode_options()); (5) (since 0.171.0) + const basic_json_decode_options& options = basic_json_decode_options()); (6) (since 0.171.0) template static basic_json parse(const allocator_set& alloc_set, const char_type* str, - const basic_json_decode_options& options = basic_json_decode_options()); (6) (since 0.171.0) + const basic_json_decode_options& options = basic_json_decode_options()); (7) (since 0.171.0) + +template +static basic_json parse(const allocator_set& alloc_set, + const char_type* str, std::size_t length, + const basic_json_decode_options& options = basic_json_decode_options()); (8) (since 0.177.0) template static basic_json parse(const allocator_set& alloc_set, std::basic_istream& is, - const basic_json_decode_options& options = basic_json_decode_options()); (7) (since 0.171.0) + const basic_json_decode_options& options = basic_json_decode_options()); (9) (since 0.171.0) template static basic_json parse(const allocator_set& alloc_set, InputIt first, InputIt last, - const basic_json_decode_options& options = basic_json_decode_options()); (8) (since 0.171.0) - -template -static basic_json parse(const Source& source, - const basic_json_decode_options& options, (9) (deprecated since 0.171.0) - std::function err_handler); - -template -static basic_json parse(const Source& source, - std::function err_handler); (10) (deprecated since 0.171.0) - -static basic_json parse(const char_type* str, - const basic_json_decode_options& options, (11) (deprecated since 0.171.0) - std::function err_handler); - -static basic_json parse(const char_type* str, - std::function err_handler); (12) (deprecated since 0.171.0) - -static basic_json parse(std::basic_istream& is, - const basic_json_decode_options& options, (13) (deprecated since 0.171.0) - std::function err_handler); - -static basic_json parse(std::istream& is, - std::function err_handler); (14) (deprecated since 0.171.0) - -template -static basic_json parse(InputIt first, InputIt last, - const basic_json_decode_options& options, (15) (deprecated since 0.171.0) - std::function err_handler); - -template -static basic_json parse(InputIt first, InputIt last, (16) (deprecated since 0.171.0) - std::function err_handler); + const basic_json_decode_options& options = basic_json_decode_options()); (10) (since 0.171.0) ``` (1) Parses JSON data from a contiguous character sequence provided by `source` and returns a `basic_json` value. Throws a [ser_error](../ser_error.md) if parsing fails. @@ -73,19 +49,24 @@ Throws a [ser_error](../ser_error.md) if parsing fails. (2) Parses JSON data from a null-terminated character string and returns a `basic_json` value. Throws a [ser_error](../ser_error.md) if parsing fails. -(3) Parses JSON data from an input stream and returns a `basic_json` value. +(3) Parses JSON data from a string and length and returns a `basic_json` value. Throws a [ser_error](../ser_error.md) if parsing fails. -(4) Parses JSON data from the range [`first`,`last`) and returns a `basic_json` value. +(4) Parses JSON data from an input stream and returns a `basic_json` value. Throws a [ser_error](../ser_error.md) if parsing fails. -(5)-(8) Same as (1)-(4), except they accept an [allocator_set](allocator_set.md) argument. +(5) Parses JSON data from the range [`first`,`last`) and returns a `basic_json` value. +Throws a [ser_error](../ser_error.md) if parsing fails. + +(6)-(10) Same as (1)-(5), except they accept an [allocator_set](allocator_set.md) argument. #### Parameters `source` = a contigugous character source, such as a `std::string` or `std::string_view` -`str` - a null terminated character string +`str` - a character string + +`length` - the length of a character string `is` - an input stream diff --git a/include/jsoncons/basic_json.hpp b/include/jsoncons/basic_json.hpp index 6c11525c68..04ebf6ef97 100644 --- a/include/jsoncons/basic_json.hpp +++ b/include/jsoncons/basic_json.hpp @@ -2930,6 +2930,12 @@ namespace jsoncons { return decoder.get_result(); } + static basic_json parse(const char_type* str, std::size_t length, + const basic_json_decode_options& options = basic_json_options()) + { + return parse(jsoncons::string_view(str,length), options); + } + static basic_json parse(const char_type* source, const basic_json_decode_options& options = basic_json_options()) { @@ -2943,17 +2949,12 @@ namespace jsoncons { return parse(alloc_set, jsoncons::basic_string_view(source), options); } - static basic_json parse(const char_type* s, - const basic_json_decode_options& options, - std::function err_handler) - { - return parse(jsoncons::basic_string_view(s), options, err_handler); - } - - static basic_json parse(const char_type* s, - std::function err_handler) + template + static basic_json parse(const allocator_set& alloc_set, + const char_type* str, std::size_t length, + const basic_json_decode_options& options = basic_json_options()) { - return parse(jsoncons::basic_string_view(s), basic_json_decode_options(), err_handler); + return parse(alloc_set, jsoncons::basic_string_view(str, length), options); } // from stream @@ -3022,6 +3023,21 @@ namespace jsoncons { return decoder.get_result(); } +#if !defined(JSONCONS_NO_DEPRECATED) + + static basic_json parse(const char_type* s, + const basic_json_decode_options& options, + std::function err_handler) + { + return parse(jsoncons::basic_string_view(s), options, err_handler); + } + + static basic_json parse(const char_type* s, + std::function err_handler) + { + return parse(jsoncons::basic_string_view(s), basic_json_decode_options(), err_handler); + } + static basic_json parse(std::basic_istream& is, const basic_json_decode_options& options, std::function err_handler) @@ -3100,7 +3116,7 @@ namespace jsoncons { { return parse(first, last, basic_json_decode_options(), err_handler); } - +#endif static basic_json make_array() { return basic_json(array());