diff options
author | DexesTTP <dexes.ttp@gmail.com> | 2022-07-05 22:33:15 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-06 11:12:45 +0200 |
commit | 7ceeb745354e246ec91cbdcd6f17c8291c09aec0 (patch) | |
tree | ff0acc8f5603d392e0f0b82793df40b257e284ea /Userland/Libraries/LibJS | |
parent | b2454888e8fa44775456536a2a71827763cba503 (diff) | |
download | serenity-7ceeb745354e246ec91cbdcd6f17c8291c09aec0.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Parser.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/RegExpObject.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Token.cpp | 2 |
6 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Parser.h b/Userland/Libraries/LibJS/Parser.h index 1f017bfbdd..39a91c0cf3 100644 --- a/Userland/Libraries/LibJS/Parser.h +++ b/Userland/Libraries/LibJS/Parser.h @@ -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'); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index 10e15fe888..d18eba5ca0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -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 diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index de87767965..2e0635b455 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -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; } diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp index e27433a2f0..cfbfbc3063 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.cpp @@ -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 diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index f8a55b8e3c..7484610a63 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -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('>'); diff --git a/Userland/Libraries/LibJS/Token.cpp b/Userland/Libraries/LibJS/Token.cpp index 1d84a4aeaf..cca3375778 100644 --- a/Userland/Libraries/LibJS/Token.cpp +++ b/Userland/Libraries/LibJS/Token.cpp @@ -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 |