summaryrefslogtreecommitdiff
path: root/Meta/Lagom
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-03-15 15:38:20 +0000
committerTim Flynn <trflynn89@pm.me>2023-03-15 12:49:33 -0400
commit414cafa7f880e0632e8ad96c89c5b030a74a6c65 (patch)
treefd09f55b3cef1f49a3b9723439951c645bb1071b /Meta/Lagom
parent8a8ad81aa13ec25d20d78bf99f951055ef416597 (diff)
downloadserenity-414cafa7f880e0632e8ad96c89c5b030a74a6c65.zip
LibLocale: Migrate code generators to Directory::for_each_entry()
Diffstat (limited to 'Meta/Lagom')
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateDateTimeFormatData.cpp19
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp70
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp19
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibLocale/GeneratePluralRulesData.cpp10
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateRelativeTimeFormatData.cpp11
5 files changed, 63 insertions, 66 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateDateTimeFormatData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateDateTimeFormatData.cpp
index 463dea1deb..88611ed856 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateDateTimeFormatData.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateDateTimeFormatData.cpp
@@ -23,7 +23,7 @@
#include <AK/Traits.h>
#include <AK/Utf8View.h>
#include <LibCore/ArgsParser.h>
-#include <LibCore/DirIterator.h>
+#include <LibCore/Directory.h>
#include <LibLocale/DateTimeFormat.h>
#include <LibTimeZone/TimeZone.h>
@@ -1654,8 +1654,6 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
TRY(parse_week_data(core_path, cldr));
TRY(parse_meta_zones(core_path, cldr));
- auto dates_iterator = TRY(path_to_dir_iterator(move(dates_path)));
-
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
@@ -1669,20 +1667,21 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
return builder.to_deprecated_string();
};
- while (dates_iterator.has_next()) {
- auto dates_path = TRY(next_path_from_dir_iterator(dates_iterator));
- auto calendars_iterator = TRY(path_to_dir_iterator(dates_path, {}));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto dates_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(dates_path));
auto& locale = cldr.locales.ensure(language);
- while (calendars_iterator.has_next()) {
- auto calendars_path = TRY(next_path_from_dir_iterator(calendars_iterator));
+ TRY(Core::Directory::for_each_entry(dates_path, Core::DirIterator::SkipParentAndBaseDir, [&](auto& dates_entry, auto& dates_directory) -> ErrorOr<IterationDecision> {
+ auto calendars_path = LexicalPath::join(dates_directory.path().string(), dates_entry.name).string();
TRY(parse_calendars(move(calendars_path), cldr, locale));
- }
+ return IterationDecision::Continue;
+ }));
TRY(parse_time_zone_names(move(dates_path), cldr, locale));
- }
+ return IterationDecision::Continue;
+ }));
TRY(parse_day_periods(move(core_path), cldr));
return {};
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp
index c046530860..8e55575b86 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateLocaleData.cpp
@@ -20,7 +20,7 @@
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DeprecatedFile.h>
-#include <LibCore/DirIterator.h>
+#include <LibCore/Directory.h>
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
{
@@ -771,15 +771,14 @@ static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_number
static ErrorOr<void> parse_calendar_keywords(DeprecatedString locale_dates_path, CLDR& cldr, LocaleData& locale)
{
- auto calendars_iterator = TRY(path_to_dir_iterator(locale_dates_path, {}));
KeywordList keywords {};
- while (calendars_iterator.has_next()) {
- auto locale_calendars_path = TRY(next_path_from_dir_iterator(calendars_iterator));
+ TRY(Core::Directory::for_each_entry(locale_dates_path, Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto locale_calendars_path = LexicalPath::join(directory.path().string(), entry.name).string();
LexicalPath calendars_path(move(locale_calendars_path));
if (!calendars_path.basename().starts_with("ca-"sv))
- continue;
+ return IterationDecision::Continue;
auto calendars = TRY(read_json_file(calendars_path.string()));
auto const& main_object = calendars.as_object().get_object("main"sv).value();
@@ -798,7 +797,9 @@ static ErrorOr<void> parse_calendar_keywords(DeprecatedString locale_dates_path,
keywords.append(cldr.unique_strings.ensure(calendar_name));
});
- }
+
+ return IterationDecision::Continue;
+ }));
locale.calendar_keywords = cldr.unique_keyword_lists.ensure(move(keywords));
return {};
@@ -910,14 +911,6 @@ static ErrorOr<void> define_aliases_without_scripts(CLDR& cldr)
static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedString core_path, DeprecatedString locale_names_path, DeprecatedString misc_path, DeprecatedString numbers_path, DeprecatedString dates_path, CLDR& cldr)
{
- auto bcp47_iterator = TRY(path_to_dir_iterator(move(bcp47_path), "bcp47"sv));
- auto identity_iterator = TRY(path_to_dir_iterator(locale_names_path));
- auto preprocess_iterator = TRY(path_to_dir_iterator(locale_names_path));
- auto locale_names_iterator = TRY(path_to_dir_iterator(move(locale_names_path)));
- auto misc_iterator = TRY(path_to_dir_iterator(move(misc_path)));
- auto numbers_iterator = TRY(path_to_dir_iterator(move(numbers_path)));
- auto dates_iterator = TRY(path_to_dir_iterator(move(dates_path)));
-
LexicalPath core_supplemental_path(core_path);
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
VERIFY(Core::DeprecatedFile::is_directory(core_supplemental_path.string()));
@@ -938,30 +931,33 @@ static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedSt
return builder.to_deprecated_string();
};
- while (identity_iterator.has_next()) {
- auto locale_path = TRY(next_path_from_dir_iterator(identity_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto locale_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(locale_path));
auto& locale = cldr.locales.ensure(language);
TRY(parse_identity(locale_path, cldr, locale));
- }
+ return IterationDecision::Continue;
+ }));
- while (preprocess_iterator.has_next()) {
- auto locale_path = TRY(next_path_from_dir_iterator(preprocess_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto locale_path = LexicalPath::join(directory.path().string(), entry.name).string();
TRY(preprocess_languages(locale_path, cldr));
- }
+ return IterationDecision::Continue;
+ }));
quick_sort(cldr.languages);
quick_sort(cldr.territories);
quick_sort(cldr.scripts);
- while (bcp47_iterator.has_next()) {
- auto bcp47_path = TRY(next_path_from_dir_iterator(bcp47_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/bcp47", bcp47_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto bcp47_path = LexicalPath::join(directory.path().string(), entry.name).string();
TRY(parse_unicode_extension_keywords(move(bcp47_path), cldr));
- }
+ return IterationDecision::Continue;
+ }));
- while (locale_names_iterator.has_next()) {
- auto locale_path = TRY(next_path_from_dir_iterator(locale_names_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto locale_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(locale_path));
auto& locale = cldr.locales.ensure(language);
@@ -970,35 +966,39 @@ static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedSt
TRY(parse_locale_territories(locale_path, cldr, locale));
TRY(parse_locale_scripts(locale_path, cldr, locale));
TRY(parse_locale_calendars(locale_path, cldr, locale));
- }
+ return IterationDecision::Continue;
+ }));
- while (misc_iterator.has_next()) {
- auto misc_path = TRY(next_path_from_dir_iterator(misc_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", misc_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto misc_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(misc_path));
auto& locale = cldr.locales.ensure(language);
TRY(parse_locale_list_patterns(misc_path, cldr, locale));
TRY(parse_locale_layout(misc_path, cldr, locale));
- }
+ return IterationDecision::Continue;
+ }));
- 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_locale_currencies(numbers_path, cldr, locale));
TRY(parse_number_system_keywords(numbers_path, cldr, locale));
fill_in_collation_keywords(cldr, locale);
- }
+ return IterationDecision::Continue;
+ }));
- while (dates_iterator.has_next()) {
- auto dates_path = TRY(next_path_from_dir_iterator(dates_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto dates_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(dates_path));
auto& locale = cldr.locales.ensure(language);
TRY(parse_locale_date_fields(dates_path, cldr, locale));
TRY(parse_calendar_keywords(dates_path, cldr, locale));
- }
+ return IterationDecision::Continue;
+ }));
TRY(parse_default_content_locales(move(core_path), cldr));
TRY(define_aliases_without_scripts(cldr));
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp
index 194cfef899..5e7046ce48 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateNumberFormatData.cpp
@@ -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 {};
}
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GeneratePluralRulesData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GeneratePluralRulesData.cpp
index ff13b336fa..2b24c31710 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GeneratePluralRulesData.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GeneratePluralRulesData.cpp
@@ -15,6 +15,7 @@
#include <AK/Variant.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DeprecatedFile.h>
+#include <LibCore/Directory.h>
#include <LibLocale/PluralRules.h>
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
@@ -393,8 +394,6 @@ static ErrorOr<void> parse_plural_ranges(DeprecatedString core_supplemental_path
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString locale_names_path, CLDR& cldr)
{
- auto identity_iterator = TRY(path_to_dir_iterator(move(locale_names_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()));
@@ -412,12 +411,13 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
return builder.to_deprecated_string();
};
- while (identity_iterator.has_next()) {
- auto locale_path = TRY(next_path_from_dir_iterator(identity_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto locale_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(locale_path));
cldr.locales.ensure(language);
- }
+ return IterationDecision::Continue;
+ }));
TRY(parse_plural_rules(core_supplemental_path.string(), "plurals.json"sv, cldr));
TRY(parse_plural_rules(core_supplemental_path.string(), "ordinals.json"sv, cldr));
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateRelativeTimeFormatData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateRelativeTimeFormatData.cpp
index f00b7d49be..ed96225bad 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateRelativeTimeFormatData.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibLocale/GenerateRelativeTimeFormatData.cpp
@@ -15,7 +15,7 @@
#include <AK/SourceGenerator.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
-#include <LibCore/DirIterator.h>
+#include <LibCore/Directory.h>
#include <LibLocale/Locale.h>
#include <LibLocale/RelativeTimeFormat.h>
@@ -137,8 +137,6 @@ static ErrorOr<void> parse_date_fields(DeprecatedString locale_dates_path, CLDR&
static ErrorOr<void> parse_all_locales(DeprecatedString dates_path, CLDR& cldr)
{
- auto dates_iterator = TRY(path_to_dir_iterator(move(dates_path)));
-
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
@@ -152,13 +150,14 @@ static ErrorOr<void> parse_all_locales(DeprecatedString dates_path, CLDR& cldr)
return builder.to_deprecated_string();
};
- while (dates_iterator.has_next()) {
- auto dates_path = TRY(next_path_from_dir_iterator(dates_iterator));
+ TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
+ auto dates_path = LexicalPath::join(directory.path().string(), entry.name).string();
auto language = TRY(remove_variants_from_path(dates_path));
auto& locale = cldr.locales.ensure(language);
TRY(parse_date_fields(move(dates_path), cldr, locale));
- }
+ return IterationDecision::Continue;
+ }));
return {};
}