libexpr/json-to-value: Migrate parseJSON to return a Value
Part of #1136 Change-Id: I5ac23ce461a106360b150e64a6bc0f2f6a6a6964
This commit is contained in:
@@ -190,13 +190,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void parseJSON(EvalState & state, const std::string_view & s_, Value & v)
|
||||
Value parseJSON(EvalState & state, const std::string_view & s_)
|
||||
{
|
||||
JSONSax parser(state);
|
||||
bool res = JSON::sax_parse(s_, &parser);
|
||||
if (!res)
|
||||
throw JSONParseError("Invalid JSON Value");
|
||||
v = parser.result();
|
||||
return parser.result();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,5 @@ struct Value;
|
||||
|
||||
MakeError(JSONParseError, Error);
|
||||
|
||||
void parseJSON(EvalState & state, const std::string_view & s, Value & v);
|
||||
|
||||
Value parseJSON(EvalState & state, const std::string_view & s);
|
||||
}
|
||||
|
||||
@@ -1622,7 +1622,7 @@ static void prim_fromJSON(EvalState & state, Value * * args, Value & v)
|
||||
{
|
||||
auto s = state.forceStringNoCtx(*args[0], noPos, "while evaluating the first argument passed to builtins.fromJSON");
|
||||
try {
|
||||
parseJSON(state, s, v);
|
||||
v = parseJSON(state, s);
|
||||
} catch (JSONParseError &e) {
|
||||
e.addTrace(nullptr, "while decoding a JSON string");
|
||||
throw;
|
||||
|
||||
Reference in New Issue
Block a user