1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 19:14:58 +00:00

AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)

Also add slightly richer parse errors now that we can include a string
literal with returned errors.

This will allow us to use TRY() when working with JSON data.
This commit is contained in:
Andreas Kling 2021-11-15 01:46:51 +01:00
parent 304c03f457
commit 587f9af960
54 changed files with 172 additions and 228 deletions

View file

@ -240,10 +240,9 @@ static void parse_number_systems(String locale_numbers_path, UnicodeLocaleData&
auto numbers_file_or_error = Core::File::open(numbers_path.string(), Core::OpenMode::ReadOnly);
VERIFY(!numbers_file_or_error.is_error());
auto numbers = JsonParser(numbers_file_or_error.value()->read_all()).parse();
VERIFY(numbers.has_value());
auto numbers = JsonValue::from_string(numbers_file_or_error.value()->read_all()).release_value_but_fixme_should_propagate_errors();
auto const& main_object = numbers->as_object().get("main"sv);
auto const& main_object = numbers.as_object().get("main"sv);
auto const& locale_object = main_object.as_object().get(numbers_path.parent().basename());
auto const& locale_numbers_object = locale_object.as_object().get("numbers"sv);
@ -360,10 +359,9 @@ static void parse_units(String locale_units_path, UnicodeLocaleData& locale_data
auto units_file_or_error = Core::File::open(units_path.string(), Core::OpenMode::ReadOnly);
VERIFY(!units_file_or_error.is_error());
auto units = JsonParser(units_file_or_error.value()->read_all()).parse();
VERIFY(units.has_value());
auto units = JsonValue::from_string(units_file_or_error.value()->read_all()).release_value_but_fixme_should_propagate_errors();
auto const& main_object = units->as_object().get("main"sv);
auto const& main_object = units.as_object().get("main"sv);
auto const& locale_object = main_object.as_object().get(units_path.parent().basename());
auto const& locale_units_object = locale_object.as_object().get("units"sv);
auto const& long_object = locale_units_object.as_object().get("long"sv);