diff options
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Base64.cpp | 4 | ||||
-rw-r--r-- | AK/Base64.h | 4 | ||||
-rw-r--r-- | AK/DateTimeLexer.h | 2 | ||||
-rw-r--r-- | AK/Demangle.h | 2 | ||||
-rw-r--r-- | AK/FlyString.cpp | 10 | ||||
-rw-r--r-- | AK/FlyString.h | 12 | ||||
-rw-r--r-- | AK/GenericLexer.h | 6 | ||||
-rw-r--r-- | AK/Hex.cpp | 2 | ||||
-rw-r--r-- | AK/Hex.h | 2 | ||||
-rw-r--r-- | AK/IPv4Address.h | 2 | ||||
-rw-r--r-- | AK/JsonArraySerializer.h | 2 | ||||
-rw-r--r-- | AK/JsonObjectSerializer.h | 30 | ||||
-rw-r--r-- | AK/JsonParser.h | 2 | ||||
-rw-r--r-- | AK/JsonPath.h | 2 | ||||
-rw-r--r-- | AK/JsonValue.cpp | 2 | ||||
-rw-r--r-- | AK/JsonValue.h | 2 | ||||
-rw-r--r-- | AK/LexicalPath.cpp | 6 | ||||
-rw-r--r-- | AK/LexicalPath.h | 14 | ||||
-rw-r--r-- | AK/MACAddress.h | 2 | ||||
-rw-r--r-- | AK/String.cpp | 18 | ||||
-rw-r--r-- | AK/String.h | 34 | ||||
-rw-r--r-- | AK/StringBuilder.cpp | 4 | ||||
-rw-r--r-- | AK/StringBuilder.h | 4 | ||||
-rw-r--r-- | AK/StringUtils.cpp | 72 | ||||
-rw-r--r-- | AK/StringUtils.h | 42 | ||||
-rw-r--r-- | AK/StringView.cpp | 20 | ||||
-rw-r--r-- | AK/StringView.h | 38 | ||||
-rw-r--r-- | AK/URL.cpp | 12 | ||||
-rw-r--r-- | AK/URL.h | 12 | ||||
-rw-r--r-- | AK/URLParser.cpp | 20 | ||||
-rw-r--r-- | AK/URLParser.h | 4 | ||||
-rw-r--r-- | AK/UUID.cpp | 4 | ||||
-rw-r--r-- | AK/UUID.h | 4 | ||||
-rw-r--r-- | AK/Utf16View.cpp | 2 | ||||
-rw-r--r-- | AK/Utf16View.h | 2 | ||||
-rw-r--r-- | AK/Utf8View.h | 2 |
36 files changed, 201 insertions, 201 deletions
diff --git a/AK/Base64.cpp b/AK/Base64.cpp index 4d0a419f4a..f9d321ee38 100644 --- a/AK/Base64.cpp +++ b/AK/Base64.cpp @@ -38,7 +38,7 @@ static constexpr auto make_lookup_table() return table; } -size_t calculate_base64_decoded_length(const StringView& input) +size_t calculate_base64_decoded_length(StringView input) { return input.length() * 3 / 4; } @@ -48,7 +48,7 @@ size_t calculate_base64_encoded_length(ReadonlyBytes input) return ((4 * input.size() / 3) + 3) & ~3; } -Optional<ByteBuffer> decode_base64(const StringView& input) +Optional<ByteBuffer> decode_base64(StringView input) { auto get = [&](const size_t offset, bool* is_padding) -> Optional<u8> { constexpr auto table = make_lookup_table(); diff --git a/AK/Base64.h b/AK/Base64.h index c1c5388629..d4c6de40f8 100644 --- a/AK/Base64.h +++ b/AK/Base64.h @@ -13,11 +13,11 @@ namespace AK { -size_t calculate_base64_decoded_length(const StringView&); +size_t calculate_base64_decoded_length(StringView); size_t calculate_base64_encoded_length(ReadonlyBytes); -Optional<ByteBuffer> decode_base64(const StringView&); +Optional<ByteBuffer> decode_base64(StringView); String encode_base64(ReadonlyBytes); diff --git a/AK/DateTimeLexer.h b/AK/DateTimeLexer.h index 51de0c4266..98c81b78f6 100644 --- a/AK/DateTimeLexer.h +++ b/AK/DateTimeLexer.h @@ -14,7 +14,7 @@ namespace AK { class DateTimeLexer : public GenericLexer { public: - constexpr explicit DateTimeLexer(const StringView& input) + constexpr explicit DateTimeLexer(StringView input) : GenericLexer(input) { } diff --git a/AK/Demangle.h b/AK/Demangle.h index 9e41dc949c..c04df9e674 100644 --- a/AK/Demangle.h +++ b/AK/Demangle.h @@ -12,7 +12,7 @@ namespace AK { -inline String demangle(const StringView& name) +inline String demangle(StringView name) { int status = 0; auto* demangled_name = abi::__cxa_demangle(name.to_string().characters(), nullptr, nullptr, &status); diff --git a/AK/FlyString.cpp b/AK/FlyString.cpp index ecf3a31df8..20b8e2ab04 100644 --- a/AK/FlyString.cpp +++ b/AK/FlyString.cpp @@ -55,7 +55,7 @@ FlyString::FlyString(const String& string) } } -FlyString::FlyString(StringView const& string) +FlyString::FlyString(StringView string) { if (string.is_null()) return; @@ -95,17 +95,17 @@ template Optional<u16> FlyString::to_uint(TrimWhitespace) const; template Optional<u32> FlyString::to_uint(TrimWhitespace) const; template Optional<u64> FlyString::to_uint(TrimWhitespace) const; -bool FlyString::equals_ignoring_case(const StringView& other) const +bool FlyString::equals_ignoring_case(StringView other) const { return StringUtils::equals_ignoring_case(view(), other); } -bool FlyString::starts_with(const StringView& str, CaseSensitivity case_sensitivity) const +bool FlyString::starts_with(StringView str, CaseSensitivity case_sensitivity) const { return StringUtils::starts_with(view(), str, case_sensitivity); } -bool FlyString::ends_with(const StringView& str, CaseSensitivity case_sensitivity) const +bool FlyString::ends_with(StringView str, CaseSensitivity case_sensitivity) const { return StringUtils::ends_with(view(), str, case_sensitivity); } @@ -132,7 +132,7 @@ bool FlyString::operator==(const String& other) const return !__builtin_memcmp(characters(), other.characters(), length()); } -bool FlyString::operator==(const StringView& string) const +bool FlyString::operator==(StringView string) const { return *this == String(string); } diff --git a/AK/FlyString.h b/AK/FlyString.h index d91e94c68b..8c8d55dad0 100644 --- a/AK/FlyString.h +++ b/AK/FlyString.h @@ -23,7 +23,7 @@ public: { } FlyString(const String&); - FlyString(const StringView&); + FlyString(StringView); FlyString(const char* string) : FlyString(static_cast<String>(string)) { @@ -58,8 +58,8 @@ public: bool operator==(const String&) const; bool operator!=(const String& string) const { return !(*this == string); } - bool operator==(const StringView&) const; - bool operator!=(const StringView& string) const { return !(*this == string); } + bool operator==(StringView) const; + bool operator!=(StringView string) const { return !(*this == string); } bool operator==(const char*) const; bool operator!=(const char* string) const { return !(*this == string); } @@ -78,9 +78,9 @@ public: template<typename T = unsigned> Optional<T> to_uint(TrimWhitespace = TrimWhitespace::Yes) const; - bool equals_ignoring_case(const StringView&) const; - bool starts_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; - bool ends_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + bool equals_ignoring_case(StringView) const; + bool starts_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + bool ends_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; static void did_destroy_impl(Badge<StringImpl>, StringImpl&); diff --git a/AK/GenericLexer.h b/AK/GenericLexer.h index 7a01060068..0a44bffc65 100644 --- a/AK/GenericLexer.h +++ b/AK/GenericLexer.h @@ -13,7 +13,7 @@ namespace AK { class GenericLexer { public: - constexpr explicit GenericLexer(const StringView& input) + constexpr explicit GenericLexer(StringView input) : m_input(input) { } @@ -93,7 +93,7 @@ public: return consume_specific(StringView { next }); } - constexpr char consume_escaped_character(char escape_char = '\\', const StringView& escape_map = "n\nr\rt\tb\bf\f") + constexpr char consume_escaped_character(char escape_char = '\\', StringView escape_map = "n\nr\rt\tb\bf\f") { if (!consume_specific(escape_char)) return consume(); @@ -215,7 +215,7 @@ private: Result<u32, UnicodeEscapeError> decode_single_or_paired_surrogate(bool combine_surrogate_pairs); }; -constexpr auto is_any_of(const StringView& values) +constexpr auto is_any_of(StringView values) { return [values](auto c) { return values.contains(c); }; } diff --git a/AK/Hex.cpp b/AK/Hex.cpp index 099b96eb5f..7e8cd99d86 100644 --- a/AK/Hex.cpp +++ b/AK/Hex.cpp @@ -15,7 +15,7 @@ namespace AK { -Optional<ByteBuffer> decode_hex(const StringView& input) +Optional<ByteBuffer> decode_hex(StringView input) { if ((input.length() % 2) != 0) return {}; @@ -24,7 +24,7 @@ constexpr u8 decode_hex_digit(char digit) return 255; } -Optional<ByteBuffer> decode_hex(const StringView&); +Optional<ByteBuffer> decode_hex(StringView); String encode_hex(ReadonlyBytes); diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index 09ea8e8200..3c0f76f6b9 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -66,7 +66,7 @@ public: octet(SubnetClass::A)); } - static Optional<IPv4Address> from_string(const StringView& string) + static Optional<IPv4Address> from_string(StringView string) { if (string.is_null()) return {}; diff --git a/AK/JsonArraySerializer.h b/AK/JsonArraySerializer.h index 38cb744f85..fa0f3086af 100644 --- a/AK/JsonArraySerializer.h +++ b/AK/JsonArraySerializer.h @@ -39,7 +39,7 @@ public: } #endif - void add(const StringView& value) + void add(StringView value) { begin_item(); (void)m_builder.append('"'); diff --git a/AK/JsonObjectSerializer.h b/AK/JsonObjectSerializer.h index 52831ed268..804ae09732 100644 --- a/AK/JsonObjectSerializer.h +++ b/AK/JsonObjectSerializer.h @@ -33,14 +33,14 @@ public: } #ifndef KERNEL - void add(const StringView& key, const JsonValue& value) + void add(StringView key, const JsonValue& value) { begin_item(key); value.serialize(m_builder); } #endif - void add(const StringView& key, const StringView& value) + void add(StringView key, StringView value) { begin_item(key); (void)m_builder.append('"'); @@ -48,7 +48,7 @@ public: (void)m_builder.append('"'); } - void add(const StringView& key, const String& value) + void add(StringView key, const String& value) { begin_item(key); (void)m_builder.append('"'); @@ -56,7 +56,7 @@ public: (void)m_builder.append('"'); } - void add(const StringView& key, const char* value) + void add(StringView key, const char* value) { begin_item(key); (void)m_builder.append('"'); @@ -64,63 +64,63 @@ public: (void)m_builder.append('"'); } - void add(const StringView& key, bool value) + void add(StringView key, bool value) { begin_item(key); (void)m_builder.append(value ? "true" : "false"); } - void add(const StringView& key, int value) + void add(StringView key, int value) { begin_item(key); (void)m_builder.appendff("{}", value); } - void add(const StringView& key, unsigned value) + void add(StringView key, unsigned value) { begin_item(key); (void)m_builder.appendff("{}", value); } - void add(const StringView& key, long value) + void add(StringView key, long value) { begin_item(key); (void)m_builder.appendff("{}", value); } - void add(const StringView& key, long unsigned value) + void add(StringView key, long unsigned value) { begin_item(key); (void)m_builder.appendff("{}", value); } - void add(const StringView& key, long long value) + void add(StringView key, long long value) { begin_item(key); (void)m_builder.appendff("{}", value); } - void add(const StringView& key, long long unsigned value) + void add(StringView key, long long unsigned value) { begin_item(key); (void)m_builder.appendff("{}", value); } #ifndef KERNEL - void add(const StringView& key, double value) + void add(StringView key, double value) { begin_item(key); (void)m_builder.appendff("{}", value); } #endif - JsonArraySerializer<Builder> add_array(const StringView& key) + JsonArraySerializer<Builder> add_array(StringView key) { begin_item(key); return JsonArraySerializer(m_builder); } - JsonObjectSerializer<Builder> add_object(const StringView& key) + JsonObjectSerializer<Builder> add_object(StringView key) { begin_item(key); return JsonObjectSerializer(m_builder); @@ -134,7 +134,7 @@ public: } private: - void begin_item(const StringView& key) + void begin_item(StringView key) { if (!m_empty) (void)m_builder.append(','); diff --git a/AK/JsonParser.h b/AK/JsonParser.h index 4d4ed19694..475903f76b 100644 --- a/AK/JsonParser.h +++ b/AK/JsonParser.h @@ -13,7 +13,7 @@ namespace AK { class JsonParser : private GenericLexer { public: - explicit JsonParser(const StringView& input) + explicit JsonParser(StringView input) : GenericLexer(input) { } diff --git a/AK/JsonPath.h b/AK/JsonPath.h index 0ae3f0f3ed..ab93c2d8ca 100644 --- a/AK/JsonPath.h +++ b/AK/JsonPath.h @@ -27,7 +27,7 @@ public: { } - JsonPathElement(const StringView& key) + JsonPathElement(StringView key) : m_kind(Kind::Key) , m_key(key) { diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp index 439b8f1859..184649b308 100644 --- a/AK/JsonValue.cpp +++ b/AK/JsonValue.cpp @@ -228,7 +228,7 @@ void JsonValue::clear() } #ifndef KERNEL -Optional<JsonValue> JsonValue::from_string(const StringView& input) +Optional<JsonValue> JsonValue::from_string(StringView input) { return JsonParser(input).parse(); } diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 9783b78ac3..b8b1b0b6d3 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -30,7 +30,7 @@ public: Object, }; - static Optional<JsonValue> from_string(const StringView&); + static Optional<JsonValue> from_string(StringView); explicit JsonValue(Type = Type::Null); ~JsonValue() { clear(); } diff --git a/AK/LexicalPath.cpp b/AK/LexicalPath.cpp index 7a4afdf2ec..7864c13983 100644 --- a/AK/LexicalPath.cpp +++ b/AK/LexicalPath.cpp @@ -67,7 +67,7 @@ Vector<String> LexicalPath::parts() const return vector; } -bool LexicalPath::has_extension(StringView const& extension) const +bool LexicalPath::has_extension(StringView extension) const { return m_string.ends_with(extension, CaseSensitivity::CaseInsensitive); } @@ -129,7 +129,7 @@ String LexicalPath::absolute_path(String dir_path, String target) return LexicalPath::canonicalized_path(join(dir_path, target).string()); } -String LexicalPath::relative_path(StringView const& a_path, StringView const& a_prefix) +String LexicalPath::relative_path(StringView a_path, StringView a_prefix) { if (!a_path.starts_with('/') || !a_prefix.starts_with('/')) { // FIXME: This should probably VERIFY or return an Optional<String>. @@ -159,7 +159,7 @@ String LexicalPath::relative_path(StringView const& a_path, StringView const& a_ return path; } -LexicalPath LexicalPath::append(StringView const& value) const +LexicalPath LexicalPath::append(StringView value) const { return LexicalPath::join(m_string, value); } diff --git a/AK/LexicalPath.h b/AK/LexicalPath.h index 562adbe83b..98e11a97c0 100644 --- a/AK/LexicalPath.h +++ b/AK/LexicalPath.h @@ -19,22 +19,22 @@ public: bool is_absolute() const { return !m_string.is_empty() && m_string[0] == '/'; } String const& string() const { return m_string; } - StringView const& dirname() const { return m_dirname; } - StringView const& basename() const { return m_basename; } - StringView const& title() const { return m_title; } - StringView const& extension() const { return m_extension; } + StringView dirname() const { return m_dirname; } + StringView basename() const { return m_basename; } + StringView title() const { return m_title; } + StringView extension() const { return m_extension; } Vector<StringView> const& parts_view() const { return m_parts; } [[nodiscard]] Vector<String> parts() const; - bool has_extension(StringView const&) const; + bool has_extension(StringView) const; - [[nodiscard]] LexicalPath append(StringView const&) const; + [[nodiscard]] LexicalPath append(StringView) const; [[nodiscard]] LexicalPath parent() const; [[nodiscard]] static String canonicalized_path(String); [[nodiscard]] static String absolute_path(String dir_path, String target); - [[nodiscard]] static String relative_path(StringView const& absolute_path, StringView const& prefix); + [[nodiscard]] static String relative_path(StringView absolute_path, StringView prefix); template<typename... S> [[nodiscard]] static LexicalPath join(StringView first, S&&... rest) diff --git a/AK/MACAddress.h b/AK/MACAddress.h index bcac9c8eec..32e32c1bf9 100644 --- a/AK/MACAddress.h +++ b/AK/MACAddress.h @@ -58,7 +58,7 @@ public: return String::formatted("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", m_data[0], m_data[1], m_data[2], m_data[3], m_data[4], m_data[5]); } - static Optional<MACAddress> from_string(const StringView& string) + static Optional<MACAddress> from_string(StringView string) { if (string.is_null()) return {}; diff --git a/AK/String.cpp b/AK/String.cpp index a37ab8095a..a3bb45c5b4 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -31,7 +31,7 @@ bool String::operator==(const String& other) const return *m_impl == *other.m_impl; } -bool String::operator==(const StringView& other) const +bool String::operator==(StringView other) const { if (!m_impl) return !other.m_characters; @@ -202,7 +202,7 @@ template Optional<u16> String::to_uint(TrimWhitespace) const; template Optional<u32> String::to_uint(TrimWhitespace) const; template Optional<u64> String::to_uint(TrimWhitespace) const; -bool String::starts_with(const StringView& str, CaseSensitivity case_sensitivity) const +bool String::starts_with(StringView str, CaseSensitivity case_sensitivity) const { return StringUtils::starts_with(*this, str, case_sensitivity); } @@ -214,7 +214,7 @@ bool String::starts_with(char ch) const return characters()[0] == ch; } -bool String::ends_with(const StringView& str, CaseSensitivity case_sensitivity) const +bool String::ends_with(StringView str, CaseSensitivity case_sensitivity) const { return StringUtils::ends_with(*this, str, case_sensitivity); } @@ -236,7 +236,7 @@ String String::repeated(char ch, size_t count) return *impl; } -String String::repeated(const StringView& string, size_t count) +String String::repeated(StringView string, size_t count) { if (!count || string.is_empty()) return empty(); @@ -327,17 +327,17 @@ String String::roman_number_from(size_t value) return builder.to_string(); } -bool String::matches(const StringView& mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const +bool String::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const { return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans); } -bool String::matches(const StringView& mask, CaseSensitivity case_sensitivity) const +bool String::matches(StringView mask, CaseSensitivity case_sensitivity) const { return StringUtils::matches(*this, mask, case_sensitivity); } -bool String::contains(const StringView& needle, CaseSensitivity case_sensitivity) const +bool String::contains(StringView needle, CaseSensitivity case_sensitivity) const { return StringUtils::contains(*this, needle, case_sensitivity); } @@ -347,7 +347,7 @@ bool String::contains(char needle, CaseSensitivity case_sensitivity) const return StringUtils::contains(*this, StringView(&needle, 1), case_sensitivity); } -bool String::equals_ignoring_case(const StringView& other) const +bool String::equals_ignoring_case(StringView other) const { return StringUtils::equals_ignoring_case(view(), other); } @@ -361,7 +361,7 @@ String String::reverse() const return reversed_string.to_string(); } -String escape_html_entities(const StringView& html) +String escape_html_entities(StringView html) { StringBuilder builder; for (size_t i = 0; i < html.length(); ++i) { diff --git a/AK/String.h b/AK/String.h index 97d8dab0cc..065c1e85f3 100644 --- a/AK/String.h +++ b/AK/String.h @@ -43,7 +43,7 @@ public: String() = default; - String(const StringView& view) + String(StringView view) { m_impl = StringImpl::create(view.characters_without_null_termination(), view.length()); } @@ -96,7 +96,7 @@ public: String(const FlyString&); [[nodiscard]] static String repeated(char, size_t count); - [[nodiscard]] static String repeated(const StringView&, size_t count); + [[nodiscard]] static String repeated(StringView, size_t count); [[nodiscard]] static String bijective_base_from(size_t value, unsigned base = 26, StringView map = {}); [[nodiscard]] static String roman_number_from(size_t value); @@ -109,8 +109,8 @@ public: return builder.build(); } - [[nodiscard]] bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; - [[nodiscard]] bool matches(const StringView& mask, Vector<MaskSpan>&, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; + [[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; + [[nodiscard]] bool matches(StringView mask, Vector<MaskSpan>&, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; template<typename T = int> [[nodiscard]] Optional<T> to_int(TrimWhitespace = TrimWhitespace::Yes) const; @@ -125,7 +125,7 @@ public: [[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); } #ifndef KERNEL - [[nodiscard]] String trim(const StringView& characters, TrimMode mode = TrimMode::Both) const + [[nodiscard]] String trim(StringView characters, TrimMode mode = TrimMode::Both) const { return StringUtils::trim(view(), characters, mode); } @@ -136,9 +136,9 @@ public: } #endif - [[nodiscard]] bool equals_ignoring_case(const StringView&) const; + [[nodiscard]] bool equals_ignoring_case(StringView) const; - [[nodiscard]] bool contains(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; [[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const; [[nodiscard]] Vector<String> split_limit(char separator, size_t limit, bool keep_empty = false) const; @@ -146,12 +146,12 @@ public: [[nodiscard]] Vector<StringView> split_view(char separator, bool keep_empty = false) const; [[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } - [[nodiscard]] Optional<size_t> find(StringView const& needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } + [[nodiscard]] Optional<size_t> find(StringView needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } [[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); } - // FIXME: Implement find_last(StringView const&) for API symmetry. + // FIXME: Implement find_last(StringView) for API symmetry. Vector<size_t> find_all(StringView needle) const; using SearchDirection = StringUtils::SearchDirection; - [[nodiscard]] Optional<size_t> find_any_of(StringView const& needles, SearchDirection direction) const { return StringUtils::find_any_of(*this, needles, direction); } + [[nodiscard]] Optional<size_t> find_any_of(StringView needles, SearchDirection direction) const { return StringUtils::find_any_of(*this, needles, direction); } [[nodiscard]] String substring(size_t start, size_t length) const; [[nodiscard]] String substring(size_t start) const; @@ -185,16 +185,16 @@ public: [[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); } [[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); } - [[nodiscard]] bool starts_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; - [[nodiscard]] bool ends_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] bool starts_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] bool ends_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; [[nodiscard]] bool starts_with(char) const; [[nodiscard]] bool ends_with(char) const; bool operator==(const String&) const; bool operator!=(const String& other) const { return !(*this == other); } - bool operator==(const StringView&) const; - bool operator!=(const StringView& other) const { return !(*this == other); } + bool operator==(StringView) const; + bool operator!=(StringView other) const { return !(*this == other); } bool operator==(const FlyString&) const; bool operator!=(const FlyString& other) const { return !(*this == other); } @@ -285,8 +285,8 @@ public: return { characters(), length() }; } - [[nodiscard]] String replace(const StringView& needle, const StringView& replacement, bool all_occurrences = false) const { return StringUtils::replace(*this, needle, replacement, all_occurrences); } - [[nodiscard]] size_t count(StringView const& needle) const { return StringUtils::count(*this, needle); } + [[nodiscard]] String replace(StringView needle, StringView replacement, bool all_occurrences = false) const { return StringUtils::replace(*this, needle, replacement, all_occurrences); } + [[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); } [[nodiscard]] String reverse() const; template<typename... Ts> @@ -314,7 +314,7 @@ bool operator>=(const char*, const String&); bool operator>(const char*, const String&); bool operator<=(const char*, const String&); -String escape_html_entities(const StringView& html); +String escape_html_entities(StringView html); InputStream& operator>>(InputStream& stream, String& string); diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index f382be467c..22bcf56389 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -38,7 +38,7 @@ StringBuilder::StringBuilder(size_t initial_capacity) m_buffer.ensure_capacity(initial_capacity); } -void StringBuilder::append(StringView const& str) +void StringBuilder::append(StringView str) { if (str.is_empty()) return; @@ -129,7 +129,7 @@ void StringBuilder::append_as_lowercase(char ch) append(ch); } -void StringBuilder::append_escaped_for_json(StringView const& string) +void StringBuilder::append_escaped_for_json(StringView string) { for (auto ch : string) { switch (ch) { diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index fc7f830dc4..36019dffa7 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -21,7 +21,7 @@ public: explicit StringBuilder(size_t initial_capacity = inline_capacity); ~StringBuilder() = default; - void append(StringView const&); + void append(StringView); void append(Utf16View const&); void append(Utf32View const&); void append(char); @@ -30,7 +30,7 @@ public: void appendvf(char const*, va_list); void append_as_lowercase(char); - void append_escaped_for_json(StringView const&); + void append_escaped_for_json(StringView); template<typename... Parameters> void appendff(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters) diff --git a/AK/StringUtils.cpp b/AK/StringUtils.cpp index 78d49a48e2..d62499f45e 100644 --- a/AK/StringUtils.cpp +++ b/AK/StringUtils.cpp @@ -19,7 +19,7 @@ namespace AK { namespace StringUtils { -bool matches(const StringView& str, const StringView& mask, CaseSensitivity case_sensitivity, Vector<MaskSpan>* match_spans) +bool matches(StringView str, StringView mask, CaseSensitivity case_sensitivity, Vector<MaskSpan>* match_spans) { auto record_span = [&match_spans](size_t start, size_t length) { if (match_spans) @@ -79,7 +79,7 @@ bool matches(const StringView& str, const StringView& mask, CaseSensitivity case } template<typename T> -Optional<T> convert_to_int(const StringView& str, TrimWhitespace trim_whitespace) +Optional<T> convert_to_int(StringView str, TrimWhitespace trim_whitespace) { auto string = trim_whitespace == TrimWhitespace::Yes ? str.trim_whitespace() @@ -113,14 +113,14 @@ Optional<T> convert_to_int(const StringView& str, TrimWhitespace trim_whitespace return value; } -template Optional<i8> convert_to_int(const StringView& str, TrimWhitespace); -template Optional<i16> convert_to_int(const StringView& str, TrimWhitespace); -template Optional<i32> convert_to_int(const StringView& str, TrimWhitespace); -template Optional<long> convert_to_int(const StringView& str, TrimWhitespace); -template Optional<long long> convert_to_int(const StringView& str, TrimWhitespace); +template Optional<i8> convert_to_int(StringView str, TrimWhitespace); +template Optional<i16> convert_to_int(StringView str, TrimWhitespace); +template Optional<i32> convert_to_int(StringView str, TrimWhitespace); +template Optional<long> convert_to_int(StringView str, TrimWhitespace); +template Optional<long long> convert_to_int(StringView str, TrimWhitespace); template<typename T> -Optional<T> convert_to_uint(const StringView& str, TrimWhitespace trim_whitespace) +Optional<T> convert_to_uint(StringView str, TrimWhitespace trim_whitespace) { auto string = trim_whitespace == TrimWhitespace::Yes ? str.trim_whitespace() @@ -144,16 +144,16 @@ Optional<T> convert_to_uint(const StringView& str, TrimWhitespace trim_whitespac return value; } -template Optional<u8> convert_to_uint(const StringView& str, TrimWhitespace); -template Optional<u16> convert_to_uint(const StringView& str, TrimWhitespace); -template Optional<u32> convert_to_uint(const StringView& str, TrimWhitespace); -template Optional<unsigned long> convert_to_uint(const StringView& str, TrimWhitespace); -template Optional<unsigned long long> convert_to_uint(const StringView& str, TrimWhitespace); -template Optional<long> convert_to_uint(const StringView& str, TrimWhitespace); -template Optional<long long> convert_to_uint(const StringView& str, TrimWhitespace); +template Optional<u8> convert_to_uint(StringView str, TrimWhitespace); +template Optional<u16> convert_to_uint(StringView str, TrimWhitespace); +template Optional<u32> convert_to_uint(StringView str, TrimWhitespace); +template Optional<unsigned long> convert_to_uint(StringView str, TrimWhitespace); +template Optional<unsigned long long> convert_to_uint(StringView str, TrimWhitespace); +template Optional<long> convert_to_uint(StringView str, TrimWhitespace); +template Optional<long long> convert_to_uint(StringView str, TrimWhitespace); template<typename T> -Optional<T> convert_to_uint_from_hex(const StringView& str, TrimWhitespace trim_whitespace) +Optional<T> convert_to_uint_from_hex(StringView str, TrimWhitespace trim_whitespace) { auto string = trim_whitespace == TrimWhitespace::Yes ? str.trim_whitespace() @@ -186,12 +186,12 @@ Optional<T> convert_to_uint_from_hex(const StringView& str, TrimWhitespace trim_ return value; } -template Optional<u8> convert_to_uint_from_hex(const StringView& str, TrimWhitespace); -template Optional<u16> convert_to_uint_from_hex(const StringView& str, TrimWhitespace); -template Optional<u32> convert_to_uint_from_hex(const StringView& str, TrimWhitespace); -template Optional<u64> convert_to_uint_from_hex(const StringView& str, TrimWhitespace); +template Optional<u8> convert_to_uint_from_hex(StringView str, TrimWhitespace); +template Optional<u16> convert_to_uint_from_hex(StringView str, TrimWhitespace); +template Optional<u32> convert_to_uint_from_hex(StringView str, TrimWhitespace); +template Optional<u64> convert_to_uint_from_hex(StringView str, TrimWhitespace); -bool equals_ignoring_case(const StringView& a, const StringView& b) +bool equals_ignoring_case(StringView a, StringView b) { if (a.length() != b.length()) return false; @@ -202,7 +202,7 @@ bool equals_ignoring_case(const StringView& a, const StringView& b) return true; } -bool ends_with(const StringView& str, const StringView& end, CaseSensitivity case_sensitivity) +bool ends_with(StringView str, StringView end, CaseSensitivity case_sensitivity) { if (end.is_empty()) return true; @@ -225,7 +225,7 @@ bool ends_with(const StringView& str, const StringView& end, CaseSensitivity cas return true; } -bool starts_with(const StringView& str, const StringView& start, CaseSensitivity case_sensitivity) +bool starts_with(StringView str, StringView start, CaseSensitivity case_sensitivity) { if (start.is_empty()) return true; @@ -250,7 +250,7 @@ bool starts_with(const StringView& str, const StringView& start, CaseSensitivity return true; } -bool contains(const StringView& str, const StringView& needle, CaseSensitivity case_sensitivity) +bool contains(StringView str, StringView needle, CaseSensitivity case_sensitivity) { if (str.is_null() || needle.is_null() || str.is_empty() || needle.length() > str.length()) return false; @@ -277,12 +277,12 @@ bool contains(const StringView& str, const StringView& needle, CaseSensitivity c return false; } -bool is_whitespace(const StringView& str) +bool is_whitespace(StringView str) { return all_of(str, is_ascii_space); } -StringView trim(const StringView& str, const StringView& characters, TrimMode mode) +StringView trim(StringView str, StringView characters, TrimMode mode) { size_t substring_start = 0; size_t substring_length = str.length(); @@ -311,12 +311,12 @@ StringView trim(const StringView& str, const StringView& characters, TrimMode mo return str.substring_view(substring_start, substring_length); } -StringView trim_whitespace(const StringView& str, TrimMode mode) +StringView trim_whitespace(StringView str, TrimMode mode) { return trim(str, " \n\t\v\f\r", mode); } -Optional<size_t> find(StringView const& haystack, char needle, size_t start) +Optional<size_t> find(StringView haystack, char needle, size_t start) { if (start >= haystack.length()) return {}; @@ -327,7 +327,7 @@ Optional<size_t> find(StringView const& haystack, char needle, size_t start) return {}; } -Optional<size_t> find(StringView const& haystack, StringView const& needle, size_t start) +Optional<size_t> find(StringView haystack, StringView needle, size_t start) { if (start > haystack.length()) return {}; @@ -337,7 +337,7 @@ Optional<size_t> find(StringView const& haystack, StringView const& needle, size return index.has_value() ? (*index + start) : index; } -Optional<size_t> find_last(StringView const& haystack, char needle) +Optional<size_t> find_last(StringView haystack, char needle) { for (size_t i = haystack.length(); i > 0; --i) { if (haystack[i - 1] == needle) @@ -346,7 +346,7 @@ Optional<size_t> find_last(StringView const& haystack, char needle) return {}; } -Vector<size_t> find_all(StringView const& haystack, StringView const& needle) +Vector<size_t> find_all(StringView haystack, StringView needle) { Vector<size_t> positions; size_t current_position = 0; @@ -362,7 +362,7 @@ Vector<size_t> find_all(StringView const& haystack, StringView const& needle) return positions; } -Optional<size_t> find_any_of(StringView const& haystack, StringView const& needles, SearchDirection direction) +Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDirection direction) { if (haystack.is_empty() || needles.is_empty()) return {}; @@ -380,7 +380,7 @@ Optional<size_t> find_any_of(StringView const& haystack, StringView const& needl return {}; } -String to_snakecase(const StringView& str) +String to_snakecase(StringView str) { auto should_insert_underscore = [&](auto i, auto current_char) { if (i == 0) @@ -406,7 +406,7 @@ String to_snakecase(const StringView& str) return builder.to_string(); } -String to_titlecase(StringView const& str) +String to_titlecase(StringView str) { StringBuilder builder; bool next_is_upper = true; @@ -422,7 +422,7 @@ String to_titlecase(StringView const& str) return builder.to_string(); } -String replace(StringView const& str, StringView const& needle, StringView const& replacement, bool all_occurrences) +String replace(StringView str, StringView needle, StringView replacement, bool all_occurrences) { if (str.is_empty()) return str; @@ -451,7 +451,7 @@ String replace(StringView const& str, StringView const& needle, StringView const } // TODO: Benchmark against KMP (AK/MemMem.h) and switch over if it's faster for short strings too -size_t count(StringView const& str, StringView const& needle) +size_t count(StringView str, StringView needle) { if (needle.is_empty()) return str.length(); diff --git a/AK/StringUtils.h b/AK/StringUtils.h index dabf4a1fef..13794c4d0c 100644 --- a/AK/StringUtils.h +++ b/AK/StringUtils.h @@ -43,36 +43,36 @@ struct MaskSpan { namespace StringUtils { -bool matches(const StringView& str, const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive, Vector<MaskSpan>* match_spans = nullptr); +bool matches(StringView str, StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive, Vector<MaskSpan>* match_spans = nullptr); template<typename T = int> -Optional<T> convert_to_int(const StringView&, TrimWhitespace = TrimWhitespace::Yes); +Optional<T> convert_to_int(StringView, TrimWhitespace = TrimWhitespace::Yes); template<typename T = unsigned> -Optional<T> convert_to_uint(const StringView&, TrimWhitespace = TrimWhitespace::Yes); +Optional<T> convert_to_uint(StringView, TrimWhitespace = TrimWhitespace::Yes); template<typename T = unsigned> -Optional<T> convert_to_uint_from_hex(const StringView&, TrimWhitespace = TrimWhitespace::Yes); -bool equals_ignoring_case(const StringView&, const StringView&); -bool ends_with(const StringView& a, const StringView& b, CaseSensitivity); -bool starts_with(const StringView&, const StringView&, CaseSensitivity); -bool contains(const StringView&, const StringView&, CaseSensitivity); -bool is_whitespace(const StringView&); -StringView trim(const StringView& string, const StringView& characters, TrimMode mode); -StringView trim_whitespace(const StringView& string, TrimMode mode); - -Optional<size_t> find(StringView const& haystack, char needle, size_t start = 0); -Optional<size_t> find(StringView const& haystack, StringView const& needle, size_t start = 0); -Optional<size_t> find_last(StringView const& haystack, char needle); -Vector<size_t> find_all(StringView const& haystack, StringView const& needle); +Optional<T> convert_to_uint_from_hex(StringView, TrimWhitespace = TrimWhitespace::Yes); +bool equals_ignoring_case(StringView, StringView); +bool ends_with(StringView a, StringView b, CaseSensitivity); +bool starts_with(StringView, StringView, CaseSensitivity); +bool contains(StringView, StringView, CaseSensitivity); +bool is_whitespace(StringView); +StringView trim(StringView string, StringView characters, TrimMode mode); +StringView trim_whitespace(StringView string, TrimMode mode); + +Optional<size_t> find(StringView haystack, char needle, size_t start = 0); +Optional<size_t> find(StringView haystack, StringView needle, size_t start = 0); +Optional<size_t> find_last(StringView haystack, char needle); +Vector<size_t> find_all(StringView haystack, StringView needle); enum class SearchDirection { Forward, Backward }; -Optional<size_t> find_any_of(StringView const& haystack, StringView const& needles, SearchDirection); +Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDirection); -String to_snakecase(const StringView&); -String to_titlecase(StringView const&); +String to_snakecase(StringView); +String to_titlecase(StringView); -String replace(StringView const&, StringView const& needle, StringView const& replacement, bool all_occurrences = false); -size_t count(StringView const&, StringView const& needle); +String replace(StringView, StringView needle, StringView replacement, bool all_occurrences = false); +size_t count(StringView, StringView needle); } diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 3bd40ac06b..79273bc5c7 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -56,7 +56,7 @@ Vector<StringView> StringView::split_view(const char separator, bool keep_empty) return v; } -Vector<StringView> StringView::split_view(const StringView& separator, bool keep_empty) const +Vector<StringView> StringView::split_view(StringView separator, bool keep_empty) const { VERIFY(!separator.is_empty()); @@ -129,7 +129,7 @@ bool StringView::starts_with(char ch) const return ch == characters_without_null_termination()[0]; } -bool StringView::starts_with(const StringView& str, CaseSensitivity case_sensitivity) const +bool StringView::starts_with(StringView str, CaseSensitivity case_sensitivity) const { return StringUtils::starts_with(*this, str, case_sensitivity); } @@ -141,17 +141,17 @@ bool StringView::ends_with(char ch) const return ch == characters_without_null_termination()[length() - 1]; } -bool StringView::ends_with(const StringView& str, CaseSensitivity case_sensitivity) const +bool StringView::ends_with(StringView str, CaseSensitivity case_sensitivity) const { return StringUtils::ends_with(*this, str, case_sensitivity); } -bool StringView::matches(const StringView& mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const +bool StringView::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const { return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans); } -bool StringView::matches(const StringView& mask, CaseSensitivity case_sensitivity) const +bool StringView::matches(StringView mask, CaseSensitivity case_sensitivity) const { return StringUtils::matches(*this, mask, case_sensitivity); } @@ -165,12 +165,12 @@ bool StringView::contains(char needle) const return false; } -bool StringView::contains(const StringView& needle, CaseSensitivity case_sensitivity) const +bool StringView::contains(StringView needle, CaseSensitivity case_sensitivity) const { return StringUtils::contains(*this, needle, case_sensitivity); } -bool StringView::equals_ignoring_case(const StringView& other) const +bool StringView::equals_ignoring_case(StringView other) const { return StringUtils::equals_ignoring_case(*this, other); } @@ -190,7 +190,7 @@ String StringView::to_titlecase_string() const return StringUtils::to_titlecase(*this); } -StringView StringView::substring_view_starting_from_substring(const StringView& substring) const +StringView StringView::substring_view_starting_from_substring(StringView substring) const { const char* remaining_characters = substring.characters_without_null_termination(); VERIFY(remaining_characters >= m_characters); @@ -199,7 +199,7 @@ StringView StringView::substring_view_starting_from_substring(const StringView& return { remaining_characters, remaining_length }; } -StringView StringView::substring_view_starting_after_substring(const StringView& substring) const +StringView StringView::substring_view_starting_after_substring(StringView substring) const { const char* remaining_characters = substring.characters_without_null_termination() + substring.length(); VERIFY(remaining_characters >= m_characters); @@ -249,7 +249,7 @@ bool StringView::operator==(const String& string) const String StringView::to_string() const { return String { *this }; } -String StringView::replace(const StringView& needle, const StringView& replacement, bool all_occurrences) const +String StringView::replace(StringView needle, StringView replacement, bool all_occurrences) const { return StringUtils::replace(*this, needle, replacement, all_occurrences); } diff --git a/AK/StringView.h b/AK/StringView.h index 0ba49a5d54..7a8fdd6ede 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -74,17 +74,17 @@ public: return string_hash(characters_without_null_termination(), length()); } - [[nodiscard]] bool starts_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; - [[nodiscard]] bool ends_with(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] bool starts_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] bool ends_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; [[nodiscard]] bool starts_with(char) const; [[nodiscard]] bool ends_with(char) const; - [[nodiscard]] bool matches(const StringView& mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; - [[nodiscard]] bool matches(const StringView& mask, Vector<MaskSpan>&, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; + [[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; + [[nodiscard]] bool matches(StringView mask, Vector<MaskSpan>&, CaseSensitivity = CaseSensitivity::CaseInsensitive) const; [[nodiscard]] bool contains(char) const; - [[nodiscard]] bool contains(const StringView&, CaseSensitivity = CaseSensitivity::CaseSensitive) const; - [[nodiscard]] bool equals_ignoring_case(const StringView& other) const; + [[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const; + [[nodiscard]] bool equals_ignoring_case(StringView other) const; - [[nodiscard]] StringView trim(const StringView& characters, TrimMode mode = TrimMode::Both) const { return StringUtils::trim(*this, characters, mode); } + [[nodiscard]] StringView trim(StringView characters, TrimMode mode = TrimMode::Both) const { return StringUtils::trim(*this, characters, mode); } [[nodiscard]] StringView trim_whitespace(TrimMode mode = TrimMode::Both) const { return StringUtils::trim_whitespace(*this, mode); } [[nodiscard]] String to_lowercase_string() const; @@ -92,14 +92,14 @@ public: [[nodiscard]] String to_titlecase_string() const; [[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } - [[nodiscard]] Optional<size_t> find(StringView const& needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } + [[nodiscard]] Optional<size_t> find(StringView needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); } [[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); } - // FIXME: Implement find_last(StringView const&) for API symmetry. + // FIXME: Implement find_last(StringView) for API symmetry. [[nodiscard]] Vector<size_t> find_all(StringView needle) const; using SearchDirection = StringUtils::SearchDirection; - [[nodiscard]] Optional<size_t> find_any_of(StringView const& needles, SearchDirection direction = SearchDirection::Forward) { return StringUtils::find_any_of(*this, needles, direction); } + [[nodiscard]] Optional<size_t> find_any_of(StringView needles, SearchDirection direction = SearchDirection::Forward) { return StringUtils::find_any_of(*this, needles, direction); } [[nodiscard]] constexpr StringView substring_view(size_t start, size_t length) const { @@ -114,7 +114,7 @@ public: } [[nodiscard]] Vector<StringView> split_view(char, bool keep_empty = false) const; - [[nodiscard]] Vector<StringView> split_view(const StringView&, bool keep_empty = false) const; + [[nodiscard]] Vector<StringView> split_view(StringView, bool keep_empty = false) const; [[nodiscard]] Vector<StringView> split_view_if(Function<bool(char)> const& predicate, bool keep_empty = false) const; @@ -145,8 +145,8 @@ public: // StringView substr { "oo" }; // // would not work. - [[nodiscard]] StringView substring_view_starting_from_substring(const StringView& substring) const; - [[nodiscard]] StringView substring_view_starting_after_substring(const StringView& substring) const; + [[nodiscard]] StringView substring_view_starting_from_substring(StringView substring) const; + [[nodiscard]] StringView substring_view_starting_after_substring(StringView substring) const; constexpr bool operator==(const char* cstring) const { @@ -172,7 +172,7 @@ public: bool operator==(const String&) const; - constexpr bool operator==(const StringView& other) const + constexpr bool operator==(StringView other) const { if (is_null()) return other.is_null(); @@ -183,12 +183,12 @@ public: return !__builtin_memcmp(m_characters, other.m_characters, m_length); } - constexpr bool operator!=(const StringView& other) const + constexpr bool operator!=(StringView other) const { return !(*this == other); } - bool operator<(const StringView& other) const + bool operator<(StringView other) const { if (int c = __builtin_memcmp(m_characters, other.m_characters, min(m_length, other.m_length))) return c < 0; @@ -199,8 +199,8 @@ public: [[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); } - [[nodiscard]] String replace(const StringView& needle, const StringView& replacement, bool all_occurrences = false) const; - [[nodiscard]] size_t count(StringView const& needle) const { return StringUtils::count(*this, needle); } + [[nodiscard]] String replace(StringView needle, StringView replacement, bool all_occurrences = false) const; + [[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); } template<typename... Ts> [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const @@ -216,7 +216,7 @@ private: template<> struct Traits<StringView> : public GenericTraits<StringView> { - static unsigned hash(const StringView& s) { return s.hash(); } + static unsigned hash(StringView s) { return s.hash(); } }; } diff --git a/AK/URL.cpp b/AK/URL.cpp index 494ea18beb..dfc68bbd7e 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -16,7 +16,7 @@ namespace AK { // FIXME: It could make sense to force users of URL to use URLParser::parse() explicitly instead of using a constructor. -URL::URL(StringView const& string) +URL::URL(StringView string) : URL(URLParser::parse(string)) { if constexpr (URL_PARSER_DEBUG) { @@ -135,12 +135,12 @@ bool URL::compute_validity() const return true; } -bool URL::scheme_requires_port(StringView const& scheme) +bool URL::scheme_requires_port(StringView scheme) { return (default_port_for_scheme(scheme) != 0); } -u16 URL::default_port_for_scheme(StringView const& scheme) +u16 URL::default_port_for_scheme(StringView scheme) { if (scheme == "http") return 80; @@ -189,7 +189,7 @@ URL URL::create_with_url_or_path(String const& url_or_path) } // https://url.spec.whatwg.org/#special-scheme -bool URL::is_special_scheme(StringView const& scheme) +bool URL::is_special_scheme(StringView scheme) { return scheme.is_one_of("ftp", "file", "http", "https", "ws", "wss"); } @@ -403,7 +403,7 @@ void URL::append_percent_encoded_if_necessary(StringBuilder& builder, u32 code_p builder.append_code_point(code_point); } -String URL::percent_encode(StringView const& input, URL::PercentEncodeSet set) +String URL::percent_encode(StringView input, URL::PercentEncodeSet set) { StringBuilder builder; for (auto code_point : Utf8View(input)) { @@ -412,7 +412,7 @@ String URL::percent_encode(StringView const& input, URL::PercentEncodeSet set) return builder.to_string(); } -String URL::percent_decode(StringView const& input) +String URL::percent_decode(StringView input) { if (!input.contains('%')) return input; @@ -37,7 +37,7 @@ public: }; URL() = default; - URL(StringView const&); + URL(StringView); URL(char const* string) : URL(StringView(string)) { @@ -100,12 +100,12 @@ public: static URL create_with_file_protocol(String const& path, String const& fragment = {}) { return create_with_file_scheme(path, fragment); } static URL create_with_data(String mime_type, String payload, bool is_base64 = false) { return URL(move(mime_type), move(payload), is_base64); }; - static bool scheme_requires_port(StringView const&); - static u16 default_port_for_scheme(StringView const&); - static bool is_special_scheme(StringView const&); + static bool scheme_requires_port(StringView); + static u16 default_port_for_scheme(StringView); + static bool is_special_scheme(StringView); - static String percent_encode(StringView const& input, PercentEncodeSet set = PercentEncodeSet::Userinfo); - static String percent_decode(StringView const& input); + static String percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo); + static String percent_decode(StringView input); bool operator==(URL const& other) const { return equals(other, ExcludeFragment::No); } diff --git a/AK/URLParser.cpp b/AK/URLParser.cpp index 63cf3c449e..d508aa96dc 100644 --- a/AK/URLParser.cpp +++ b/AK/URLParser.cpp @@ -30,7 +30,7 @@ static void report_validation_error(SourceLocation const& location = SourceLocat dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Validation error! {}", location); } -static Optional<String> parse_opaque_host(StringView const& input) +static Optional<String> parse_opaque_host(StringView input) { auto forbidden_host_code_points_excluding_percent = "\0\t\n\r #/:<>?@[\\]^|"sv; for (auto code_point : forbidden_host_code_points_excluding_percent) { @@ -44,7 +44,7 @@ static Optional<String> parse_opaque_host(StringView const& input) return URL::percent_encode(input, URL::PercentEncodeSet::C0Control); } -static Optional<String> parse_ipv4_address(StringView const& input) +static Optional<String> parse_ipv4_address(StringView input) { // FIXME: Implement the correct IPv4 parser as specified by https://url.spec.whatwg.org/#concept-ipv4-parser. return input; @@ -52,7 +52,7 @@ static Optional<String> parse_ipv4_address(StringView const& input) // https://url.spec.whatwg.org/#concept-host-parser // NOTE: This is a very bare-bones implementation. -static Optional<String> parse_host(StringView const& input, bool is_not_special = false) +static Optional<String> parse_host(StringView input, bool is_not_special = false) { if (input.starts_with('[')) { if (!input.ends_with(']')) { @@ -84,7 +84,7 @@ static Optional<String> parse_host(StringView const& input, bool is_not_special return ipv4_host; } -constexpr bool starts_with_windows_drive_letter(StringView const& input) +constexpr bool starts_with_windows_drive_letter(StringView input) { if (input.length() < 2) return false; @@ -95,29 +95,29 @@ constexpr bool starts_with_windows_drive_letter(StringView const& input) return "/\\?#"sv.contains(input[2]); } -constexpr bool is_windows_drive_letter(StringView const& input) +constexpr bool is_windows_drive_letter(StringView input) { return input.length() == 2 && is_ascii_alpha(input[0]) && (input[1] == ':' || input[1] == '|'); } -constexpr bool is_normalized_windows_drive_letter(StringView const& input) +constexpr bool is_normalized_windows_drive_letter(StringView input) { return input.length() == 2 && is_ascii_alpha(input[0]) && input[1] == ':'; } -constexpr bool is_single_dot_path_segment(StringView const& input) +constexpr bool is_single_dot_path_segment(StringView input) { return input == "."sv || input.equals_ignoring_case("%2e"sv); } -constexpr bool is_double_dot_path_segment(StringView const& input) +constexpr bool is_double_dot_path_segment(StringView input) { return input == ".."sv || input.equals_ignoring_case(".%2e"sv) || input.equals_ignoring_case("%2e."sv) || input.equals_ignoring_case("%2e%2e"sv); } // https://fetch.spec.whatwg.org/#data-urls // FIXME: This only loosely follows the spec, as we use the same class for "regular" and data URLs, unlike the spec. -Optional<URL> URLParser::parse_data_url(StringView const& raw_input) +Optional<URL> URLParser::parse_data_url(StringView raw_input) { dbgln_if(URL_PARSER_DEBUG, "URLParser::parse_data_url: Parsing '{}'.", raw_input); VERIFY(raw_input.starts_with("data:")); @@ -161,7 +161,7 @@ Optional<URL> URLParser::parse_data_url(StringView const& raw_input) // NOTE: Since the URL class's member variables contain percent decoded data, we have to deviate from the URL parser specification when setting // some of those values. Because the specification leaves all values percent encoded in their URL data structure, we have to percent decode // everything before setting the member variables. -URL URLParser::parse(StringView const& raw_input, URL const* base_url, Optional<URL> url, Optional<State> state_override) +URL URLParser::parse(StringView raw_input, URL const* base_url, Optional<URL> url, Optional<State> state_override) { dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Parsing '{}'", raw_input); if (raw_input.is_empty()) diff --git a/AK/URLParser.h b/AK/URLParser.h index ea296c07c1..99e9dc0805 100644 --- a/AK/URLParser.h +++ b/AK/URLParser.h @@ -55,10 +55,10 @@ public: VERIFY_NOT_REACHED(); } - static URL parse(StringView const& input, URL const* base_url = nullptr, Optional<URL> url = {}, Optional<State> state_override = {}); + static URL parse(StringView input, URL const* base_url = nullptr, Optional<URL> url = {}, Optional<State> state_override = {}); private: - static Optional<URL> parse_data_url(StringView const& raw_input); + static Optional<URL> parse_data_url(StringView raw_input); }; #undef ENUMERATE_STATES diff --git a/AK/UUID.cpp b/AK/UUID.cpp index cc87d7adca..835da053b4 100644 --- a/AK/UUID.cpp +++ b/AK/UUID.cpp @@ -16,7 +16,7 @@ UUID::UUID(Array<u8, 16> uuid_buffer) uuid_buffer.span().copy_to(m_uuid_buffer); } -void UUID::convert_string_view_to_uuid(const StringView& uuid_string_view) +void UUID::convert_string_view_to_uuid(StringView uuid_string_view) { VERIFY(uuid_string_view.length() == 36); auto first_unit = decode_hex(uuid_string_view.substring_view(0, 8)); @@ -36,7 +36,7 @@ void UUID::convert_string_view_to_uuid(const StringView& uuid_string_view) m_uuid_buffer.span().overwrite(10, fifth_unit.value().data(), fifth_unit.value().size()); } -UUID::UUID(const StringView& uuid_string_view) +UUID::UUID(StringView uuid_string_view) { convert_string_view_to_uuid(uuid_string_view); } @@ -17,7 +17,7 @@ class UUID { public: UUID() = default; UUID(Array<u8, 16> uuid_buffer); - UUID(const StringView&); + UUID(StringView); ~UUID() = default; bool operator==(const UUID&) const; @@ -31,7 +31,7 @@ public: bool is_zero() const; private: - void convert_string_view_to_uuid(const StringView&); + void convert_string_view_to_uuid(StringView); Array<u8, 16> m_uuid_buffer {}; }; diff --git a/AK/Utf16View.cpp b/AK/Utf16View.cpp index 09cd06cf16..3e29368a01 100644 --- a/AK/Utf16View.cpp +++ b/AK/Utf16View.cpp @@ -32,7 +32,7 @@ static Vector<u16, 1> to_utf16_impl(UtfViewType const& view) requires(IsSame<Utf return utf16_data; } -Vector<u16, 1> utf8_to_utf16(StringView const& utf8_view) +Vector<u16, 1> utf8_to_utf16(StringView utf8_view) { return to_utf16_impl(Utf8View { utf8_view }); } diff --git a/AK/Utf16View.h b/AK/Utf16View.h index 348ef085e8..5b6fc24e06 100644 --- a/AK/Utf16View.h +++ b/AK/Utf16View.h @@ -16,7 +16,7 @@ namespace AK { -Vector<u16, 1> utf8_to_utf16(StringView const&); +Vector<u16, 1> utf8_to_utf16(StringView); Vector<u16, 1> utf8_to_utf16(Utf8View const&); Vector<u16, 1> utf32_to_utf16(Utf32View const&); void code_point_to_utf16(Vector<u16, 1>&, u32); diff --git a/AK/Utf8View.h b/AK/Utf8View.h index 18b5a3df4b..60496deb9a 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -74,7 +74,7 @@ public: explicit Utf8View(String&&) = delete; - const StringView& as_string() const { return m_string; } + StringView as_string() const { return m_string; } Utf8CodePointIterator begin() const { return { begin_ptr(), m_string.length() }; } Utf8CodePointIterator end() const { return { end_ptr(), 0 }; } |