Convert everything to c api
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "parser3.h"
|
||||
#include "weaseljson.h"
|
||||
|
||||
struct JsonNumber : std::string {};
|
||||
@@ -195,21 +194,23 @@ inline std::string toString(JsonValue const &jsonValue) {
|
||||
inline std::optional<JsonValue> toValue(std::string copy, int stride) {
|
||||
ReadValueState state;
|
||||
auto c = readValueCallbacks();
|
||||
parser3::Parser3 parser(&c, &state);
|
||||
std::unique_ptr<WeaselJsonParser, decltype(&WeaselJsonParser_destroy)> parser{
|
||||
WeaselJsonParser_create(1024, &c, &state), WeaselJsonParser_destroy};
|
||||
if (stride == 0) {
|
||||
if (parser.parse(copy.data(), copy.size()) != WeaselJson_AGAIN) {
|
||||
if (WeaselJsonParser_parse(parser.get(), copy.data(), copy.size()) !=
|
||||
WeaselJson_AGAIN) {
|
||||
return std::nullopt;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < copy.size(); i += stride) {
|
||||
if (parser.parse(copy.data() + i,
|
||||
std::min<int>(stride, copy.size() - i)) !=
|
||||
if (WeaselJsonParser_parse(parser.get(), copy.data() + i,
|
||||
std::min<int>(stride, copy.size() - i)) !=
|
||||
WeaselJson_AGAIN) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parser.parse(nullptr, 0) != WeaselJson_OK) {
|
||||
if (WeaselJsonParser_parse(parser.get(), nullptr, 0) != WeaselJson_OK) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::move(state.result);
|
||||
|
||||
Reference in New Issue
Block a user