1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-28 09:07:19 +03:00

Only allow minus at the begining of json numbers

This commit is contained in:
Maxime Coste 2019-10-23 22:08:07 +11:00
parent c792986768
commit db2db951c3

View File

@ -257,7 +257,7 @@ void JsonUI::set_on_key(OnKeyCallback callback)
using JsonArray = Vector<Value>;
using JsonObject = HashMap<String, Value>;
static bool is_digit_or_minus(char c) { return (c >= '0' and c <= '9') or c == '-'; }
static bool is_digit(char c) { return c >= '0' and c <= '9'; }
struct JsonResult { Value value; const char* new_pos; };
@ -266,10 +266,10 @@ JsonResult parse_json(const char* pos, const char* end)
if (not skip_while(pos, end, is_blank))
return {};
if (is_digit_or_minus(*pos))
if (is_digit(*pos) or *pos == '-')
{
auto digit_end = pos;
skip_while(digit_end, end, is_digit_or_minus);
auto digit_end = pos + 1;
skip_while(digit_end, end, is_digit);
return { Value{str_to_int({pos, digit_end})}, digit_end };
}
if (end - pos > 4 and StringView{pos, pos+4} == "true")