@@ -13,6 +13,7 @@ namespace simdjson {
1313// C API (json_parse and build_parsed_json) declarations
1414//
1515
16+ [[deprecated("Use document::parser.parse() instead")]]
1617inline int json_parse (const uint8_t *buf, size_t len, document::parser &parser, bool realloc_if_needed = true ) noexcept {
1718 error_code code = parser.parse (buf, len, realloc_if_needed).error ();
1819 // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
@@ -23,29 +24,87 @@ inline int json_parse(const uint8_t *buf, size_t len, document::parser &parser,
2324 parser.error = code;
2425 return code;
2526}
27+ [[deprecated("Use document::parser.parse() instead")]]
2628inline int json_parse (const char *buf, size_t len, document::parser &parser, bool realloc_if_needed = true ) noexcept {
27- return json_parse (reinterpret_cast <const uint8_t *>(buf), len, parser, realloc_if_needed);
29+ error_code code = parser.parse (buf, len, realloc_if_needed).error ();
30+ // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
31+ // bits in the parser instead of heeding the result code. The normal parser unsets those in
32+ // anticipation of making the error code ephemeral.
33+ // Here we put the code back into the parser, until we've removed this method.
34+ parser.valid = code == SUCCESS ;
35+ parser.error = code;
36+ return code;
2837}
38+ [[deprecated("Use document::parser.parse() instead")]]
2939inline int json_parse (const std::string &s, document::parser &parser, bool realloc_if_needed = true ) noexcept {
30- return json_parse (s.data (), s.length (), parser, realloc_if_needed);
40+ error_code code = parser.parse (s.data (), s.length (), realloc_if_needed).error ();
41+ // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
42+ // bits in the parser instead of heeding the result code. The normal parser unsets those in
43+ // anticipation of making the error code ephemeral.
44+ // Here we put the code back into the parser, until we've removed this method.
45+ parser.valid = code == SUCCESS ;
46+ parser.error = code;
47+ return code;
3148}
49+ [[deprecated("Use document::parser.parse() instead")]]
3250inline int json_parse (const padded_string &s, document::parser &parser) noexcept {
33- return json_parse (s.data (), s.length (), parser, false );
51+ error_code code = parser.parse (s).error ();
52+ // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
53+ // bits in the parser instead of heeding the result code. The normal parser unsets those in
54+ // anticipation of making the error code ephemeral.
55+ // Here we put the code back into the parser, until we've removed this method.
56+ parser.valid = code == SUCCESS ;
57+ parser.error = code;
58+ return code;
3459}
3560
36- WARN_UNUSED static document::parser build_parsed_json (const uint8_t *buf, size_t len, bool realloc_if_needed = true ) noexcept {
61+ [[deprecated("Use document::parser.parse() instead")]]
62+ WARN_UNUSED inline document::parser build_parsed_json (const uint8_t *buf, size_t len, bool realloc_if_needed = true ) noexcept {
3763 document::parser parser;
38- json_parse (buf, len, parser, realloc_if_needed);
64+ error_code code = parser.parse (buf, len, realloc_if_needed).error ();
65+ // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
66+ // bits in the parser instead of heeding the result code. The normal parser unsets those in
67+ // anticipation of making the error code ephemeral.
68+ // Here we put the code back into the parser, until we've removed this method.
69+ parser.valid = code == SUCCESS ;
70+ parser.error = code;
3971 return parser;
4072}
73+ [[deprecated("Use document::parser.parse() instead")]]
4174WARN_UNUSED inline document::parser build_parsed_json (const char *buf, size_t len, bool realloc_if_needed = true ) noexcept {
42- return build_parsed_json (reinterpret_cast <const uint8_t *>(buf), len, realloc_if_needed);
75+ document::parser parser;
76+ error_code code = parser.parse (buf, len, realloc_if_needed).error ();
77+ // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
78+ // bits in the parser instead of heeding the result code. The normal parser unsets those in
79+ // anticipation of making the error code ephemeral.
80+ // Here we put the code back into the parser, until we've removed this method.
81+ parser.valid = code == SUCCESS ;
82+ parser.error = code;
83+ return parser;
4384}
85+ [[deprecated("Use document::parser.parse() instead")]]
4486WARN_UNUSED inline document::parser build_parsed_json (const std::string &s, bool realloc_if_needed = true ) noexcept {
45- return build_parsed_json (s.data (), s.length (), realloc_if_needed);
87+ document::parser parser;
88+ error_code code = parser.parse (s.data (), s.length (), realloc_if_needed).error ();
89+ // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
90+ // bits in the parser instead of heeding the result code. The normal parser unsets those in
91+ // anticipation of making the error code ephemeral.
92+ // Here we put the code back into the parser, until we've removed this method.
93+ parser.valid = code == SUCCESS ;
94+ parser.error = code;
95+ return parser;
4696}
97+ [[deprecated("Use document::parser.parse() instead")]]
4798WARN_UNUSED inline document::parser build_parsed_json (const padded_string &s) noexcept {
48- return build_parsed_json (s.data (), s.length (), false );
99+ document::parser parser;
100+ error_code code = parser.parse (s).error ();
101+ // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid
102+ // bits in the parser instead of heeding the result code. The normal parser unsets those in
103+ // anticipation of making the error code ephemeral.
104+ // Here we put the code back into the parser, until we've removed this method.
105+ parser.valid = code == SUCCESS ;
106+ parser.error = code;
107+ return parser;
49108}
50109
51110// We do not want to allow implicit conversion from C string to std::string.
0 commit comments