mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 06:38:10 +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
|
@ -211,7 +211,7 @@ static void parse_dst_rule(StringView segment, TimeZoneOffset& time_zone)
|
|||
|
||||
static void parse_format(StringView format, TimeZoneData& time_zone_data, TimeZoneOffset& time_zone)
|
||||
{
|
||||
auto formats = format.replace("%s"sv, "{}"sv).split('/');
|
||||
auto formats = format.replace("%s"sv, "{}"sv, ReplaceMode::FirstOnly).split('/');
|
||||
VERIFY(formats.size() <= 2);
|
||||
|
||||
time_zone.standard_format = time_zone_data.unique_strings.ensure(formats[0]);
|
||||
|
@ -422,8 +422,8 @@ 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);
|
||||
|
@ -690,7 +690,7 @@ Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone,
|
|||
|
||||
auto format_name = [](auto format, auto offset) -> String {
|
||||
if (offset == 0)
|
||||
return s_string_list[format].replace("{}"sv, ""sv);
|
||||
return s_string_list[format].replace("{}"sv, ""sv, ReplaceMode::FirstOnly);
|
||||
return String::formatted(s_string_list[format], s_string_list[offset]);
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ String camel_casify(StringView dashy_name)
|
|||
|
||||
String snake_casify(String const& dashy_name)
|
||||
{
|
||||
return dashy_name.replace("-", "_", true);
|
||||
return dashy_name.replace("-", "_", ReplaceMode::All);
|
||||
}
|
||||
|
||||
ErrorOr<JsonValue> read_entire_file_as_json(StringView filename)
|
||||
|
|
|
@ -153,7 +153,7 @@ static String make_input_acceptable_cpp(String const& input)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
return input.replace("-", "_");
|
||||
return input.replace("-", "_", ReplaceMode::FirstOnly);
|
||||
}
|
||||
|
||||
static void generate_include_for_wrapper(auto& generator, auto& wrapper_name)
|
||||
|
@ -237,7 +237,7 @@ static void emit_includes_for_all_imports(auto& interface, auto& generator, bool
|
|||
|
||||
if (is_iterator) {
|
||||
auto iterator_name = String::formatted("{}Iterator", interface->name);
|
||||
auto iterator_path = String::formatted("{}Iterator", interface->fully_qualified_name.replace("::", "/"));
|
||||
auto iterator_path = String::formatted("{}Iterator", interface->fully_qualified_name.replace("::", "/", ReplaceMode::FirstOnly));
|
||||
generate_include_for_iterator(generator, iterator_path, iterator_name);
|
||||
}
|
||||
|
||||
|
@ -3635,7 +3635,7 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface)
|
|||
generator.set("prototype_class", String::formatted("{}IteratorPrototype", interface.name));
|
||||
generator.set("wrapper_class", String::formatted("{}IteratorWrapper", interface.name));
|
||||
generator.set("fully_qualified_name", String::formatted("{}Iterator", interface.fully_qualified_name));
|
||||
generator.set("possible_include_path", String::formatted("{}Iterator", interface.name.replace("::", "/")));
|
||||
generator.set("possible_include_path", String::formatted("{}Iterator", interface.name.replace("::", "/", ReplaceMode::FirstOnly)));
|
||||
|
||||
generator.append(R"~~~(
|
||||
#include <AK/Function.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue