| 1 | // TODO Remove this -- deprecated API and files |
| 2 | |
| 3 | #ifndef SIMDJSON_DOM_JSONPARSER_H |
| 4 | #define SIMDJSON_DOM_JSONPARSER_H |
| 5 | |
| 6 | #include "simdjson/dom/document.h" |
| 7 | #include "simdjson/dom/parsedjson.h" |
| 8 | #include "simdjson/jsonioutil.h" |
| 9 | |
| 10 | namespace simdjson { |
| 11 | |
| 12 | // |
| 13 | // C API (json_parse and build_parsed_json) declarations |
| 14 | // |
| 15 | |
| 16 | #ifndef SIMDJSON_DISABLE_DEPRECATED_API |
| 17 | [[deprecated("Use parser.parse() instead" )]] |
| 18 | inline int json_parse(const uint8_t *buf, size_t len, dom::parser &parser, bool realloc_if_needed = true) noexcept { |
| 19 | error_code code = parser.parse(buf, len, realloc_if_needed).error(); |
| 20 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 21 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 22 | // anticipation of making the error code ephemeral. |
| 23 | // Here we put the code back into the parser, until we've removed this method. |
| 24 | parser.valid = code == SUCCESS; |
| 25 | parser.error = code; |
| 26 | return code; |
| 27 | } |
| 28 | [[deprecated("Use parser.parse() instead" )]] |
| 29 | inline int json_parse(const char *buf, size_t len, dom::parser &parser, bool realloc_if_needed = true) noexcept { |
| 30 | error_code code = parser.parse(buf, len, realloc_if_needed).error(); |
| 31 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 32 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 33 | // anticipation of making the error code ephemeral. |
| 34 | // Here we put the code back into the parser, until we've removed this method. |
| 35 | parser.valid = code == SUCCESS; |
| 36 | parser.error = code; |
| 37 | return code; |
| 38 | } |
| 39 | [[deprecated("Use parser.parse() instead" )]] |
| 40 | inline int json_parse(const std::string &s, dom::parser &parser, bool realloc_if_needed = true) noexcept { |
| 41 | error_code code = parser.parse(buf: s.data(), len: s.length(), realloc_if_needed).error(); |
| 42 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 43 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 44 | // anticipation of making the error code ephemeral. |
| 45 | // Here we put the code back into the parser, until we've removed this method. |
| 46 | parser.valid = code == SUCCESS; |
| 47 | parser.error = code; |
| 48 | return code; |
| 49 | } |
| 50 | [[deprecated("Use parser.parse() instead" )]] |
| 51 | inline int json_parse(const padded_string &s, dom::parser &parser) noexcept { |
| 52 | error_code code = parser.parse(s).error(); |
| 53 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 54 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 55 | // anticipation of making the error code ephemeral. |
| 56 | // Here we put the code back into the parser, until we've removed this method. |
| 57 | parser.valid = code == SUCCESS; |
| 58 | parser.error = code; |
| 59 | return code; |
| 60 | } |
| 61 | |
| 62 | [[deprecated("Use parser.parse() instead" )]] |
| 63 | simdjson_warn_unused inline dom::parser build_parsed_json(const uint8_t *buf, size_t len, bool realloc_if_needed = true) noexcept { |
| 64 | dom::parser parser; |
| 65 | error_code code = parser.parse(buf, len, realloc_if_needed).error(); |
| 66 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 67 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 68 | // anticipation of making the error code ephemeral. |
| 69 | // Here we put the code back into the parser, until we've removed this method. |
| 70 | parser.valid = code == SUCCESS; |
| 71 | parser.error = code; |
| 72 | return parser; |
| 73 | } |
| 74 | [[deprecated("Use parser.parse() instead" )]] |
| 75 | simdjson_warn_unused inline dom::parser build_parsed_json(const char *buf, size_t len, bool realloc_if_needed = true) noexcept { |
| 76 | dom::parser parser; |
| 77 | error_code code = parser.parse(buf, len, realloc_if_needed).error(); |
| 78 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 79 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 80 | // anticipation of making the error code ephemeral. |
| 81 | // Here we put the code back into the parser, until we've removed this method. |
| 82 | parser.valid = code == SUCCESS; |
| 83 | parser.error = code; |
| 84 | return parser; |
| 85 | } |
| 86 | [[deprecated("Use parser.parse() instead" )]] |
| 87 | simdjson_warn_unused inline dom::parser build_parsed_json(const std::string &s, bool realloc_if_needed = true) noexcept { |
| 88 | dom::parser parser; |
| 89 | error_code code = parser.parse(buf: s.data(), len: s.length(), realloc_if_needed).error(); |
| 90 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 91 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 92 | // anticipation of making the error code ephemeral. |
| 93 | // Here we put the code back into the parser, until we've removed this method. |
| 94 | parser.valid = code == SUCCESS; |
| 95 | parser.error = code; |
| 96 | return parser; |
| 97 | } |
| 98 | [[deprecated("Use parser.parse() instead" )]] |
| 99 | simdjson_warn_unused inline dom::parser build_parsed_json(const padded_string &s) noexcept { |
| 100 | dom::parser parser; |
| 101 | error_code code = parser.parse(s).error(); |
| 102 | // The deprecated json_parse API is a signal that the user plans to *use* the error code / valid |
| 103 | // bits in the parser instead of heeding the result code. The normal parser unsets those in |
| 104 | // anticipation of making the error code ephemeral. |
| 105 | // Here we put the code back into the parser, until we've removed this method. |
| 106 | parser.valid = code == SUCCESS; |
| 107 | parser.error = code; |
| 108 | return parser; |
| 109 | } |
| 110 | #endif // SIMDJSON_DISABLE_DEPRECATED_API |
| 111 | |
| 112 | /** @private We do not want to allow implicit conversion from C string to std::string. */ |
| 113 | int json_parse(const char *buf, dom::parser &parser) noexcept = delete; |
| 114 | /** @private We do not want to allow implicit conversion from C string to std::string. */ |
| 115 | dom::parser build_parsed_json(const char *buf) noexcept = delete; |
| 116 | |
| 117 | } // namespace simdjson |
| 118 | |
| 119 | #endif // SIMDJSON_DOM_JSONPARSER_H |
| 120 | |