mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +00:00
AK: Use an enum instead of a bool for String::replace(all_occurences)
This commit has no behavior changes. In particular, this does not fix any of the wrong uses of the previous default parameter (which used to be 'false', meaning "only replace the first occurence in the string"). It simply replaces the default uses by String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
This commit is contained in:
parent
b2454888e8
commit
7ceeb74535
47 changed files with 108 additions and 102 deletions
|
@ -146,8 +146,8 @@ struct UnicodeData {
|
|||
|
||||
static String sanitize_entry(String const& entry)
|
||||
{
|
||||
auto sanitized = entry.replace("-", "_", true);
|
||||
sanitized = sanitized.replace(" ", "_", true);
|
||||
auto sanitized = entry.replace("-", "_", ReplaceMode::All);
|
||||
sanitized = sanitized.replace(" ", "_", ReplaceMode::All);
|
||||
|
||||
StringBuilder builder;
|
||||
bool next_is_upper = true;
|
||||
|
@ -229,7 +229,7 @@ static ErrorOr<void> parse_special_casing(Core::Stream::BufferedFile& file, Unic
|
|||
|
||||
if (!casing.locale.is_empty())
|
||||
casing.locale = String::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
|
||||
casing.condition = casing.condition.replace("_", "", true);
|
||||
casing.condition = casing.condition.replace("_", "", ReplaceMode::All);
|
||||
|
||||
if (!casing.condition.is_empty() && !unicode_data.conditions.contains_slow(casing.condition))
|
||||
unicode_data.conditions.append(casing.condition);
|
||||
|
|
|
@ -1088,14 +1088,14 @@ static void generate_missing_patterns(Calendar& calendar, CalendarPatternList& f
|
|||
auto time_pattern = locale_data.unique_strings.get(time_format);
|
||||
auto date_pattern = locale_data.unique_strings.get(date_format);
|
||||
|
||||
auto new_pattern = pattern.replace("{0}", time_pattern).replace("{1}", date_pattern);
|
||||
auto new_pattern = pattern.replace("{0}", time_pattern, ReplaceMode::FirstOnly).replace("{1}", date_pattern, ReplaceMode::FirstOnly);
|
||||
return locale_data.unique_strings.ensure(move(new_pattern));
|
||||
};
|
||||
|
||||
auto inject_fractional_second_digits = [&](auto format) {
|
||||
auto pattern = locale_data.unique_strings.get(format);
|
||||
|
||||
auto new_pattern = pattern.replace("{second}"sv, "{second}{decimal}{fractionalSecondDigits}"sv);
|
||||
auto new_pattern = pattern.replace("{second}"sv, "{second}{decimal}{fractionalSecondDigits}"sv, ReplaceMode::FirstOnly);
|
||||
return locale_data.unique_strings.ensure(move(new_pattern));
|
||||
};
|
||||
|
||||
|
@ -1606,8 +1606,8 @@ static ErrorOr<void> parse_all_locales(String core_path, String dates_path, Unic
|
|||
|
||||
static String format_identifier(StringView owner, String identifier)
|
||||
{
|
||||
identifier = identifier.replace("-"sv, "_"sv, true);
|
||||
identifier = identifier.replace("/"sv, "_"sv, true);
|
||||
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
|
||||
|
||||
if (all_of(identifier, is_ascii_digit))
|
||||
return String::formatted("{}_{}", owner[0], identifier);
|
||||
|
|
|
@ -57,7 +57,7 @@ constexpr auto s_list_pattern_list_index_type = "u8"sv;
|
|||
|
||||
static String format_identifier(StringView owner, String identifier)
|
||||
{
|
||||
identifier = identifier.replace("-"sv, "_"sv, true);
|
||||
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||
|
||||
if (all_of(identifier, is_ascii_digit))
|
||||
return String::formatted("{}_{}", owner[0], identifier);
|
||||
|
|
|
@ -340,7 +340,7 @@ static String parse_identifiers(String pattern, StringView replacement, UnicodeL
|
|||
utf8_pattern = utf8_pattern.substring_view(*start_index, *end_index - *start_index);
|
||||
utf8_pattern = utf8_pattern.trim(whitespace);
|
||||
|
||||
auto identifier = utf8_pattern.as_string().replace("'.'"sv, "."sv);
|
||||
auto identifier = utf8_pattern.as_string().replace("'.'"sv, "."sv, ReplaceMode::FirstOnly);
|
||||
auto identifier_index = locale_data.unique_strings.ensure(move(identifier));
|
||||
size_t replacement_index = 0;
|
||||
|
||||
|
@ -379,7 +379,7 @@ static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& loc
|
|||
};
|
||||
|
||||
for (auto const& replacement : replacements)
|
||||
pattern = pattern.replace(replacement.key, replacement.value, true);
|
||||
pattern = pattern.replace(replacement.key, replacement.value, ReplaceMode::All);
|
||||
|
||||
if (auto start_number_index = pattern.find_any_of("#0"sv, String::SearchDirection::Forward); start_number_index.has_value()) {
|
||||
auto end_number_index = *start_number_index + 1;
|
||||
|
@ -415,7 +415,7 @@ static void parse_number_pattern(Vector<String> patterns, UnicodeLocaleData& loc
|
|||
// This is specifically handled here rather than in the replacements HashMap above so
|
||||
// that we do not errantly replace zeroes in number patterns.
|
||||
if (pattern.contains(*replacements.get("E"sv)))
|
||||
pattern = pattern.replace("0"sv, "{scientificExponent}"sv);
|
||||
pattern = pattern.replace("0"sv, "{scientificExponent}"sv, ReplaceMode::FirstOnly);
|
||||
}
|
||||
|
||||
if (type == NumberFormatType::Compact)
|
||||
|
@ -677,11 +677,11 @@ static ErrorOr<void> parse_units(String locale_units_path, UnicodeLocaleData& lo
|
|||
auto plurality = unit_key.substring_view(unit_pattern_prefix.length());
|
||||
format.plurality = NumberFormat::plurality_from_string(plurality);
|
||||
|
||||
auto zero_format = pattern_value.as_string().replace("{0}"sv, "{number}"sv);
|
||||
auto zero_format = pattern_value.as_string().replace("{0}"sv, "{number}"sv, ReplaceMode::FirstOnly);
|
||||
zero_format = parse_identifiers(zero_format, "unitIdentifier"sv, locale_data, format);
|
||||
|
||||
format.positive_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{plusSign}{number}"sv));
|
||||
format.negative_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{minusSign}{number}"sv));
|
||||
format.positive_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{plusSign}{number}"sv, ReplaceMode::FirstOnly));
|
||||
format.negative_format_index = locale_data.unique_strings.ensure(zero_format.replace("{number}"sv, "{minusSign}{number}"sv, ReplaceMode::FirstOnly));
|
||||
format.zero_format_index = locale_data.unique_strings.ensure(move(zero_format));
|
||||
|
||||
formats.append(locale_data.unique_formats.ensure(move(format)));
|
||||
|
|
|
@ -464,7 +464,7 @@ void generate_mapping(SourceGenerator& generator, LocalesType const& locales, St
|
|||
String mapping_name;
|
||||
|
||||
if constexpr (IsNullPointer<IdentifierFormatter>)
|
||||
mapping_name = name.replace("-"sv, "_"sv, true);
|
||||
mapping_name = name.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||
else
|
||||
mapping_name = format_identifier(type, name);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue