2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-09-23 11:21:18 +00:00
|
|
|
#include <AK/Format.h>
|
2020-02-14 20:41:10 +00:00
|
|
|
#include <AK/Forward.h>
|
2019-06-21 16:45:35 +00:00
|
|
|
#include <AK/RefPtr.h>
|
2020-08-05 10:14:44 +00:00
|
|
|
#include <AK/Stream.h>
|
2021-01-15 19:13:14 +00:00
|
|
|
#include <AK/StringBuilder.h>
|
2019-04-15 12:56:37 +00:00
|
|
|
#include <AK/StringImpl.h>
|
2020-02-26 07:25:24 +00:00
|
|
|
#include <AK/StringUtils.h>
|
2019-04-15 12:56:37 +00:00
|
|
|
#include <AK/Traits.h>
|
2018-10-10 09:53:07 +00:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
// DeprecatedString is a convenience wrapper around StringImpl, suitable for passing
|
2019-06-02 06:37:01 +00:00
|
|
|
// around as a value type. It's basically the same as passing around a
|
2019-06-21 16:37:47 +00:00
|
|
|
// RefPtr<StringImpl>, with a bit of syntactic sugar.
|
2019-06-02 06:37:01 +00:00
|
|
|
//
|
|
|
|
// Note that StringImpl is an immutable object that cannot shrink or grow.
|
|
|
|
// Its allocation size is snugly tailored to the specific string it contains.
|
2022-12-04 18:02:33 +00:00
|
|
|
// Copying a DeprecatedString is very efficient, since the internal StringImpl is
|
2019-06-21 16:40:24 +00:00
|
|
|
// retainable and so copying only requires modifying the ref count.
|
2019-06-02 06:37:01 +00:00
|
|
|
//
|
2022-12-04 18:02:33 +00:00
|
|
|
// There are three main ways to construct a new DeprecatedString:
|
2019-06-02 06:37:01 +00:00
|
|
|
//
|
2022-12-04 18:02:33 +00:00
|
|
|
// s = DeprecatedString("some literal");
|
2019-06-02 06:37:01 +00:00
|
|
|
//
|
2022-12-04 18:02:33 +00:00
|
|
|
// s = DeprecatedString::formatted("{} little piggies", m_piggies);
|
2019-06-02 06:37:01 +00:00
|
|
|
//
|
|
|
|
// StringBuilder builder;
|
|
|
|
// builder.append("abc");
|
|
|
|
// builder.append("123");
|
2022-12-06 01:12:49 +00:00
|
|
|
// s = builder.to_deprecated_string();
|
2019-06-02 06:37:01 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
class DeprecatedString {
|
2018-10-10 09:53:07 +00:00
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
~DeprecatedString() = default;
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString() = default;
|
2021-06-02 23:35:01 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(StringView view)
|
2022-01-20 12:30:23 +00:00
|
|
|
: m_impl(StringImpl::create(view.characters_without_null_termination(), view.length()))
|
2021-06-02 23:35:01 +00:00
|
|
|
{
|
|
|
|
}
|
2019-04-15 12:56:37 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(DeprecatedString const& other)
|
|
|
|
: m_impl(const_cast<DeprecatedString&>(other).m_impl)
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(DeprecatedString&& other)
|
2018-10-17 08:55:43 +00:00
|
|
|
: m_impl(move(other.m_impl))
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
|
2018-11-06 23:19:35 +00:00
|
|
|
: m_impl(StringImpl::create(cstring, shouldChomp))
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
|
2018-11-06 23:19:35 +00:00
|
|
|
: m_impl(StringImpl::create(cstring, length, shouldChomp))
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
explicit DeprecatedString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
|
2020-08-05 08:37:34 +00:00
|
|
|
: m_impl(StringImpl::create(bytes, shouldChomp))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(StringImpl const& impl)
|
2018-10-10 09:53:07 +00:00
|
|
|
: m_impl(const_cast<StringImpl&>(impl))
|
2019-04-12 12:43:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(StringImpl const* impl)
|
2019-04-12 12:43:44 +00:00
|
|
|
: m_impl(const_cast<StringImpl*>(impl))
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(RefPtr<StringImpl>&& impl)
|
2018-10-17 08:55:43 +00:00
|
|
|
: m_impl(move(impl))
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(NonnullRefPtr<StringImpl>&& impl)
|
2019-02-25 15:04:08 +00:00
|
|
|
: m_impl(move(impl))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString(FlyString const&);
|
2020-03-22 18:07:02 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString repeated(char, size_t count);
|
|
|
|
[[nodiscard]] static DeprecatedString repeated(StringView, size_t count);
|
2021-01-15 19:13:14 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
|
|
|
|
[[nodiscard]] static DeprecatedString roman_number_from(size_t value);
|
2021-04-30 21:31:53 +00:00
|
|
|
|
2021-01-15 19:13:14 +00:00
|
|
|
template<class SeparatorType, class CollectionType>
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
|
2021-01-15 19:13:14 +00:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
2022-02-22 21:31:05 +00:00
|
|
|
builder.join(separator, collection, fmtstr);
|
2021-01-15 19:13:14 +00:00
|
|
|
return builder.build();
|
|
|
|
}
|
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
[[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
|
|
|
|
[[nodiscard]] bool matches(StringView mask, Vector<MaskSpan>&, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
|
2019-04-25 20:56:09 +00:00
|
|
|
|
2020-12-10 13:17:30 +00:00
|
|
|
template<typename T = int>
|
2021-06-18 16:21:27 +00:00
|
|
|
[[nodiscard]] Optional<T> to_int(TrimWhitespace = TrimWhitespace::Yes) const;
|
2020-12-10 13:17:30 +00:00
|
|
|
template<typename T = unsigned>
|
2021-06-18 16:21:27 +00:00
|
|
|
[[nodiscard]] Optional<T> to_uint(TrimWhitespace = TrimWhitespace::Yes) const;
|
2022-10-10 22:48:45 +00:00
|
|
|
#ifndef KERNEL
|
|
|
|
[[nodiscard]] Optional<double> to_double(TrimWhitespace = TrimWhitespace::Yes) const;
|
|
|
|
[[nodiscard]] Optional<float> to_float(TrimWhitespace = TrimWhitespace::Yes) const;
|
|
|
|
#endif
|
2018-10-31 18:49:22 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] DeprecatedString to_lowercase() const;
|
|
|
|
[[nodiscard]] DeprecatedString to_uppercase() const;
|
|
|
|
[[nodiscard]] DeprecatedString to_snakecase() const;
|
|
|
|
[[nodiscard]] DeprecatedString to_titlecase() const;
|
|
|
|
[[nodiscard]] DeprecatedString invert_case() const;
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
|
2021-01-02 23:26:02 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] DeprecatedString trim(StringView characters, TrimMode mode = TrimMode::Both) const
|
2021-05-25 07:42:01 +00:00
|
|
|
{
|
2022-02-18 23:36:30 +00:00
|
|
|
auto trimmed_view = StringUtils::trim(view(), characters, mode);
|
|
|
|
if (view() == trimmed_view)
|
|
|
|
return *this;
|
|
|
|
return trimmed_view;
|
2021-05-25 07:42:01 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] DeprecatedString trim_whitespace(TrimMode mode = TrimMode::Both) const
|
2020-09-20 13:35:04 +00:00
|
|
|
{
|
2022-02-18 23:36:30 +00:00
|
|
|
auto trimmed_view = StringUtils::trim_whitespace(view(), mode);
|
|
|
|
if (view() == trimmed_view)
|
|
|
|
return *this;
|
|
|
|
return trimmed_view;
|
2020-09-20 13:35:04 +00:00
|
|
|
}
|
2020-05-11 00:43:33 +00:00
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
[[nodiscard]] bool equals_ignoring_case(StringView) const;
|
2019-12-18 11:43:53 +00:00
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
2021-08-11 18:49:32 +00:00
|
|
|
[[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
2019-10-28 17:47:48 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] Vector<DeprecatedString> split_limit(char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const;
|
|
|
|
[[nodiscard]] Vector<DeprecatedString> split(char separator, SplitBehavior = SplitBehavior::Nothing) const;
|
2022-10-22 13:38:21 +00:00
|
|
|
[[nodiscard]] Vector<StringView> split_view(char separator, SplitBehavior = SplitBehavior::Nothing) const;
|
|
|
|
[[nodiscard]] Vector<StringView> split_view(Function<bool(char)> separator, SplitBehavior = SplitBehavior::Nothing) const;
|
2021-01-12 19:58:45 +00:00
|
|
|
|
2021-07-01 15:34:25 +00:00
|
|
|
[[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); }
|
2021-11-10 23:55:02 +00:00
|
|
|
[[nodiscard]] Optional<size_t> find(StringView needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); }
|
2021-07-01 15:34:25 +00:00
|
|
|
[[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); }
|
2021-11-10 23:55:02 +00:00
|
|
|
// FIXME: Implement find_last(StringView) for API symmetry.
|
2021-11-10 10:05:21 +00:00
|
|
|
Vector<size_t> find_all(StringView needle) const;
|
2021-07-01 16:12:21 +00:00
|
|
|
using SearchDirection = StringUtils::SearchDirection;
|
2021-11-10 23:55:02 +00:00
|
|
|
[[nodiscard]] Optional<size_t> find_any_of(StringView needles, SearchDirection direction) const { return StringUtils::find_any_of(*this, needles, direction); }
|
2021-01-12 19:58:45 +00:00
|
|
|
|
2022-06-18 16:35:36 +00:00
|
|
|
[[nodiscard]] StringView find_last_split_view(char separator) const { return view().find_last_split_view(separator); }
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] DeprecatedString substring(size_t start, size_t length) const;
|
|
|
|
[[nodiscard]] DeprecatedString substring(size_t start) const;
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] StringView substring_view(size_t start, size_t length) const;
|
|
|
|
[[nodiscard]] StringView substring_view(size_t start) const;
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] bool is_null() const { return !m_impl; }
|
|
|
|
[[nodiscard]] ALWAYS_INLINE bool is_empty() const { return length() == 0; }
|
|
|
|
[[nodiscard]] ALWAYS_INLINE size_t length() const { return m_impl ? m_impl->length() : 0; }
|
2020-08-23 10:56:46 +00:00
|
|
|
// Includes NUL-terminator, if non-nullptr.
|
2022-04-01 17:58:27 +00:00
|
|
|
[[nodiscard]] ALWAYS_INLINE char const* characters() const { return m_impl ? m_impl->characters() : nullptr; }
|
2020-07-27 12:15:37 +00:00
|
|
|
|
2020-08-25 14:23:18 +00:00
|
|
|
[[nodiscard]] bool copy_characters_to_buffer(char* buffer, size_t buffer_size) const;
|
|
|
|
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] ALWAYS_INLINE ReadonlyBytes bytes() const
|
2021-01-10 23:29:28 +00:00
|
|
|
{
|
|
|
|
if (m_impl) {
|
|
|
|
return m_impl->bytes();
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
2020-07-27 12:15:37 +00:00
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
[[nodiscard]] ALWAYS_INLINE char const& operator[](size_t i) const
|
2019-05-28 09:53:16 +00:00
|
|
|
{
|
2021-05-30 14:07:07 +00:00
|
|
|
VERIFY(!is_null());
|
2019-05-28 09:53:16 +00:00
|
|
|
return (*m_impl)[i];
|
|
|
|
}
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
using ConstIterator = SimpleIterator<const DeprecatedString, char const>;
|
2020-09-06 19:14:08 +00:00
|
|
|
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); }
|
|
|
|
[[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); }
|
2020-03-10 08:13:29 +00:00
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
[[nodiscard]] bool starts_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
|
|
|
[[nodiscard]] bool ends_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] bool starts_with(char) const;
|
|
|
|
[[nodiscard]] bool ends_with(char) const;
|
2019-03-22 11:43:29 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
bool operator==(DeprecatedString const&) const;
|
2019-07-11 10:58:27 +00:00
|
|
|
|
2021-11-10 23:55:02 +00:00
|
|
|
bool operator==(StringView) const;
|
2019-08-24 20:28:42 +00:00
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
bool operator==(FlyString const&) const;
|
2020-03-28 08:11:00 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
bool operator<(DeprecatedString const&) const;
|
2022-04-01 17:58:27 +00:00
|
|
|
bool operator<(char const*) const;
|
2022-12-04 18:02:33 +00:00
|
|
|
bool operator>=(DeprecatedString const& other) const { return !(*this < other); }
|
2022-04-01 17:58:27 +00:00
|
|
|
bool operator>=(char const* other) const { return !(*this < other); }
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
bool operator>(DeprecatedString const&) const;
|
2022-04-01 17:58:27 +00:00
|
|
|
bool operator>(char const*) const;
|
2022-12-04 18:02:33 +00:00
|
|
|
bool operator<=(DeprecatedString const& other) const { return !(*this > other); }
|
2022-04-01 17:58:27 +00:00
|
|
|
bool operator<=(char const* other) const { return !(*this > other); }
|
2019-07-11 10:58:27 +00:00
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
bool operator==(char const* cstring) const;
|
2019-06-08 16:30:40 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] DeprecatedString isolated_copy() const;
|
2018-10-26 07:54:29 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString empty()
|
2021-06-02 23:35:01 +00:00
|
|
|
{
|
|
|
|
return StringImpl::the_empty_stringimpl();
|
|
|
|
}
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] StringImpl* impl() { return m_impl.ptr(); }
|
2022-04-01 17:58:27 +00:00
|
|
|
[[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); }
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString& operator=(DeprecatedString&& other)
|
2018-10-10 09:53:07 +00:00
|
|
|
{
|
2018-10-24 12:28:22 +00:00
|
|
|
if (this != &other)
|
2018-10-17 08:55:43 +00:00
|
|
|
m_impl = move(other.m_impl);
|
2018-10-24 12:28:22 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString& operator=(DeprecatedString const& other)
|
2018-10-24 12:28:22 +00:00
|
|
|
{
|
|
|
|
if (this != &other)
|
2022-12-04 18:02:33 +00:00
|
|
|
m_impl = const_cast<DeprecatedString&>(other).m_impl;
|
2018-10-10 09:53:07 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString& operator=(std::nullptr_t)
|
2020-08-05 08:37:34 +00:00
|
|
|
{
|
|
|
|
m_impl = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString& operator=(ReadonlyBytes bytes)
|
2020-08-05 08:37:34 +00:00
|
|
|
{
|
|
|
|
m_impl = StringImpl::create(bytes);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] u32 hash() const
|
2019-10-18 15:17:47 +00:00
|
|
|
{
|
|
|
|
if (!m_impl)
|
|
|
|
return 0;
|
|
|
|
return m_impl->hash();
|
|
|
|
}
|
|
|
|
|
2021-04-21 19:35:08 +00:00
|
|
|
[[nodiscard]] ByteBuffer to_byte_buffer() const;
|
2019-04-20 12:13:40 +00:00
|
|
|
|
|
|
|
template<typename BufferType>
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString copy(BufferType const& buffer, ShouldChomp should_chomp = NoChomp)
|
2019-04-20 12:13:40 +00:00
|
|
|
{
|
|
|
|
if (buffer.is_empty())
|
|
|
|
return empty();
|
2022-12-04 18:02:33 +00:00
|
|
|
return DeprecatedString((char const*)buffer.data(), buffer.size(), should_chomp);
|
2019-04-20 12:13:40 +00:00
|
|
|
}
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString vformatted(StringView fmtstr, TypeErasedFormatParams&);
|
2020-09-23 11:21:18 +00:00
|
|
|
|
|
|
|
template<typename... Parameters>
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
2020-09-23 11:21:18 +00:00
|
|
|
{
|
2021-09-01 04:44:05 +00:00
|
|
|
VariadicFormatParams variadic_format_parameters { parameters... };
|
|
|
|
return vformatted(fmtstr.view(), variadic_format_parameters);
|
2020-09-23 11:21:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 18:20:59 +00:00
|
|
|
template<Arithmetic T>
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] static DeprecatedString number(T value)
|
2021-01-17 08:22:04 +00:00
|
|
|
{
|
|
|
|
return formatted("{}", value);
|
|
|
|
}
|
2019-01-30 15:28:51 +00:00
|
|
|
|
2021-06-02 23:35:01 +00:00
|
|
|
[[nodiscard]] StringView view() const
|
|
|
|
{
|
|
|
|
return { characters(), length() };
|
|
|
|
}
|
2019-04-15 12:56:37 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] DeprecatedString replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }
|
2021-11-10 23:55:02 +00:00
|
|
|
[[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); }
|
2022-12-04 18:02:33 +00:00
|
|
|
[[nodiscard]] DeprecatedString reverse() const;
|
2020-04-01 19:27:39 +00:00
|
|
|
|
2021-06-04 09:46:29 +00:00
|
|
|
template<typename... Ts>
|
2021-07-31 23:27:25 +00:00
|
|
|
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
|
2020-05-25 10:36:41 +00:00
|
|
|
{
|
2021-06-04 09:46:29 +00:00
|
|
|
return (... || this->operator==(forward<Ts>(strings)));
|
2020-05-25 10:36:41 +00:00
|
|
|
}
|
|
|
|
|
2022-03-20 22:52:36 +00:00
|
|
|
template<typename... Ts>
|
|
|
|
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of_ignoring_case(Ts&&... strings) const
|
|
|
|
{
|
|
|
|
return (... ||
|
|
|
|
[this, &strings]() -> bool {
|
|
|
|
if constexpr (requires(Ts a) { a.view()->StringView; })
|
|
|
|
return this->equals_ignoring_case(forward<Ts>(strings.view()));
|
|
|
|
else
|
|
|
|
return this->equals_ignoring_case(forward<Ts>(strings));
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
private:
|
2019-06-21 16:37:47 +00:00
|
|
|
RefPtr<StringImpl> m_impl;
|
2018-10-10 09:53:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2022-12-04 18:02:33 +00:00
|
|
|
struct Traits<DeprecatedString> : public GenericTraits<DeprecatedString> {
|
|
|
|
static unsigned hash(DeprecatedString const& s) { return s.impl() ? s.impl()->hash() : 0; }
|
2018-10-10 09:53:07 +00:00
|
|
|
};
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
struct CaseInsensitiveStringTraits : public Traits<DeprecatedString> {
|
|
|
|
static unsigned hash(DeprecatedString const& s) { return s.impl() ? s.impl()->case_insensitive_hash() : 0; }
|
|
|
|
static bool equals(DeprecatedString const& a, DeprecatedString const& b) { return a.equals_ignoring_case(b); }
|
2019-07-13 09:00:29 +00:00
|
|
|
};
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString escape_html_entities(StringView html);
|
2020-02-13 07:46:00 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
InputStream& operator>>(InputStream& stream, DeprecatedString& string);
|
2020-08-05 10:14:44 +00:00
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
#if USING_AK_GLOBALLY
|
2019-09-13 12:37:25 +00:00
|
|
|
using AK::CaseInsensitiveStringTraits;
|
2020-02-13 07:46:00 +00:00
|
|
|
using AK::escape_html_entities;
|
2022-11-26 11:18:30 +00:00
|
|
|
#endif
|