mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 02:40:49 +00:00
AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.
As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
This commit is contained in:
@@ -507,7 +507,7 @@ static void parse_all_locales(String core_path, String locale_names_path, String
|
||||
|
||||
static String format_identifier(StringView owner, String identifier)
|
||||
{
|
||||
identifier.replace("-"sv, "_"sv, true);
|
||||
identifier = identifier.replace("-"sv, "_"sv, true);
|
||||
|
||||
if (all_of(identifier, is_ascii_digit))
|
||||
return String::formatted("{}_{}", owner[0], identifier);
|
||||
@@ -638,8 +638,7 @@ struct Patterns {
|
||||
)~~~");
|
||||
|
||||
auto format_mapping_name = [](StringView format, StringView name) {
|
||||
auto mapping_name = name.to_lowercase_string();
|
||||
mapping_name.replace("-"sv, "_"sv, true);
|
||||
auto mapping_name = name.to_lowercase_string().replace("-"sv, "_"sv, true);
|
||||
return String::formatted(format, mapping_name);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user