1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

LibLocale: Migrate code generators to Directory::for_each_entry()

This commit is contained in:
Sam Atkins 2023-03-15 15:38:20 +00:00 committed by Tim Flynn
parent 8a8ad81aa1
commit 414cafa7f8
5 changed files with 63 additions and 66 deletions

View file

@ -24,7 +24,7 @@
#include <AK/Utf8View.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/DirIterator.h>
#include <LibCore/Directory.h>
#include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
#include <LibLocale/Locale.h>
#include <LibLocale/NumberFormat.h>
@ -698,9 +698,6 @@ static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr,
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString numbers_path, DeprecatedString units_path, CLDR& cldr)
{
auto numbers_iterator = TRY(path_to_dir_iterator(move(numbers_path)));
auto units_iterator = TRY(path_to_dir_iterator(move(units_path)));
LexicalPath core_supplemental_path(move(core_path));
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
VERIFY(Core::DeprecatedFile::is_directory(core_supplemental_path.string()));
@ -720,21 +717,23 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
return builder.to_deprecated_string();
};
while (numbers_iterator.has_next()) {
auto numbers_path = TRY(next_path_from_dir_iterator(numbers_iterator));
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", numbers_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
auto numbers_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(numbers_path));
auto& locale = cldr.locales.ensure(language);
TRY(parse_number_systems(numbers_path, cldr, locale));
}
return IterationDecision::Continue;
}));
while (units_iterator.has_next()) {
auto units_path = TRY(next_path_from_dir_iterator(units_iterator));
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", units_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
auto units_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(units_path));
auto& locale = cldr.locales.ensure(language);
TRY(parse_units(units_path, cldr, locale));
}
return IterationDecision::Continue;
}));
return {};
}