mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:27:46 +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
|
@ -451,7 +451,7 @@ void endservent()
|
|||
static bool fill_getserv_buffers(char const* line, ssize_t read)
|
||||
{
|
||||
// Splitting the line by tab delimiter and filling the servent buffers name, port, and protocol members.
|
||||
auto split_line = StringView(line, read).replace(" ", "\t", true).split('\t');
|
||||
auto split_line = StringView(line, read).replace(" ", "\t", ReplaceMode::All).split('\t');
|
||||
|
||||
// This indicates an incorrect file format.
|
||||
// Services file entries should always at least contain
|
||||
|
@ -474,7 +474,7 @@ static bool fill_getserv_buffers(char const* line, ssize_t read)
|
|||
__getserv_port_buffer = number.value();
|
||||
|
||||
// Remove any annoying whitespace at the end of the protocol.
|
||||
__getserv_protocol_buffer = port_protocol_split[1].replace(" ", "", true).replace("\t", "", true).replace("\n", "", true);
|
||||
__getserv_protocol_buffer = port_protocol_split[1].replace(" ", "", ReplaceMode::All).replace("\t", "", ReplaceMode::All).replace("\n", "", ReplaceMode::All);
|
||||
__getserv_alias_list_buffer.clear();
|
||||
|
||||
// If there are aliases for the service, we will fill the alias list buffer.
|
||||
|
@ -630,7 +630,7 @@ void endprotoent()
|
|||
static bool fill_getproto_buffers(char const* line, ssize_t read)
|
||||
{
|
||||
String string_line = String(line, read);
|
||||
auto split_line = string_line.replace(" ", "\t", true).split('\t');
|
||||
auto split_line = string_line.replace(" ", "\t", ReplaceMode::All).split('\t');
|
||||
|
||||
// This indicates an incorrect file format. Protocols file entries should
|
||||
// always have at least a name and a protocol.
|
||||
|
|
|
@ -114,7 +114,7 @@ int __attribute__((weak)) tgetnum(char const* id)
|
|||
static Vector<char> s_tgoto_buffer;
|
||||
char* __attribute__((weak)) tgoto([[maybe_unused]] char const* cap, [[maybe_unused]] int col, [[maybe_unused]] int row)
|
||||
{
|
||||
auto cap_str = StringView(cap).replace("%p1%d", String::number(col)).replace("%p2%d", String::number(row));
|
||||
auto cap_str = StringView(cap).replace("%p1%d", String::number(col), ReplaceMode::FirstOnly).replace("%p2%d", String::number(row), ReplaceMode::FirstOnly);
|
||||
|
||||
s_tgoto_buffer.clear_with_capacity();
|
||||
s_tgoto_buffer.ensure_capacity(cap_str.length());
|
||||
|
|
|
@ -126,7 +126,7 @@ static Optional<String> resolve_library(String const& name, DynamicObject const&
|
|||
search_paths.append("/usr/local/lib"sv);
|
||||
|
||||
for (auto const& search_path : search_paths) {
|
||||
LexicalPath library_path(search_path.replace("$ORIGIN"sv, LexicalPath::dirname(parent_object.filepath())));
|
||||
LexicalPath library_path(search_path.replace("$ORIGIN"sv, LexicalPath::dirname(parent_object.filepath()), ReplaceMode::FirstOnly));
|
||||
String library_name = library_path.append(name).string();
|
||||
|
||||
if (access(library_name.characters(), F_OK) == 0)
|
||||
|
|
|
@ -128,7 +128,7 @@ String serialize_astring(StringView string)
|
|||
// Try to quote
|
||||
auto can_be_quoted = !(string.contains('\n') || string.contains('\r'));
|
||||
if (can_be_quoted) {
|
||||
auto escaped_str = string.replace("\\", "\\\\").replace("\"", "\\\"");
|
||||
auto escaped_str = string.replace("\\", "\\\\", ReplaceMode::FirstOnly).replace("\"", "\\\"", ReplaceMode::FirstOnly);
|
||||
return String::formatted("\"{}\"", escaped_str);
|
||||
}
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@ public:
|
|||
return {};
|
||||
// We need to modify the source to match what the lexer considers one line - normalizing
|
||||
// line terminators to \n is easier than splitting using all different LT characters.
|
||||
String source_string = source.replace("\r\n", "\n").replace("\r", "\n").replace(LINE_SEPARATOR_STRING, "\n").replace(PARAGRAPH_SEPARATOR_STRING, "\n");
|
||||
String source_string = source.replace("\r\n", "\n", ReplaceMode::FirstOnly).replace("\r", "\n", ReplaceMode::FirstOnly).replace(LINE_SEPARATOR_STRING, "\n", ReplaceMode::FirstOnly).replace(PARAGRAPH_SEPARATOR_STRING, "\n", ReplaceMode::FirstOnly);
|
||||
StringBuilder builder;
|
||||
builder.append(source_string.split_view('\n', true)[position.value().line - 1]);
|
||||
builder.append('\n');
|
||||
|
|
|
@ -217,7 +217,7 @@ Optional<Unicode::CalendarPattern> date_time_style_format(StringView data_locale
|
|||
return {};
|
||||
|
||||
// e. Let pattern be the string connector with the substring "{0}" replaced with timeFormat.[[pattern]] and the substring "{1}" replaced with dateFormat.[[pattern]].
|
||||
auto pattern = connector->pattern.replace("{0}"sv, time_format.pattern).replace("{1}"sv, date_format.pattern);
|
||||
auto pattern = connector->pattern.replace("{0}"sv, time_format.pattern, ReplaceMode::FirstOnly).replace("{1}"sv, date_format.pattern, ReplaceMode::FirstOnly);
|
||||
|
||||
// f. Set format.[[pattern]] to pattern.
|
||||
format.pattern = move(pattern);
|
||||
|
@ -225,7 +225,7 @@ Optional<Unicode::CalendarPattern> date_time_style_format(StringView data_locale
|
|||
// g. If timeFormat has a [[pattern12]] field, then
|
||||
if (time_format.pattern12.has_value()) {
|
||||
// i. Let pattern12 be the string connector with the substring "{0}" replaced with timeFormat.[[pattern12]] and the substring "{1}" replaced with dateFormat.[[pattern]].
|
||||
auto pattern12 = connector->pattern.replace("{0}"sv, *time_format.pattern12).replace("{1}"sv, date_format.pattern);
|
||||
auto pattern12 = connector->pattern.replace("{0}"sv, *time_format.pattern12, ReplaceMode::FirstOnly).replace("{1}"sv, date_format.pattern, ReplaceMode::FirstOnly);
|
||||
|
||||
// ii. Set format.[[pattern12]] to pattern12.
|
||||
format.pattern12 = move(pattern12);
|
||||
|
@ -1075,11 +1075,11 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
|
|||
auto const& pattern = date_time_format.pattern();
|
||||
|
||||
if (range_pattern->start_range.contains("{0}"sv)) {
|
||||
range_pattern->start_range = range_pattern->start_range.replace("{0}"sv, pattern);
|
||||
range_pattern->end_range = range_pattern->end_range.replace("{1}"sv, pattern);
|
||||
range_pattern->start_range = range_pattern->start_range.replace("{0}"sv, pattern, ReplaceMode::FirstOnly);
|
||||
range_pattern->end_range = range_pattern->end_range.replace("{1}"sv, pattern, ReplaceMode::FirstOnly);
|
||||
} else {
|
||||
range_pattern->start_range = range_pattern->start_range.replace("{1}"sv, pattern);
|
||||
range_pattern->end_range = range_pattern->end_range.replace("{0}"sv, pattern);
|
||||
range_pattern->start_range = range_pattern->start_range.replace("{1}"sv, pattern, ReplaceMode::FirstOnly);
|
||||
range_pattern->end_range = range_pattern->end_range.replace("{0}"sv, pattern, ReplaceMode::FirstOnly);
|
||||
}
|
||||
|
||||
// FIXME: The above is not sufficient. For example, if the start date is days before the end date, and only the timeStyle
|
||||
|
|
|
@ -299,10 +299,10 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(GlobalObject& g
|
|||
// here, but at some point we should split the the NumberFormat exporter to export both formats of the data.
|
||||
static String convert_number_format_pattern_to_duration_format_template(Unicode::NumberFormat const& number_format)
|
||||
{
|
||||
auto result = number_format.zero_format.replace("{number}", "{0}");
|
||||
auto result = number_format.zero_format.replace("{number}", "{0}", ReplaceMode::FirstOnly);
|
||||
|
||||
for (size_t i = 0; i < number_format.identifiers.size(); ++i)
|
||||
result = result.replace(String::formatted("{{unitIdentifier:{}}}", i), number_format.identifiers[i]);
|
||||
result = result.replace(String::formatted("{{unitIdentifier:{}}}", i), number_format.identifiers[i], ReplaceMode::FirstOnly);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -182,7 +182,7 @@ String RegExpObject::escape_regexp_pattern() const
|
|||
if (m_pattern.is_empty())
|
||||
return "(?:)";
|
||||
// FIXME: Check u flag and escape accordingly
|
||||
return m_pattern.replace("\n", "\\n", true).replace("\r", "\\r", true).replace(LINE_SEPARATOR_STRING, "\\u2028", true).replace(PARAGRAPH_SEPARATOR_STRING, "\\u2029", true).replace("/", "\\/", true);
|
||||
return m_pattern.replace("\n", "\\n", ReplaceMode::All).replace("\r", "\\r", ReplaceMode::All).replace(LINE_SEPARATOR_STRING, "\\u2028", ReplaceMode::All).replace(PARAGRAPH_SEPARATOR_STRING, "\\u2029", ReplaceMode::All).replace("/", "\\/", ReplaceMode::All);
|
||||
}
|
||||
|
||||
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate
|
||||
|
|
|
@ -970,7 +970,7 @@ static ThrowCompletionOr<Value> create_html(GlobalObject& global_object, Value s
|
|||
builder.append(' ');
|
||||
builder.append(attribute);
|
||||
builder.append("=\"");
|
||||
builder.append(value_string.replace("\"", """, true));
|
||||
builder.append(value_string.replace("\"", """, ReplaceMode::All));
|
||||
builder.append('"');
|
||||
}
|
||||
builder.append('>');
|
||||
|
|
|
@ -213,7 +213,7 @@ String Token::string_value(StringValueStatus& status) const
|
|||
// 12.8.6.2 Static Semantics: TRV, https://tc39.es/ecma262/#sec-static-semantics-trv
|
||||
String Token::raw_template_value() const
|
||||
{
|
||||
return value().replace("\r\n", "\n", true).replace("\r", "\n", true);
|
||||
return value().replace("\r\n", "\n", ReplaceMode::All).replace("\r", "\n", ReplaceMode::All);
|
||||
}
|
||||
|
||||
bool Token::bool_value() const
|
||||
|
|
|
@ -246,7 +246,7 @@ static Optional<String> format_time_zone_offset(StringView locale, CalendarPatte
|
|||
|
||||
// The digits used for hours, minutes and seconds fields in this format are the locale's default decimal digits.
|
||||
auto result = replace_digits_for_number_system(*number_system, builder.build());
|
||||
return formats->gmt_format.replace("{0}"sv, result);
|
||||
return formats->gmt_format.replace("{0}"sv, result, ReplaceMode::FirstOnly);
|
||||
}
|
||||
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Zone_Format_Terminology
|
||||
|
|
|
@ -816,7 +816,7 @@ Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id
|
|||
Optional<String> secondary_tag;
|
||||
|
||||
if (script.has_value() && region.has_value())
|
||||
secondary_tag = patterns->locale_separator.replace("{0}"sv, *script).replace("{1}"sv, *region);
|
||||
secondary_tag = patterns->locale_separator.replace("{0}"sv, *script, ReplaceMode::FirstOnly).replace("{1}"sv, *region, ReplaceMode::FirstOnly);
|
||||
else if (script.has_value())
|
||||
secondary_tag = *script;
|
||||
else if (region.has_value())
|
||||
|
@ -825,7 +825,7 @@ Optional<String> format_locale_for_display(StringView locale, LocaleID locale_id
|
|||
if (!secondary_tag.has_value())
|
||||
return primary_tag;
|
||||
|
||||
return patterns->locale_pattern.replace("{0}"sv, primary_tag).replace("{1}"sv, *secondary_tag);
|
||||
return patterns->locale_pattern.replace("{0}"sv, primary_tag, ReplaceMode::FirstOnly).replace("{1}"sv, *secondary_tag, ReplaceMode::FirstOnly);
|
||||
}
|
||||
|
||||
Optional<ListPatterns> __attribute__((weak)) get_locale_list_patterns(StringView, StringView, Style) { return {}; }
|
||||
|
|
|
@ -105,7 +105,7 @@ Optional<String> augment_currency_format_pattern([[maybe_unused]] StringView cur
|
|||
}
|
||||
|
||||
if (currency_key_with_spacing.has_value())
|
||||
return base_pattern.replace(currency_key, *currency_key_with_spacing);
|
||||
return base_pattern.replace(currency_key, *currency_key_with_spacing, ReplaceMode::FirstOnly);
|
||||
#endif
|
||||
|
||||
return {};
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -276,16 +276,16 @@ static DOM::ExceptionOr<String> serialize_an_attribute_value(String const& attri
|
|||
auto final_attribute_value = attribute_value;
|
||||
|
||||
// 1. "&" with "&"
|
||||
final_attribute_value = final_attribute_value.replace("&"sv, "&"sv, true);
|
||||
final_attribute_value = final_attribute_value.replace("&"sv, "&"sv, ReplaceMode::All);
|
||||
|
||||
// 2. """ with """
|
||||
final_attribute_value = final_attribute_value.replace("\""sv, """sv, true);
|
||||
final_attribute_value = final_attribute_value.replace("\""sv, """sv, ReplaceMode::All);
|
||||
|
||||
// 3. "<" with "<"
|
||||
final_attribute_value = final_attribute_value.replace("<"sv, "<"sv, true);
|
||||
final_attribute_value = final_attribute_value.replace("<"sv, "<"sv, ReplaceMode::All);
|
||||
|
||||
// 4. ">" with ">"
|
||||
final_attribute_value = final_attribute_value.replace(">"sv, ">"sv, true);
|
||||
final_attribute_value = final_attribute_value.replace(">"sv, ">"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 "&".
|
||||
markup = markup.replace("&"sv, "&"sv, true);
|
||||
markup = markup.replace("&"sv, "&"sv, ReplaceMode::All);
|
||||
|
||||
// 4. Replace any occurrences of "<" in markup by "<".
|
||||
markup = markup.replace("<"sv, "<"sv, true);
|
||||
markup = markup.replace("<"sv, "<"sv, ReplaceMode::All);
|
||||
|
||||
// 5. Replace any occurrences of ">" in markup by ">".
|
||||
markup = markup.replace(">"sv, ">"sv, true);
|
||||
markup = markup.replace(">"sv, ">"sv, ReplaceMode::All);
|
||||
|
||||
// 6. Return the value of markup.
|
||||
return markup;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -150,7 +150,7 @@ private:
|
|||
[this, position = m_lexer.tell(), location] {
|
||||
m_lexer.retreat(m_lexer.tell() - position);
|
||||
(void)location;
|
||||
dbgln_if(XML_PARSER_DEBUG, "{:->{}}FAIL @ {} -- \x1b[31m{}\x1b[0m", " ", s_debug_indent_level * 2, location, m_lexer.remaining().substring_view(0, min(16, m_lexer.tell_remaining())).replace("\n", "\\n", true));
|
||||
dbgln_if(XML_PARSER_DEBUG, "{:->{}}FAIL @ {} -- \x1b[31m{}\x1b[0m", " ", s_debug_indent_level * 2, location, m_lexer.remaining().substring_view(0, min(16, m_lexer.tell_remaining())).replace("\n", "\\n", ReplaceMode::All));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue