@@ -13,6 +13,7 @@ namespace simdjson {
13
13
// C API (json_parse and build_parsed_json) declarations
14
14
//
15
15
16
+ [[deprecated(" Use document::parser.parse() instead" )]]
16
17
inline int json_parse (const uint8_t *buf, size_t len, document::parser &parser, bool realloc_if_needed = true ) noexcept {
17
18
error_code code = parser.parse (buf, len, realloc_if_needed).error ();
18
19
// 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,
23
24
parser.error = code;
24
25
return code;
25
26
}
27
+ [[deprecated(" Use document::parser.parse() instead" )]]
26
28
inline 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;
28
37
}
38
+ [[deprecated(" Use document::parser.parse() instead" )]]
29
39
inline 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;
31
48
}
49
+ [[deprecated(" Use document::parser.parse() instead" )]]
32
50
inline 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;
34
59
}
35
60
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 {
37
63
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;
39
71
return parser;
40
72
}
73
+ [[deprecated(" Use document::parser.parse() instead" )]]
41
74
WARN_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;
43
84
}
85
+ [[deprecated(" Use document::parser.parse() instead" )]]
44
86
WARN_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;
46
96
}
97
+ [[deprecated(" Use document::parser.parse() instead" )]]
47
98
WARN_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;
49
108
}
50
109
51
110
// We do not want to allow implicit conversion from C string to std::string.
0 commit comments