1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:57:35 +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:
DexesTTP 2022-07-05 22:33:15 +02:00 committed by Linus Groh
parent b2454888e8
commit 7ceeb74535
47 changed files with 108 additions and 102 deletions

View file

@ -2883,7 +2883,7 @@ Optional<UnicodeRange> Parser::parse_unicode_range(StringView text)
// 2. Interpret the consumed code points as a hexadecimal number,
// with the U+003F QUESTION MARK (?) code points replaced by U+0030 DIGIT ZERO (0) code points.
// This is the start value.
auto start_value_string = start_value_code_points.replace("?", "0", true);
auto start_value_string = start_value_code_points.replace("?", "0", ReplaceMode::All);
auto maybe_start_value = AK::StringUtils::convert_to_uint_from_hex<u32>(start_value_string);
if (!maybe_start_value.has_value()) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: <urange> ?-converted start value did not parse as hex number.");
@ -2894,7 +2894,7 @@ Optional<UnicodeRange> Parser::parse_unicode_range(StringView text)
// 3. Interpret the consumed code points as a hexadecimal number again,
// with the U+003F QUESTION MARK (?) code points replaced by U+0046 LATIN CAPITAL LETTER F (F) code points.
// This is the end value.
auto end_value_string = start_value_code_points.replace("?", "F", true);
auto end_value_string = start_value_code_points.replace("?", "F", ReplaceMode::All);
auto maybe_end_value = AK::StringUtils::convert_to_uint_from_hex<u32>(end_value_string);
if (!maybe_end_value.has_value()) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: <urange> ?-converted end value did not parse as hex number.");

View file

@ -276,16 +276,16 @@ static DOM::ExceptionOr<String> serialize_an_attribute_value(String const& attri
auto final_attribute_value = attribute_value;
// 1. "&" with "&amp;"
final_attribute_value = final_attribute_value.replace("&"sv, "&amp;"sv, true);
final_attribute_value = final_attribute_value.replace("&"sv, "&amp;"sv, ReplaceMode::All);
// 2. """ with "&quot;"
final_attribute_value = final_attribute_value.replace("\""sv, "&quot;"sv, true);
final_attribute_value = final_attribute_value.replace("\""sv, "&quot;"sv, ReplaceMode::All);
// 3. "<" with "&lt;"
final_attribute_value = final_attribute_value.replace("<"sv, "&lt;"sv, true);
final_attribute_value = final_attribute_value.replace("<"sv, "&lt;"sv, ReplaceMode::All);
// 4. ">" with "&gt;"
final_attribute_value = final_attribute_value.replace(">"sv, "&gt;"sv, true);
final_attribute_value = final_attribute_value.replace(">"sv, "&gt;"sv, ReplaceMode::All);
return final_attribute_value;
}
@ -736,13 +736,13 @@ static DOM::ExceptionOr<String> serialize_text(DOM::Text const& text, [[maybe_un
String markup = text.data();
// 3. Replace any occurrences of "&" in markup by "&amp;".
markup = markup.replace("&"sv, "&amp;"sv, true);
markup = markup.replace("&"sv, "&amp;"sv, ReplaceMode::All);
// 4. Replace any occurrences of "<" in markup by "&lt;".
markup = markup.replace("<"sv, "&lt;"sv, true);
markup = markup.replace("<"sv, "&lt;"sv, ReplaceMode::All);
// 5. Replace any occurrences of ">" in markup by "&gt;".
markup = markup.replace(">"sv, "&gt;"sv, true);
markup = markup.replace(">"sv, "&gt;"sv, ReplaceMode::All);
// 6. Return the value of markup.
return markup;

View file

@ -54,7 +54,7 @@ Vector<QueryParam> url_decode(StringView input)
}
// 4. Replace any 0x2B (+) in name and value with 0x20 (SP).
auto space_decoded_name = name.replace("+"sv, " "sv, true);
auto space_decoded_name = name.replace("+"sv, " "sv, ReplaceMode::All);
// 5. Let nameString and valueString be the result of running UTF-8 decode without BOM on the percent-decoding of name and value, respectively.
auto name_string = AK::URL::percent_decode(space_decoded_name);