1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 12:17:36 +00:00

Everywhere: Rename {Deprecated => Byte}String

This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -5,8 +5,8 @@
*/
#include <AK/ByteBuffer.h>
#include <AK/ByteString.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/Function.h>
#include <AK/StdLibExtras.h>
@ -16,17 +16,17 @@
namespace AK {
bool DeprecatedString::operator==(DeprecatedFlyString const& fly_string) const
bool ByteString::operator==(DeprecatedFlyString const& fly_string) const
{
return m_impl == fly_string.impl() || view() == fly_string.view();
}
bool DeprecatedString::operator==(DeprecatedString const& other) const
bool ByteString::operator==(ByteString const& other) const
{
return m_impl == other.impl() || view() == other.view();
}
bool DeprecatedString::operator==(StringView other) const
bool ByteString::operator==(StringView other) const
{
if (other.is_null())
return is_empty();
@ -34,17 +34,17 @@ bool DeprecatedString::operator==(StringView other) const
return view() == other;
}
bool DeprecatedString::operator<(DeprecatedString const& other) const
bool ByteString::operator<(ByteString const& other) const
{
return view() < other.view();
}
bool DeprecatedString::operator>(DeprecatedString const& other) const
bool ByteString::operator>(ByteString const& other) const
{
return view() > other.view();
}
bool DeprecatedString::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
bool ByteString::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
{
// We must fit at least the NUL-terminator.
VERIFY(buffer_size > 0);
@ -56,55 +56,55 @@ bool DeprecatedString::copy_characters_to_buffer(char* buffer, size_t buffer_siz
return characters_to_copy == length();
}
DeprecatedString DeprecatedString::isolated_copy() const
ByteString ByteString::isolated_copy() const
{
if (m_impl->length() == 0)
return empty();
char* buffer;
auto impl = StringImpl::create_uninitialized(length(), buffer);
memcpy(buffer, m_impl->characters(), m_impl->length());
return DeprecatedString(move(*impl));
return ByteString(move(*impl));
}
DeprecatedString DeprecatedString::substring(size_t start, size_t length) const
ByteString ByteString::substring(size_t start, size_t length) const
{
if (!length)
return DeprecatedString::empty();
return ByteString::empty();
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
VERIFY(start + length <= m_impl->length());
return { characters() + start, length };
}
DeprecatedString DeprecatedString::substring(size_t start) const
ByteString ByteString::substring(size_t start) const
{
VERIFY(start <= length());
return { characters() + start, length() - start };
}
StringView DeprecatedString::substring_view(size_t start, size_t length) const
StringView ByteString::substring_view(size_t start, size_t length) const
{
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
VERIFY(start + length <= m_impl->length());
return { characters() + start, length };
}
StringView DeprecatedString::substring_view(size_t start) const
StringView ByteString::substring_view(size_t start) const
{
VERIFY(start <= length());
return { characters() + start, length() - start };
}
Vector<DeprecatedString> DeprecatedString::split(char separator, SplitBehavior split_behavior) const
Vector<ByteString> ByteString::split(char separator, SplitBehavior split_behavior) const
{
return split_limit(separator, 0, split_behavior);
}
Vector<DeprecatedString> DeprecatedString::split_limit(char separator, size_t limit, SplitBehavior split_behavior) const
Vector<ByteString> ByteString::split_limit(char separator, size_t limit, SplitBehavior split_behavior) const
{
if (is_empty())
return {};
Vector<DeprecatedString> v;
Vector<ByteString> v;
size_t substart = 0;
bool keep_empty = has_flag(split_behavior, SplitBehavior::KeepEmpty);
bool keep_separator = has_flag(split_behavior, SplitBehavior::KeepTrailingSeparator);
@ -123,7 +123,7 @@ Vector<DeprecatedString> DeprecatedString::split_limit(char separator, size_t li
return v;
}
Vector<StringView> DeprecatedString::split_view(Function<bool(char)> separator, SplitBehavior split_behavior) const
Vector<StringView> ByteString::split_view(Function<bool(char)> separator, SplitBehavior split_behavior) const
{
if (is_empty())
return {};
@ -147,78 +147,78 @@ Vector<StringView> DeprecatedString::split_view(Function<bool(char)> separator,
return v;
}
Vector<StringView> DeprecatedString::split_view(char const separator, SplitBehavior split_behavior) const
Vector<StringView> ByteString::split_view(char const separator, SplitBehavior split_behavior) const
{
return split_view([separator](char ch) { return ch == separator; }, split_behavior);
}
ByteBuffer DeprecatedString::to_byte_buffer() const
ByteBuffer ByteString::to_byte_buffer() const
{
// FIXME: Handle OOM failure.
return ByteBuffer::copy(bytes()).release_value_but_fixme_should_propagate_errors();
}
template<typename T>
Optional<T> DeprecatedString::to_int(TrimWhitespace trim_whitespace) const
Optional<T> ByteString::to_int(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_int<T>(view(), trim_whitespace);
}
template Optional<i8> DeprecatedString::to_int(TrimWhitespace) const;
template Optional<i16> DeprecatedString::to_int(TrimWhitespace) const;
template Optional<i32> DeprecatedString::to_int(TrimWhitespace) const;
template Optional<long> DeprecatedString::to_int(TrimWhitespace) const;
template Optional<long long> DeprecatedString::to_int(TrimWhitespace) const;
template Optional<i8> ByteString::to_int(TrimWhitespace) const;
template Optional<i16> ByteString::to_int(TrimWhitespace) const;
template Optional<i32> ByteString::to_int(TrimWhitespace) const;
template Optional<long> ByteString::to_int(TrimWhitespace) const;
template Optional<long long> ByteString::to_int(TrimWhitespace) const;
template<typename T>
Optional<T> DeprecatedString::to_uint(TrimWhitespace trim_whitespace) const
Optional<T> ByteString::to_uint(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_uint<T>(view(), trim_whitespace);
}
template Optional<u8> DeprecatedString::to_uint(TrimWhitespace) const;
template Optional<u16> DeprecatedString::to_uint(TrimWhitespace) const;
template Optional<u32> DeprecatedString::to_uint(TrimWhitespace) const;
template Optional<unsigned long> DeprecatedString::to_uint(TrimWhitespace) const;
template Optional<unsigned long long> DeprecatedString::to_uint(TrimWhitespace) const;
template Optional<u8> ByteString::to_uint(TrimWhitespace) const;
template Optional<u16> ByteString::to_uint(TrimWhitespace) const;
template Optional<u32> ByteString::to_uint(TrimWhitespace) const;
template Optional<unsigned long> ByteString::to_uint(TrimWhitespace) const;
template Optional<unsigned long long> ByteString::to_uint(TrimWhitespace) const;
#ifndef KERNEL
Optional<double> DeprecatedString::to_double(TrimWhitespace trim_whitespace) const
Optional<double> ByteString::to_double(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_floating_point<double>(*this, trim_whitespace);
}
Optional<float> DeprecatedString::to_float(TrimWhitespace trim_whitespace) const
Optional<float> ByteString::to_float(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
}
#endif
bool DeprecatedString::starts_with(StringView str, CaseSensitivity case_sensitivity) const
bool ByteString::starts_with(StringView str, CaseSensitivity case_sensitivity) const
{
return StringUtils::starts_with(*this, str, case_sensitivity);
}
bool DeprecatedString::starts_with(char ch) const
bool ByteString::starts_with(char ch) const
{
if (is_empty())
return false;
return characters()[0] == ch;
}
bool DeprecatedString::ends_with(StringView str, CaseSensitivity case_sensitivity) const
bool ByteString::ends_with(StringView str, CaseSensitivity case_sensitivity) const
{
return StringUtils::ends_with(*this, str, case_sensitivity);
}
bool DeprecatedString::ends_with(char ch) const
bool ByteString::ends_with(char ch) const
{
if (is_empty())
return false;
return characters()[length() - 1] == ch;
}
DeprecatedString DeprecatedString::repeated(char ch, size_t count)
ByteString ByteString::repeated(char ch, size_t count)
{
if (!count)
return empty();
@ -228,7 +228,7 @@ DeprecatedString DeprecatedString::repeated(char ch, size_t count)
return *impl;
}
DeprecatedString DeprecatedString::repeated(StringView string, size_t count)
ByteString ByteString::repeated(StringView string, size_t count)
{
if (!count || string.is_empty())
return empty();
@ -239,7 +239,7 @@ DeprecatedString DeprecatedString::repeated(StringView string, size_t count)
return *impl;
}
DeprecatedString DeprecatedString::bijective_base_from(size_t value, unsigned base, StringView map)
ByteString ByteString::bijective_base_from(size_t value, unsigned base, StringView map)
{
value++;
if (map.is_null())
@ -265,13 +265,13 @@ DeprecatedString DeprecatedString::bijective_base_from(size_t value, unsigned ba
for (size_t j = 0; j < i / 2; ++j)
swap(buffer[j], buffer[i - j - 1]);
return DeprecatedString { ReadonlyBytes(buffer.data(), i) };
return ByteString { ReadonlyBytes(buffer.data(), i) };
}
DeprecatedString DeprecatedString::roman_number_from(size_t value)
ByteString ByteString::roman_number_from(size_t value)
{
if (value > 3999)
return DeprecatedString::number(value);
return ByteString::number(value);
StringBuilder builder;
@ -318,44 +318,44 @@ DeprecatedString DeprecatedString::roman_number_from(size_t value)
}
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
bool DeprecatedString::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
bool ByteString::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
{
return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans);
}
bool DeprecatedString::matches(StringView mask, CaseSensitivity case_sensitivity) const
bool ByteString::matches(StringView mask, CaseSensitivity case_sensitivity) const
{
return StringUtils::matches(*this, mask, case_sensitivity);
}
bool DeprecatedString::contains(StringView needle, CaseSensitivity case_sensitivity) const
bool ByteString::contains(StringView needle, CaseSensitivity case_sensitivity) const
{
return StringUtils::contains(*this, needle, case_sensitivity);
}
bool DeprecatedString::contains(char needle, CaseSensitivity case_sensitivity) const
bool ByteString::contains(char needle, CaseSensitivity case_sensitivity) const
{
return StringUtils::contains(*this, StringView(&needle, 1), case_sensitivity);
}
bool DeprecatedString::equals_ignoring_ascii_case(StringView other) const
bool ByteString::equals_ignoring_ascii_case(StringView other) const
{
return StringUtils::equals_ignoring_ascii_case(view(), other);
}
DeprecatedString DeprecatedString::reverse() const
ByteString ByteString::reverse() const
{
StringBuilder reversed_string(length());
for (size_t i = length(); i-- > 0;) {
reversed_string.append(characters()[i]);
}
return reversed_string.to_deprecated_string();
return reversed_string.to_byte_string();
}
DeprecatedString escape_html_entities(StringView html)
ByteString escape_html_entities(StringView html)
{
StringBuilder builder;
for (size_t i = 0; i < html.length(); ++i) {
@ -370,40 +370,40 @@ DeprecatedString escape_html_entities(StringView html)
else
builder.append(html[i]);
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString::DeprecatedString(DeprecatedFlyString const& string)
ByteString::ByteString(DeprecatedFlyString const& string)
: m_impl(*(string.impl() ?: &StringImpl::the_empty_stringimpl()))
{
}
DeprecatedString DeprecatedString::to_lowercase() const
ByteString ByteString::to_lowercase() const
{
return m_impl->to_lowercase();
}
DeprecatedString DeprecatedString::to_uppercase() const
ByteString ByteString::to_uppercase() const
{
return m_impl->to_uppercase();
}
DeprecatedString DeprecatedString::to_snakecase() const
ByteString ByteString::to_snakecase() const
{
return StringUtils::to_snakecase(*this);
}
DeprecatedString DeprecatedString::to_titlecase() const
ByteString ByteString::to_titlecase() const
{
return StringUtils::to_titlecase(*this);
}
DeprecatedString DeprecatedString::invert_case() const
ByteString ByteString::invert_case() const
{
return StringUtils::invert_case(*this);
}
bool DeprecatedString::operator==(char const* cstring) const
bool ByteString::operator==(char const* cstring) const
{
if (!cstring)
return is_empty();
@ -411,28 +411,28 @@ bool DeprecatedString::operator==(char const* cstring) const
return view() == cstring;
}
DeprecatedString DeprecatedString::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
ByteString ByteString::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
{
StringBuilder builder;
MUST(vformat(builder, fmtstr, params));
return builder.to_deprecated_string();
return builder.to_byte_string();
}
Vector<size_t> DeprecatedString::find_all(StringView needle) const
Vector<size_t> ByteString::find_all(StringView needle) const
{
return StringUtils::find_all(*this, needle);
}
DeprecatedStringCodePointIterator DeprecatedString::code_points() const
DeprecatedStringCodePointIterator ByteString::code_points() const
{
return DeprecatedStringCodePointIterator(*this);
}
ErrorOr<DeprecatedString> DeprecatedString::from_utf8(ReadonlyBytes bytes)
ErrorOr<ByteString> ByteString::from_utf8(ReadonlyBytes bytes)
{
if (!Utf8View(bytes).validate())
return Error::from_string_literal("DeprecatedString::from_utf8: Input was not valid UTF-8");
return DeprecatedString { *StringImpl::create(bytes) };
return Error::from_string_literal("ByteString::from_utf8: Input was not valid UTF-8");
return ByteString { *StringImpl::create(bytes) };
}
}

View file

@ -16,93 +16,93 @@
namespace AK {
// DeprecatedString is a convenience wrapper around StringImpl, suitable for passing
// ByteString is a convenience wrapper around StringImpl, suitable for passing
// around as a value type. It's basically the same as passing around a
// RefPtr<StringImpl const>, with a bit of syntactic sugar.
//
// Note that StringImpl is an immutable object that cannot shrink or grow.
// Its allocation size is snugly tailored to the specific string it contains.
// Copying a DeprecatedString is very efficient, since the internal StringImpl is
// Copying a ByteString is very efficient, since the internal StringImpl is
// retainable and so copying only requires modifying the ref count.
//
// There are three main ways to construct a new DeprecatedString:
// There are three main ways to construct a new ByteString:
//
// s = DeprecatedString("some literal");
// s = ByteString("some literal");
//
// s = DeprecatedString::formatted("{} little piggies", m_piggies);
// s = ByteString::formatted("{} little piggies", m_piggies);
//
// StringBuilder builder;
// builder.append("abc");
// builder.append("123");
// s = builder.to_deprecated_string();
// s = builder.to_byte_string();
class DeprecatedString {
class ByteString {
public:
~DeprecatedString() = default;
~ByteString() = default;
DeprecatedString()
ByteString()
: m_impl(StringImpl::the_empty_stringimpl())
{
}
DeprecatedString(StringView view)
ByteString(StringView view)
: m_impl(*StringImpl::create(view.characters_without_null_termination(), view.length()))
{
}
DeprecatedString(DeprecatedString const& other)
ByteString(ByteString const& other)
: m_impl(other.m_impl)
{
}
DeprecatedString(DeprecatedString&& other)
ByteString(ByteString&& other)
: m_impl(move(other.m_impl))
{
other.m_impl = StringImpl::the_empty_stringimpl();
}
DeprecatedString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
ByteString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
: m_impl(*StringImpl::create(cstring, shouldChomp))
{
}
DeprecatedString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
ByteString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
: m_impl(*StringImpl::create(cstring, length, shouldChomp))
{
}
explicit DeprecatedString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
explicit ByteString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
: m_impl(*StringImpl::create(bytes, shouldChomp))
{
}
DeprecatedString(StringImpl const& impl)
ByteString(StringImpl const& impl)
: m_impl(impl)
{
}
DeprecatedString(NonnullRefPtr<StringImpl const>&& impl)
ByteString(NonnullRefPtr<StringImpl const>&& impl)
: m_impl(*move(impl))
{
}
DeprecatedString(DeprecatedFlyString const&);
ByteString(DeprecatedFlyString const&);
static ErrorOr<DeprecatedString> from_utf8(ReadonlyBytes);
static ErrorOr<DeprecatedString> from_utf8(StringView string) { return from_utf8(string.bytes()); }
static ErrorOr<ByteString> from_utf8(ReadonlyBytes);
static ErrorOr<ByteString> from_utf8(StringView string) { return from_utf8(string.bytes()); }
[[nodiscard]] static DeprecatedString repeated(char, size_t count);
[[nodiscard]] static DeprecatedString repeated(StringView, size_t count);
[[nodiscard]] static ByteString repeated(char, size_t count);
[[nodiscard]] static ByteString repeated(StringView, size_t count);
[[nodiscard]] static DeprecatedString bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
[[nodiscard]] static DeprecatedString roman_number_from(size_t value);
[[nodiscard]] static ByteString bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
[[nodiscard]] static ByteString roman_number_from(size_t value);
template<class SeparatorType, class CollectionType>
[[nodiscard]] static DeprecatedString join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
[[nodiscard]] static ByteString join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
{
StringBuilder builder;
builder.join(separator, collection, fmtstr);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
[[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
@ -117,17 +117,17 @@ public:
[[nodiscard]] Optional<float> to_float(TrimWhitespace = TrimWhitespace::Yes) const;
#endif
[[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;
[[nodiscard]] ByteString to_lowercase() const;
[[nodiscard]] ByteString to_uppercase() const;
[[nodiscard]] ByteString to_snakecase() const;
[[nodiscard]] ByteString to_titlecase() const;
[[nodiscard]] ByteString invert_case() const;
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
[[nodiscard]] DeprecatedStringCodePointIterator code_points() const;
[[nodiscard]] DeprecatedString trim(StringView characters, TrimMode mode = TrimMode::Both) const
[[nodiscard]] ByteString trim(StringView characters, TrimMode mode = TrimMode::Both) const
{
auto trimmed_view = StringUtils::trim(view(), characters, mode);
if (view() == trimmed_view)
@ -135,7 +135,7 @@ public:
return trimmed_view;
}
[[nodiscard]] DeprecatedString trim_whitespace(TrimMode mode = TrimMode::Both) const
[[nodiscard]] ByteString trim_whitespace(TrimMode mode = TrimMode::Both) const
{
auto trimmed_view = StringUtils::trim_whitespace(view(), mode);
if (view() == trimmed_view)
@ -148,8 +148,8 @@ public:
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
[[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
[[nodiscard]] Vector<DeprecatedString> split_limit(char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<DeprecatedString> split(char separator, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<ByteString> split_limit(char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<ByteString> split(char separator, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<StringView> split_view(char separator, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<StringView> split_view(Function<bool(char)> separator, SplitBehavior = SplitBehavior::Nothing) const;
@ -163,8 +163,8 @@ public:
[[nodiscard]] StringView find_last_split_view(char separator) const { return view().find_last_split_view(separator); }
[[nodiscard]] DeprecatedString substring(size_t start, size_t length) const;
[[nodiscard]] DeprecatedString substring(size_t start) const;
[[nodiscard]] ByteString substring(size_t start, size_t length) const;
[[nodiscard]] ByteString substring(size_t start) const;
[[nodiscard]] StringView substring_view(size_t start, size_t length) const;
[[nodiscard]] StringView substring_view(size_t start) const;
@ -190,7 +190,7 @@ public:
return bit_cast<u8>((*m_impl)[i]);
}
using ConstIterator = SimpleIterator<const DeprecatedString, char const>;
using ConstIterator = SimpleIterator<const ByteString, char const>;
[[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); }
[[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); }
@ -200,47 +200,47 @@ public:
[[nodiscard]] bool starts_with(char) const;
[[nodiscard]] bool ends_with(char) const;
bool operator==(DeprecatedString const&) const;
bool operator==(ByteString const&) const;
bool operator==(StringView) const;
bool operator==(DeprecatedFlyString const&) const;
bool operator<(DeprecatedString const&) const;
bool operator>=(DeprecatedString const& other) const { return !(*this < other); }
bool operator<(ByteString const&) const;
bool operator>=(ByteString const& other) const { return !(*this < other); }
bool operator>=(char const* other) const { return !(*this < other); }
bool operator>(DeprecatedString const&) const;
bool operator<=(DeprecatedString const& other) const { return !(*this > other); }
bool operator>(ByteString const&) const;
bool operator<=(ByteString const& other) const { return !(*this > other); }
bool operator<=(char const* other) const { return !(*this > other); }
bool operator==(char const* cstring) const;
[[nodiscard]] DeprecatedString isolated_copy() const;
[[nodiscard]] ByteString isolated_copy() const;
[[nodiscard]] static DeprecatedString empty()
[[nodiscard]] static ByteString empty()
{
return StringImpl::the_empty_stringimpl();
}
[[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); }
DeprecatedString& operator=(DeprecatedString&& other)
ByteString& operator=(ByteString&& other)
{
if (this != &other)
m_impl = move(other.m_impl);
return *this;
}
DeprecatedString& operator=(DeprecatedString const& other)
ByteString& operator=(ByteString const& other)
{
if (this != &other)
m_impl = const_cast<DeprecatedString&>(other).m_impl;
m_impl = const_cast<ByteString&>(other).m_impl;
return *this;
}
template<OneOf<ReadonlyBytes, Bytes> T>
DeprecatedString& operator=(T bytes)
ByteString& operator=(T bytes)
{
m_impl = *StringImpl::create(bytes);
return *this;
@ -254,24 +254,24 @@ public:
[[nodiscard]] ByteBuffer to_byte_buffer() const;
template<typename BufferType>
[[nodiscard]] static DeprecatedString copy(BufferType const& buffer, ShouldChomp should_chomp = NoChomp)
[[nodiscard]] static ByteString copy(BufferType const& buffer, ShouldChomp should_chomp = NoChomp)
{
if (buffer.is_empty())
return empty();
return DeprecatedString(reinterpret_cast<char const*>(buffer.data()), buffer.size(), should_chomp);
return ByteString(reinterpret_cast<char const*>(buffer.data()), buffer.size(), should_chomp);
}
[[nodiscard]] static DeprecatedString vformatted(StringView fmtstr, TypeErasedFormatParams&);
[[nodiscard]] static ByteString vformatted(StringView fmtstr, TypeErasedFormatParams&);
template<typename... Parameters>
[[nodiscard]] static DeprecatedString formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
[[nodiscard]] static ByteString formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
return vformatted(fmtstr.view(), variadic_format_parameters);
}
template<Arithmetic T>
[[nodiscard]] static DeprecatedString number(T value)
[[nodiscard]] static ByteString number(T value)
{
return formatted("{}", value);
}
@ -281,9 +281,9 @@ public:
return { characters(), length() };
}
[[nodiscard]] DeprecatedString replace(StringView needle, StringView replacement, ReplaceMode replace_mode = ReplaceMode::All) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }
[[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode replace_mode = ReplaceMode::All) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }
[[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); }
[[nodiscard]] DeprecatedString reverse() const;
[[nodiscard]] ByteString reverse() const;
template<typename... Ts>
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
@ -308,17 +308,17 @@ private:
};
template<>
struct Traits<DeprecatedString> : public DefaultTraits<DeprecatedString> {
static unsigned hash(DeprecatedString const& s) { return s.impl() ? s.impl()->hash() : 0; }
struct Traits<ByteString> : public DefaultTraits<ByteString> {
static unsigned hash(ByteString const& s) { return s.impl() ? s.impl()->hash() : 0; }
};
// FIXME: Rename this to indicate that it's about ASCII-only case insensitivity.
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_ascii_case(b); }
struct CaseInsensitiveStringTraits : public Traits<ByteString> {
static unsigned hash(ByteString const& s) { return s.impl() ? s.impl()->case_insensitive_hash() : 0; }
static bool equals(ByteString const& a, ByteString const& b) { return a.equals_ignoring_ascii_case(b); }
};
DeprecatedString escape_html_entities(StringView html);
ByteString escape_html_entities(StringView html);
}

View file

@ -6,7 +6,7 @@ set(AK_SOURCES
CountingStream.cpp
DOSPackedTime.cpp
DeprecatedFlyString.cpp
DeprecatedString.cpp
ByteString.cpp
Error.cpp
FloatingPointStringConversions.cpp
FlyString.cpp

View file

@ -8,17 +8,17 @@
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
# include <AK/StringView.h>
# include <cxxabi.h>
namespace AK {
inline DeprecatedString demangle(StringView name)
inline ByteString demangle(StringView name)
{
int status = 0;
auto* demangled_name = abi::__cxa_demangle(name.to_deprecated_string().characters(), nullptr, nullptr, &status);
auto string = DeprecatedString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name);
auto* demangled_name = abi::__cxa_demangle(name.to_byte_string().characters(), nullptr, nullptr, &status);
auto string = ByteString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name);
if (status == 0)
free(demangled_name);
return string;

View file

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteString.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/HashTable.h>
#include <AK/Optional.h>
#include <AK/Singleton.h>
@ -36,7 +36,7 @@ void DeprecatedFlyString::did_destroy_impl(Badge<StringImpl>, StringImpl& impl)
fly_impls().remove(&impl);
}
DeprecatedFlyString::DeprecatedFlyString(DeprecatedString const& string)
DeprecatedFlyString::DeprecatedFlyString(ByteString const& string)
{
if (string.impl()->is_fly()) {
m_impl = string.impl();
@ -61,7 +61,7 @@ DeprecatedFlyString::DeprecatedFlyString(StringView string)
return string == *candidate;
});
if (it == fly_impls().end()) {
auto new_string = string.to_deprecated_string();
auto new_string = string.to_byte_string();
fly_impls().set(new_string.impl());
new_string.impl()->set_fly({}, true);
m_impl = new_string.impl();
@ -122,10 +122,10 @@ bool DeprecatedFlyString::ends_with(StringView str, CaseSensitivity case_sensiti
DeprecatedFlyString DeprecatedFlyString::to_lowercase() const
{
return DeprecatedString(*m_impl).to_lowercase();
return ByteString(*m_impl).to_lowercase();
}
bool DeprecatedFlyString::operator==(DeprecatedString const& other) const
bool DeprecatedFlyString::operator==(ByteString const& other) const
{
return m_impl == other.impl() || view() == other.view();
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/StringUtils.h>
namespace AK {
@ -22,10 +22,10 @@ public:
: m_impl(move(other.m_impl))
{
}
DeprecatedFlyString(DeprecatedString const&);
DeprecatedFlyString(ByteString const&);
DeprecatedFlyString(StringView);
DeprecatedFlyString(char const* string)
: DeprecatedFlyString(static_cast<DeprecatedString>(string))
: DeprecatedFlyString(static_cast<ByteString>(string))
{
}
@ -54,7 +54,7 @@ public:
bool operator==(DeprecatedFlyString const& other) const { return m_impl == other.m_impl; }
bool operator==(DeprecatedString const&) const;
bool operator==(ByteString const&) const;
bool operator==(StringView) const;

View file

@ -43,10 +43,10 @@ public:
}
static Error from_string_view(StringView string_literal) { return Error(string_literal); }
template<OneOf<DeprecatedString, DeprecatedFlyString, String, FlyString> T>
template<OneOf<ByteString, DeprecatedFlyString, String, FlyString> T>
static Error from_string_view(T)
{
// `Error::from_string_view(DeprecatedString::formatted(...))` is a somewhat common mistake, which leads to a UAF situation.
// `Error::from_string_view(ByteString::formatted(...))` is a somewhat common mistake, which leads to a UAF situation.
// If your string outlives this error and _isn't_ a temporary being passed to this function, explicitly call .view() on it to resolve to the StringView overload.
static_assert(DependentFalse<T>, "Error::from_string_view(String) is almost always a use-after-free");
VERIFY_NOT_REACHED();

View file

@ -22,7 +22,7 @@ public:
static ErrorOr<FlyString> from_utf8(StringView);
template<typename T>
requires(IsOneOf<RemoveCVReference<T>, DeprecatedString, DeprecatedFlyString, FlyString, String>)
requires(IsOneOf<RemoveCVReference<T>, ByteString, DeprecatedFlyString, FlyString, String>)
static ErrorOr<String> from_utf8(T&&) = delete;
FlyString(String const&);

View file

@ -274,7 +274,7 @@ ErrorOr<void> FormatBuilder::put_u64(
size_t used_by_prefix = 0;
if (align == Align::Right && zero_pad) {
// We want DeprecatedString::formatted("{:#08x}", 32) to produce '0x00000020' instead of '0x000020'. This
// We want ByteString::formatted("{:#08x}", 32) to produce '0x00000020' instead of '0x000020'. This
// behavior differs from both fmtlib and printf, but is more intuitive.
used_by_prefix = 0;
} else {
@ -1131,13 +1131,13 @@ void vout(LogLevel log_level, StringView fmtstr, TypeErasedFormatParams& params,
#ifndef KERNEL
// FIXME: Deduplicate with Core::Process:get_name()
[[gnu::used]] static DeprecatedString process_name_helper()
[[gnu::used]] static ByteString process_name_helper()
{
# if defined(AK_OS_SERENITY)
char buffer[BUFSIZ] = {};
int rc = get_process_name(buffer, BUFSIZ);
if (rc != 0)
return DeprecatedString {};
return ByteString {};
return StringView { buffer, strlen(buffer) };
# elif defined(AK_LIBC_GLIBC) || (defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID))
return StringView { program_invocation_name, strlen(program_invocation_name) };

View file

@ -501,7 +501,7 @@ struct Formatter<unsigned char[Size]> : Formatter<StringView> {
}
};
template<>
struct Formatter<DeprecatedString> : Formatter<StringView> {
struct Formatter<ByteString> : Formatter<StringView> {
};
template<>
struct Formatter<DeprecatedFlyString> : Formatter<StringView> {

View file

@ -27,7 +27,7 @@ class CircularBuffer;
class ConstrainedStream;
class CountingStream;
class DeprecatedFlyString;
class DeprecatedString;
class ByteString;
class DeprecatedStringCodePointIterator;
class Duration;
class Error;
@ -159,12 +159,12 @@ using AK::BigEndianOutputBitStream;
using AK::Bitmap;
using AK::ByteBuffer;
using AK::Bytes;
using AK::ByteString;
using AK::CircularBuffer;
using AK::CircularQueue;
using AK::ConstrainedStream;
using AK::CountingStream;
using AK::DeprecatedFlyString;
using AK::DeprecatedString;
using AK::DeprecatedStringCodePointIterator;
using AK::DoublyLinkedList;
using AK::Duration;

View file

@ -11,7 +11,7 @@
#include <AK/StringBuilder.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
# include <AK/Utf16View.h>
#endif
@ -186,7 +186,7 @@ template ErrorOr<u64> GenericLexer::consume_decimal_integer<u64>();
template ErrorOr<i64> GenericLexer::consume_decimal_integer<i64>();
#ifndef KERNEL
Optional<DeprecatedString> GenericLexer::consume_and_unescape_string(char escape_char)
Optional<ByteString> GenericLexer::consume_and_unescape_string(char escape_char)
{
auto view = consume_quoted_string(escape_char);
if (view.is_null())
@ -195,7 +195,7 @@ Optional<DeprecatedString> GenericLexer::consume_and_unescape_string(char escape
StringBuilder builder;
for (size_t i = 0; i < view.length(); ++i)
builder.append(consume_escaped_character(escape_char));
return builder.to_deprecated_string();
return builder.to_byte_string();
}
auto GenericLexer::consume_escaped_code_point(bool combine_surrogate_pairs) -> Result<u32, UnicodeEscapeError>

View file

@ -92,7 +92,7 @@ public:
}
#ifndef KERNEL
bool consume_specific(DeprecatedString const& next)
bool consume_specific(ByteString const& next)
{
return consume_specific(StringView { next });
}
@ -126,7 +126,7 @@ public:
StringView consume_until(StringView);
StringView consume_quoted_string(char escape_char = 0);
#ifndef KERNEL
Optional<DeprecatedString> consume_and_unescape_string(char escape_char = '\\');
Optional<ByteString> consume_and_unescape_string(char escape_char = '\\');
#endif
template<Integral T>
ErrorOr<T> consume_decimal_integer();

View file

@ -45,14 +45,14 @@ ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(const ReadonlyBytes input)
return Kernel::KString::try_create(output.string_view());
}
#else
DeprecatedString encode_hex(const ReadonlyBytes input)
ByteString encode_hex(const ReadonlyBytes input)
{
StringBuilder output(input.size() * 2);
for (auto ch : input)
output.appendff("{:02x}", ch);
return output.to_deprecated_string();
return output.to_byte_string();
}
#endif

View file

@ -13,7 +13,7 @@
#ifdef KERNEL
# include <Kernel/Library/KString.h>
#else
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
#endif
namespace AK {
@ -34,7 +34,7 @@ ErrorOr<ByteBuffer> decode_hex(StringView);
#ifdef KERNEL
ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(ReadonlyBytes);
#else
DeprecatedString encode_hex(ReadonlyBytes);
ByteString encode_hex(ReadonlyBytes);
#endif
}

View file

@ -17,7 +17,7 @@
# include <AK/Error.h>
# include <Kernel/Library/KString.h>
#else
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
# include <AK/String.h>
#endif
@ -67,18 +67,18 @@ public:
octet(SubnetClass::D));
}
#else
DeprecatedString to_deprecated_string() const
ByteString to_byte_string() const
{
return DeprecatedString::formatted("{}.{}.{}.{}",
return ByteString::formatted("{}.{}.{}.{}",
octet(SubnetClass::A),
octet(SubnetClass::B),
octet(SubnetClass::C),
octet(SubnetClass::D));
}
DeprecatedString to_deprecated_string_reversed() const
ByteString to_byte_string_reversed() const
{
return DeprecatedString::formatted("{}.{}.{}.{}",
return ByteString::formatted("{}.{}.{}.{}",
octet(SubnetClass::D),
octet(SubnetClass::C),
octet(SubnetClass::B),
@ -179,7 +179,7 @@ template<>
struct Formatter<IPv4Address> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
{
return Formatter<StringView>::format(builder, value.to_deprecated_string());
return Formatter<StringView>::format(builder, value.to_byte_string());
}
};
#endif

View file

@ -71,7 +71,7 @@ private:
{
using RawContainerType = RemoveCV<Container>;
if constexpr (IsSame<StringView, RawContainerType> || IsSame<DeprecatedString, RawContainerType>)
if constexpr (IsSame<StringView, RawContainerType> || IsSame<ByteString, RawContainerType>)
return { container, container.length() };
else
return { container, container.size() };

View file

@ -73,7 +73,7 @@ public:
template<typename Builder>
void serialize(Builder&) const;
[[nodiscard]] DeprecatedString to_deprecated_string() const { return serialized<StringBuilder>(); }
[[nodiscard]] ByteString to_byte_string() const { return serialized<StringBuilder>(); }
template<typename Callback>
void for_each(Callback callback) const
@ -111,7 +111,7 @@ inline typename Builder::OutputType JsonArray::serialized() const
{
Builder builder;
serialize(builder);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
}

View file

@ -68,7 +68,7 @@ public:
}
#ifndef KERNEL
ErrorOr<void> add(DeprecatedString const& value)
ErrorOr<void> add(ByteString const& value)
{
TRY(begin_item());
if constexpr (IsLegacyBuilder<Builder>) {

View file

@ -109,7 +109,7 @@ Optional<bool> JsonObject::get_bool(StringView key) const
}
#if !defined(KERNEL)
Optional<DeprecatedString> JsonObject::get_deprecated_string(StringView key) const
Optional<ByteString> JsonObject::get_byte_string(StringView key) const
{
auto maybe_value = get(key);
if (maybe_value.has_value() && maybe_value->is_string())
@ -249,7 +249,7 @@ bool JsonObject::has_double(StringView key) const
}
#endif
void JsonObject::set(DeprecatedString const& key, JsonValue value)
void JsonObject::set(ByteString const& key, JsonValue value)
{
m_members.set(key, move(value));
}
@ -259,7 +259,7 @@ bool JsonObject::remove(StringView key)
return m_members.remove(key);
}
DeprecatedString JsonObject::to_deprecated_string() const
ByteString JsonObject::to_byte_string() const
{
return serialized<StringBuilder>();
}

View file

@ -8,8 +8,8 @@
#pragma once
#include <AK/ByteString.h>
#include <AK/Concepts.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/HashMap.h>
#include <AK/JsonArray.h>
@ -20,7 +20,7 @@ namespace AK {
class JsonObject {
template<typename Callback>
using CallbackErrorType = decltype(declval<Callback>()(declval<DeprecatedString const&>(), declval<JsonValue const&>()).release_error());
using CallbackErrorType = decltype(declval<Callback>()(declval<ByteString const&>(), declval<JsonValue const&>()).release_error());
public:
JsonObject();
@ -78,7 +78,7 @@ public:
Optional<bool> get_bool(StringView key) const;
#if !defined(KERNEL)
Optional<DeprecatedString> get_deprecated_string(StringView key) const;
Optional<ByteString> get_byte_string(StringView key) const;
#endif
Optional<JsonObject const&> get_object(StringView key) const;
@ -89,7 +89,7 @@ public:
Optional<float> get_float_with_precision_loss(StringView key) const;
#endif
void set(DeprecatedString const& key, JsonValue value);
void set(ByteString const& key, JsonValue value);
template<typename Callback>
void for_each_member(Callback callback) const
@ -98,7 +98,7 @@ public:
callback(member.key, member.value);
}
template<FallibleFunction<DeprecatedString const&, JsonValue const&> Callback>
template<FallibleFunction<ByteString const&, JsonValue const&> Callback>
ErrorOr<void, CallbackErrorType<Callback>> try_for_each_member(Callback&& callback) const
{
for (auto const& member : m_members)
@ -114,10 +114,10 @@ public:
template<typename Builder>
void serialize(Builder&) const;
[[nodiscard]] DeprecatedString to_deprecated_string() const;
[[nodiscard]] ByteString to_byte_string() const;
private:
OrderedHashMap<DeprecatedString, JsonValue> m_members;
OrderedHashMap<ByteString, JsonValue> m_members;
};
template<typename Builder>
@ -135,7 +135,7 @@ inline typename Builder::OutputType JsonObject::serialized() const
{
Builder builder;
serialize(builder);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
template<typename Builder>
@ -186,7 +186,7 @@ inline typename Builder::OutputType JsonValue::serialized() const
{
Builder builder;
serialize(builder);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
}

View file

@ -63,7 +63,7 @@ public:
}
#ifndef KERNEL
ErrorOr<void> add(StringView key, DeprecatedString const& value)
ErrorOr<void> add(StringView key, ByteString const& value)
{
TRY(begin_item(key));
if constexpr (IsLegacyBuilder<Builder>) {

View file

@ -31,7 +31,7 @@ constexpr bool is_space(int ch)
// │ │
// ╰─── u[0-9A-Za-z]{4} ──╯
//
ErrorOr<DeprecatedString> JsonParser::consume_and_unescape_string()
ErrorOr<ByteString> JsonParser::consume_and_unescape_string()
{
if (!consume_specific('"'))
return Error::from_string_literal("JsonParser: Expected '\"'");
@ -128,7 +128,7 @@ ErrorOr<DeprecatedString> JsonParser::consume_and_unescape_string()
}
}
return final_sb.to_deprecated_string();
return final_sb.to_byte_string();
}
ErrorOr<JsonValue> JsonParser::parse_object()

View file

@ -23,7 +23,7 @@ public:
private:
ErrorOr<JsonValue> parse_helper();
ErrorOr<DeprecatedString> consume_and_unescape_string();
ErrorOr<ByteString> consume_and_unescape_string();
ErrorOr<JsonValue> parse_array();
ErrorOr<JsonValue> parse_object();
ErrorOr<JsonValue> parse_number();

View file

@ -31,16 +31,16 @@ JsonValue JsonPath::resolve(JsonValue const& top_root) const
return root;
}
DeprecatedString JsonPath::to_deprecated_string() const
ByteString JsonPath::to_byte_string() const
{
StringBuilder builder;
builder.append("{ ."sv);
for (auto const& el : *this) {
builder.append("sv > "sv);
builder.append(el.to_deprecated_string());
builder.append(el.to_byte_string());
}
builder.append("sv }"sv);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Types.h>
#include <AK/Vector.h>
@ -34,7 +34,7 @@ public:
}
Kind kind() const { return m_kind; }
DeprecatedString const& key() const
ByteString const& key() const
{
VERIFY(m_kind == Kind::Key);
return m_key;
@ -46,13 +46,13 @@ public:
return m_index;
}
DeprecatedString to_deprecated_string() const
ByteString to_byte_string() const
{
switch (m_kind) {
case Kind::Key:
return key();
case Kind::Index:
return DeprecatedString::number(index());
return ByteString::number(index());
default:
return "*";
}
@ -78,7 +78,7 @@ public:
private:
Kind m_kind;
DeprecatedString m_key;
ByteString m_key;
size_t m_index { 0 };
JsonPathElement(Kind kind)
@ -90,7 +90,7 @@ private:
class JsonPath : public Vector<JsonPathElement> {
public:
JsonValue resolve(JsonValue const&) const;
DeprecatedString to_deprecated_string() const;
ByteString to_byte_string() const;
};
}

View file

@ -155,7 +155,7 @@ JsonValue::JsonValue(long long unsigned value)
}
JsonValue::JsonValue(char const* cstring)
: JsonValue(DeprecatedString(cstring))
: JsonValue(ByteString(cstring))
{
}
@ -167,7 +167,7 @@ JsonValue::JsonValue(double value)
}
#endif
JsonValue::JsonValue(DeprecatedString const& value)
JsonValue::JsonValue(ByteString const& value)
{
m_type = Type::String;
m_value.as_string = const_cast<StringImpl*>(value.impl());
@ -175,7 +175,7 @@ JsonValue::JsonValue(DeprecatedString const& value)
}
JsonValue::JsonValue(StringView value)
: JsonValue(value.to_deprecated_string())
: JsonValue(value.to_byte_string())
{
}

View file

@ -10,7 +10,7 @@
# error "JsonValue does not propagate allocation failures, so it is not safe to use in the kernel."
#endif
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Forward.h>
#include <AK/Optional.h>
#include <AK/StringBuilder.h>
@ -52,7 +52,7 @@ public:
JsonValue(double);
JsonValue(char const*);
JsonValue(DeprecatedString const&);
JsonValue(ByteString const&);
JsonValue(StringView);
template<typename T>
@ -78,14 +78,14 @@ public:
template<typename Builder>
void serialize(Builder&) const;
DeprecatedString as_string_or(DeprecatedString const& alternative) const
ByteString as_string_or(ByteString const& alternative) const
{
if (is_string())
return as_string();
return alternative;
}
DeprecatedString to_deprecated_string() const
ByteString to_byte_string() const
{
if (is_string())
return as_string();
@ -148,7 +148,7 @@ public:
return m_value.as_bool;
}
DeprecatedString as_string() const
ByteString as_string() const
{
VERIFY(is_string());
return *m_value.as_string;
@ -290,7 +290,7 @@ template<>
struct Formatter<JsonValue> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, JsonValue const& value)
{
return Formatter<StringView>::format(builder, value.to_deprecated_string());
return Formatter<StringView>::format(builder, value.to_byte_string());
}
};

View file

@ -14,7 +14,7 @@ namespace AK {
char s_single_dot = '.';
LexicalPath::LexicalPath(DeprecatedString path)
LexicalPath::LexicalPath(ByteString path)
: m_string(canonicalized_path(move(path)))
{
if (m_string.is_empty()) {
@ -58,9 +58,9 @@ LexicalPath::LexicalPath(DeprecatedString path)
}
}
Vector<DeprecatedString> LexicalPath::parts() const
Vector<ByteString> LexicalPath::parts() const
{
Vector<DeprecatedString> vector;
Vector<ByteString> vector;
vector.ensure_capacity(m_parts.size());
for (auto& part : m_parts)
vector.unchecked_append(part);
@ -88,7 +88,7 @@ bool LexicalPath::is_child_of(LexicalPath const& possible_parent) const
return common_parts_with_parent == possible_parent.parts_view().span();
}
DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path)
ByteString LexicalPath::canonicalized_path(ByteString path)
{
// NOTE: We never allow an empty m_string, if it's empty, we just set it to '.'.
if (path.is_empty())
@ -101,7 +101,7 @@ DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path)
auto is_absolute = path[0] == '/';
auto parts = path.split_view('/');
size_t approximate_canonical_length = 0;
Vector<DeprecatedString> canonical_parts;
Vector<ByteString> canonical_parts;
for (auto& part : parts) {
if (part == ".")
@ -131,10 +131,10 @@ DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path)
if (is_absolute)
builder.append('/');
builder.join('/', canonical_parts);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString LexicalPath::absolute_path(DeprecatedString dir_path, DeprecatedString target)
ByteString LexicalPath::absolute_path(ByteString dir_path, ByteString target)
{
if (LexicalPath(target).is_absolute()) {
return LexicalPath::canonicalized_path(target);
@ -142,10 +142,10 @@ DeprecatedString LexicalPath::absolute_path(DeprecatedString dir_path, Deprecate
return LexicalPath::canonicalized_path(join(dir_path, target).string());
}
DeprecatedString LexicalPath::relative_path(StringView a_path, StringView a_prefix)
ByteString 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<DeprecatedString>.
// FIXME: This should probably VERIFY or return an Optional<ByteString>.
return ""sv;
}
@ -186,7 +186,7 @@ DeprecatedString LexicalPath::relative_path(StringView a_path, StringView a_pref
builder.append('/');
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
LexicalPath LexicalPath::append(StringView value) const

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Vector.h>
// On Linux distros that use mlibc `basename` is defined as a macro that expands to `__mlibc_gnu_basename` or `__mlibc_gnu_basename_c`, so we undefine it.
@ -24,10 +24,10 @@ public:
Yes
};
explicit LexicalPath(DeprecatedString);
explicit LexicalPath(ByteString);
bool is_absolute() const { return !m_string.is_empty() && m_string[0] == '/'; }
DeprecatedString const& string() const { return m_string; }
ByteString const& string() const { return m_string; }
StringView dirname() const { return m_dirname; }
StringView basename(StripExtension s = StripExtension::No) const { return s == StripExtension::No ? m_basename : m_basename.substring_view(0, m_basename.length() - m_extension.length() - 1); }
@ -35,7 +35,7 @@ public:
StringView extension() const { return m_extension; }
Vector<StringView> const& parts_view() const { return m_parts; }
[[nodiscard]] Vector<DeprecatedString> parts() const;
[[nodiscard]] Vector<ByteString> parts() const;
bool has_extension(StringView) const;
bool is_child_of(LexicalPath const& possible_parent) const;
@ -44,9 +44,9 @@ public:
[[nodiscard]] LexicalPath prepend(StringView) const;
[[nodiscard]] LexicalPath parent() const;
[[nodiscard]] static DeprecatedString canonicalized_path(DeprecatedString);
[[nodiscard]] static DeprecatedString absolute_path(DeprecatedString dir_path, DeprecatedString target);
[[nodiscard]] static DeprecatedString relative_path(StringView absolute_path, StringView prefix);
[[nodiscard]] static ByteString canonicalized_path(ByteString);
[[nodiscard]] static ByteString absolute_path(ByteString dir_path, ByteString target);
[[nodiscard]] static ByteString relative_path(StringView absolute_path, StringView prefix);
template<typename... S>
[[nodiscard]] static LexicalPath join(StringView first, S&&... rest)
@ -55,28 +55,28 @@ public:
builder.append(first);
((builder.append('/'), builder.append(forward<S>(rest))), ...);
return LexicalPath { builder.to_deprecated_string() };
return LexicalPath { builder.to_byte_string() };
}
[[nodiscard]] static DeprecatedString dirname(DeprecatedString path)
[[nodiscard]] static ByteString dirname(ByteString path)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.dirname();
}
[[nodiscard]] static DeprecatedString basename(DeprecatedString path, StripExtension s = StripExtension::No)
[[nodiscard]] static ByteString basename(ByteString path, StripExtension s = StripExtension::No)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.basename(s);
}
[[nodiscard]] static DeprecatedString title(DeprecatedString path)
[[nodiscard]] static ByteString title(ByteString path)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.title();
}
[[nodiscard]] static DeprecatedString extension(DeprecatedString path)
[[nodiscard]] static ByteString extension(ByteString path)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.extension();
@ -84,7 +84,7 @@ public:
private:
Vector<StringView> m_parts;
DeprecatedString m_string;
ByteString m_string;
StringView m_dirname;
StringView m_basename;
StringView m_title;

View file

@ -15,7 +15,7 @@
#ifdef KERNEL
# include <Kernel/Library/KString.h>
#else
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
#endif
class [[gnu::packed]] MACAddress {
@ -64,9 +64,9 @@ public:
return Kernel::KString::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]);
}
#else
DeprecatedString to_deprecated_string() const
ByteString to_byte_string() const
{
return DeprecatedString::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]);
return ByteString::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]);
}
#endif

View file

@ -5,7 +5,7 @@
*/
#include <AK/Assertions.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/NumberFormat.h>
#include <AK/NumericLimits.h>
#include <AK/StringView.h>
@ -13,7 +13,7 @@
namespace AK {
// FIXME: Remove this hackery once printf() supports floats.
static DeprecatedString number_string_with_one_decimal(u64 number, u64 unit, StringView suffix, UseThousandsSeparator use_thousands_separator)
static ByteString number_string_with_one_decimal(u64 number, u64 unit, StringView suffix, UseThousandsSeparator use_thousands_separator)
{
constexpr auto max_unit_size = NumericLimits<u64>::max() / 10;
VERIFY(unit < max_unit_size);
@ -21,25 +21,25 @@ static DeprecatedString number_string_with_one_decimal(u64 number, u64 unit, Str
auto integer_part = number / unit;
auto decimal_part = (number % unit) * 10 / unit;
if (use_thousands_separator == UseThousandsSeparator::Yes)
return DeprecatedString::formatted("{:'d}.{} {}", integer_part, decimal_part, suffix);
return ByteString::formatted("{:'d}.{} {}", integer_part, decimal_part, suffix);
return DeprecatedString::formatted("{}.{} {}", integer_part, decimal_part, suffix);
return ByteString::formatted("{}.{} {}", integer_part, decimal_part, suffix);
}
DeprecatedString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on, StringView unit, UseThousandsSeparator use_thousands_separator)
ByteString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on, StringView unit, UseThousandsSeparator use_thousands_separator)
{
u64 size_of_unit = based_on == HumanReadableBasedOn::Base2 ? 1024 : 1000;
constexpr auto unit_prefixes = AK::Array { "", "K", "M", "G", "T", "P", "E" };
auto full_unit_suffix = [&](int index) {
auto binary_infix = (based_on == HumanReadableBasedOn::Base2 && index != 0) ? "i"sv : ""sv;
return DeprecatedString::formatted("{}{}{}",
return ByteString::formatted("{}{}{}",
unit_prefixes[index], binary_infix, unit);
};
auto size_of_current_unit = size_of_unit;
if (quantity < size_of_unit)
return DeprecatedString::formatted("{} {}", quantity, full_unit_suffix(0));
return ByteString::formatted("{} {}", quantity, full_unit_suffix(0));
for (size_t i = 1; i < unit_prefixes.size() - 1; i++) {
auto suffix = full_unit_suffix(i);
@ -54,28 +54,28 @@ DeprecatedString human_readable_quantity(u64 quantity, HumanReadableBasedOn base
size_of_current_unit, full_unit_suffix(unit_prefixes.size() - 1), use_thousands_separator);
}
DeprecatedString human_readable_size(u64 size, HumanReadableBasedOn based_on, UseThousandsSeparator use_thousands_separator)
ByteString human_readable_size(u64 size, HumanReadableBasedOn based_on, UseThousandsSeparator use_thousands_separator)
{
return human_readable_quantity(size, based_on, "B"sv, use_thousands_separator);
}
DeprecatedString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator)
ByteString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator)
{
if (size < 1 * KiB) {
if (use_thousands_separator == UseThousandsSeparator::Yes)
return DeprecatedString::formatted("{:'d} bytes", size);
return ByteString::formatted("{:'d} bytes", size);
return DeprecatedString::formatted("{} bytes", size);
return ByteString::formatted("{} bytes", size);
}
auto human_readable_size_string = human_readable_size(size, HumanReadableBasedOn::Base2, use_thousands_separator);
if (use_thousands_separator == UseThousandsSeparator::Yes)
return DeprecatedString::formatted("{} ({:'d} bytes)", human_readable_size_string, size);
return ByteString::formatted("{} ({:'d} bytes)", human_readable_size_string, size);
return DeprecatedString::formatted("{} ({} bytes)", human_readable_size_string, size);
return ByteString::formatted("{} ({} bytes)", human_readable_size_string, size);
}
DeprecatedString human_readable_time(i64 time_in_seconds)
ByteString human_readable_time(i64 time_in_seconds)
{
auto days = time_in_seconds / 86400;
time_in_seconds = time_in_seconds % 86400;
@ -99,10 +99,10 @@ DeprecatedString human_readable_time(i64 time_in_seconds)
builder.appendff("{} second{}", time_in_seconds, time_in_seconds == 1 ? "" : "s");
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString human_readable_digital_time(i64 time_in_seconds)
ByteString human_readable_digital_time(i64 time_in_seconds)
{
auto hours = time_in_seconds / 3600;
time_in_seconds = time_in_seconds % 3600;
@ -117,7 +117,7 @@ DeprecatedString human_readable_digital_time(i64 time_in_seconds)
builder.appendff("{:02}:", minutes);
builder.appendff("{:02}", time_in_seconds);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
namespace AK {
@ -20,12 +20,12 @@ enum class UseThousandsSeparator {
No
};
DeprecatedString human_readable_size(u64 size, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
DeprecatedString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, StringView unit = "B"sv, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
ByteString human_readable_size(u64 size, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
ByteString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, StringView unit = "B"sv, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
DeprecatedString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
DeprecatedString human_readable_time(i64 time_in_seconds);
DeprecatedString human_readable_digital_time(i64 time_in_seconds);
ByteString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
ByteString human_readable_time(i64 time_in_seconds);
ByteString human_readable_digital_time(i64 time_in_seconds);
}

View file

@ -66,7 +66,7 @@ private:
static constexpr SimpleReverseIterator rbegin(Container& container)
{
using RawContainerType = RemoveCV<Container>;
if constexpr (IsSame<StringView, RawContainerType> || IsSame<DeprecatedString, RawContainerType>)
if constexpr (IsSame<StringView, RawContainerType> || IsSame<ByteString, RawContainerType>)
return { container, static_cast<int>(container.length()) - 1 };
else
return { container, static_cast<int>(container.size()) - 1 };

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/SourceLocation.h>
#include <AK/StringBuilder.h>
@ -24,9 +24,9 @@ public:
for (auto indent = m_depth++; indent > 0; indent--)
sb.append(' ');
if (m_extra.is_empty())
dbgln("\033[1;{}m{}entering {}\033[0m", m_depth % 8 + 30, sb.to_deprecated_string(), m_location);
dbgln("\033[1;{}m{}entering {}\033[0m", m_depth % 8 + 30, sb.to_byte_string(), m_location);
else
dbgln("\033[1;{}m{}entering {}\033[0m ({})", m_depth % 8 + 30, sb.to_deprecated_string(), m_location, m_extra);
dbgln("\033[1;{}m{}entering {}\033[0m ({})", m_depth % 8 + 30, sb.to_byte_string(), m_location, m_extra);
}
ScopeLogger(SourceLocation location = SourceLocation::current())
@ -42,15 +42,15 @@ public:
for (auto indent = --m_depth; indent > 0; indent--)
sb.append(' ');
if (m_extra.is_empty())
dbgln("\033[1;{}m{}leaving {}\033[0m", depth % 8 + 30, sb.to_deprecated_string(), m_location);
dbgln("\033[1;{}m{}leaving {}\033[0m", depth % 8 + 30, sb.to_byte_string(), m_location);
else
dbgln("\033[1;{}m{}leaving {}\033[0m ({})", depth % 8 + 30, sb.to_deprecated_string(), m_location, m_extra);
dbgln("\033[1;{}m{}leaving {}\033[0m ({})", depth % 8 + 30, sb.to_byte_string(), m_location, m_extra);
}
private:
static inline size_t m_depth = 0;
SourceLocation m_location;
DeprecatedString m_extra;
ByteString m_extra;
};
template<>

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/GenericLexer.h>
#include <AK/HashMap.h>
#include <AK/String.h>
@ -116,12 +116,12 @@ public:
}
// FIXME: These are deprecated.
void set(StringView key, DeprecatedString value)
void set(StringView key, ByteString value)
{
set(key, MUST(String::from_deprecated_string(value)));
set(key, MUST(String::from_byte_string(value)));
}
template<size_t N>
void set(char const (&key)[N], DeprecatedString value)
void set(char const (&key)[N], ByteString value)
{
set(StringView { key, N - 1 }, value);
}

View file

@ -621,14 +621,14 @@ void String::did_create_fly_string(Badge<FlyString>) const
m_data->set_fly_string(true);
}
DeprecatedString String::to_deprecated_string() const
ByteString String::to_byte_string() const
{
return DeprecatedString(bytes_as_string_view());
return ByteString(bytes_as_string_view());
}
ErrorOr<String> String::from_deprecated_string(DeprecatedString const& deprecated_string)
ErrorOr<String> String::from_byte_string(ByteString const& byte_string)
{
return String::from_utf8(deprecated_string.view());
return String::from_utf8(byte_string.view());
}
bool String::equals_ignoring_ascii_case(StringView other) const

View file

@ -67,7 +67,7 @@ public:
// Creates a new String from a sequence of UTF-8 encoded code points.
static ErrorOr<String> from_utf8(StringView);
template<typename T>
requires(IsOneOf<RemoveCVReference<T>, DeprecatedString, DeprecatedFlyString, FlyString, String>)
requires(IsOneOf<RemoveCVReference<T>, ByteString, DeprecatedFlyString, FlyString, String>)
static ErrorOr<String> from_utf8(T&&) = delete;
// Creates a new String by reading byte_count bytes from a UTF-8 encoded Stream.
@ -221,11 +221,11 @@ public:
void did_create_fly_string(Badge<FlyString>) const;
// FIXME: Remove these once all code has been ported to String
[[nodiscard]] DeprecatedString to_deprecated_string() const;
static ErrorOr<String> from_deprecated_string(DeprecatedString const&);
[[nodiscard]] ByteString to_byte_string() const;
static ErrorOr<String> from_byte_string(ByteString const&);
template<typename T>
requires(IsSame<RemoveCVReference<T>, StringView>)
static ErrorOr<String> from_deprecated_string(T&&) = delete;
static ErrorOr<String> from_byte_string(T&&) = delete;
private:
// NOTE: If the least significant bit of the pointer is set, this is a short string.

View file

@ -15,7 +15,7 @@
#include <AK/Utf32View.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
# include <AK/FlyString.h>
# include <AK/Utf16View.h>
#endif
@ -144,11 +144,11 @@ ErrorOr<ByteBuffer> StringBuilder::to_byte_buffer() const
}
#ifndef KERNEL
DeprecatedString StringBuilder::to_deprecated_string() const
ByteString StringBuilder::to_byte_string() const
{
if (is_empty())
return DeprecatedString::empty();
return DeprecatedString((char const*)data(), length());
return ByteString::empty();
return ByteString((char const*)data(), length());
}
ErrorOr<String> StringBuilder::to_string() const

View file

@ -18,7 +18,7 @@ class StringBuilder {
public:
static constexpr size_t inline_capacity = 256;
using OutputType = DeprecatedString;
using OutputType = ByteString;
static ErrorOr<StringBuilder> create(size_t initial_capacity = inline_capacity);
@ -70,7 +70,7 @@ public:
}
#ifndef KERNEL
[[nodiscard]] DeprecatedString to_deprecated_string() const;
[[nodiscard]] ByteString to_byte_string() const;
#endif
ErrorOr<String> to_string() const;

View file

@ -17,7 +17,7 @@
#ifdef KERNEL
# include <Kernel/Library/StdLib.h>
#else
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
# include <AK/FloatingPointStringConversions.h>
# include <string.h>
#endif
@ -465,7 +465,7 @@ Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDire
}
#ifndef KERNEL
DeprecatedString to_snakecase(StringView str)
ByteString to_snakecase(StringView str)
{
auto should_insert_underscore = [&](auto i, auto current_char) {
if (i == 0)
@ -488,10 +488,10 @@ DeprecatedString to_snakecase(StringView str)
builder.append('_');
builder.append_as_lowercase(ch);
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString to_titlecase(StringView str)
ByteString to_titlecase(StringView str)
{
StringBuilder builder;
bool next_is_upper = true;
@ -504,10 +504,10 @@ DeprecatedString to_titlecase(StringView str)
next_is_upper = ch == ' ';
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString invert_case(StringView str)
ByteString invert_case(StringView str)
{
StringBuilder builder(str.length());
@ -518,10 +518,10 @@ DeprecatedString invert_case(StringView str)
builder.append(to_ascii_lowercase(ch));
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString replace(StringView str, StringView needle, StringView replacement, ReplaceMode replace_mode)
ByteString replace(StringView str, StringView needle, StringView replacement, ReplaceMode replace_mode)
{
if (str.is_empty())
return str;
@ -546,7 +546,7 @@ DeprecatedString replace(StringView str, StringView needle, StringView replaceme
last_position = position + needle.length();
}
replaced_string.append(str.substring_view(last_position, str.length() - last_position));
return replaced_string.to_deprecated_string();
return replaced_string.to_byte_string();
}
ErrorOr<String> replace(String const& haystack, StringView needle, StringView replacement, ReplaceMode replace_mode)

View file

@ -106,11 +106,11 @@ enum class SearchDirection {
};
Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDirection);
DeprecatedString to_snakecase(StringView);
DeprecatedString to_titlecase(StringView);
DeprecatedString invert_case(StringView);
ByteString to_snakecase(StringView);
ByteString to_titlecase(StringView);
ByteString invert_case(StringView);
DeprecatedString replace(StringView, StringView needle, StringView replacement, ReplaceMode);
ByteString replace(StringView, StringView needle, StringView replacement, ReplaceMode);
ErrorOr<String> replace(String const&, StringView needle, StringView replacement, ReplaceMode);
size_t count(StringView, StringView needle);

View file

@ -13,8 +13,8 @@
#include <AK/Vector.h>
#ifndef KERNEL
# include <AK/ByteString.h>
# include <AK/DeprecatedFlyString.h>
# include <AK/DeprecatedString.h>
# include <AK/FlyString.h>
# include <AK/String.h>
#endif
@ -34,7 +34,7 @@ StringView::StringView(FlyString const& string)
{
}
StringView::StringView(DeprecatedString const& string)
StringView::StringView(ByteString const& string)
: m_characters(string.characters())
, m_length(string.length())
{
@ -176,17 +176,17 @@ bool StringView::equals_ignoring_ascii_case(StringView other) const
}
#ifndef KERNEL
DeprecatedString StringView::to_lowercase_string() const
ByteString StringView::to_lowercase_string() const
{
return StringImpl::create_lowercased(characters_without_null_termination(), length()).release_nonnull();
}
DeprecatedString StringView::to_uppercase_string() const
ByteString StringView::to_uppercase_string() const
{
return StringImpl::create_uppercased(characters_without_null_termination(), length()).release_nonnull();
}
DeprecatedString StringView::to_titlecase_string() const
ByteString StringView::to_titlecase_string() const
{
return StringUtils::to_titlecase(*this);
}
@ -257,14 +257,14 @@ Optional<float> StringView::to_float(TrimWhitespace trim_whitespace) const
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
}
bool StringView::operator==(DeprecatedString const& string) const
bool StringView::operator==(ByteString const& string) const
{
return *this == string.view();
}
DeprecatedString StringView::to_deprecated_string() const { return DeprecatedString { *this }; }
ByteString StringView::to_byte_string() const { return ByteString { *this }; }
DeprecatedString StringView::replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const
ByteString StringView::replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const
{
return StringUtils::replace(*this, needle, replacement, replace_mode);
}

View file

@ -50,7 +50,7 @@ public:
#ifndef KERNEL
StringView(String const&);
StringView(FlyString const&);
StringView(DeprecatedString const&);
StringView(ByteString const&);
StringView(DeprecatedFlyString const&);
#endif
@ -58,11 +58,11 @@ public:
#ifndef KERNEL
explicit StringView(String&&) = delete;
explicit StringView(FlyString&&) = delete;
explicit StringView(DeprecatedString&&) = delete;
explicit StringView(ByteString&&) = delete;
explicit StringView(DeprecatedFlyString&&) = delete;
#endif
template<OneOf<String, FlyString, DeprecatedString, DeprecatedFlyString, ByteBuffer> StringType>
template<OneOf<String, FlyString, ByteString, DeprecatedFlyString, ByteBuffer> StringType>
StringView& operator=(StringType&&) = delete;
[[nodiscard]] constexpr bool is_null() const
@ -110,9 +110,9 @@ public:
[[nodiscard]] StringView trim_whitespace(TrimMode mode = TrimMode::Both) const { return StringUtils::trim_whitespace(*this, mode); }
#ifndef KERNEL
[[nodiscard]] DeprecatedString to_lowercase_string() const;
[[nodiscard]] DeprecatedString to_uppercase_string() const;
[[nodiscard]] DeprecatedString to_titlecase_string() const;
[[nodiscard]] ByteString to_lowercase_string() const;
[[nodiscard]] ByteString to_uppercase_string() const;
[[nodiscard]] ByteString to_titlecase_string() const;
#endif
[[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const
@ -272,7 +272,7 @@ public:
}
#ifndef KERNEL
bool operator==(DeprecatedString const&) const;
bool operator==(ByteString const&) const;
#endif
[[nodiscard]] constexpr int compare(StringView other) const
@ -314,7 +314,7 @@ public:
constexpr bool operator>=(StringView other) const { return compare(other) >= 0; }
#ifndef KERNEL
[[nodiscard]] DeprecatedString to_deprecated_string() const;
[[nodiscard]] ByteString to_byte_string() const;
#endif
[[nodiscard]] bool is_whitespace() const
@ -323,7 +323,7 @@ public:
}
#ifndef KERNEL
[[nodiscard]] DeprecatedString replace(StringView needle, StringView replacement, ReplaceMode) const;
[[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode) const;
#endif
[[nodiscard]] size_t count(StringView needle) const
{
@ -354,7 +354,7 @@ public:
}
private:
friend class DeprecatedString;
friend class ByteString;
char const* m_characters { nullptr };
size_t m_length { 0 };
};

View file

@ -38,21 +38,21 @@ URL URL::complete_url(StringView relative_url) const
ErrorOr<String> URL::username() const
{
return String::from_deprecated_string(percent_decode(m_username));
return String::from_byte_string(percent_decode(m_username));
}
ErrorOr<String> URL::password() const
{
return String::from_deprecated_string(percent_decode(m_password));
return String::from_byte_string(percent_decode(m_password));
}
DeprecatedString URL::path_segment_at_index(size_t index) const
ByteString URL::path_segment_at_index(size_t index) const
{
VERIFY(index < path_segment_count());
return percent_decode(m_paths[index]);
}
DeprecatedString URL::basename() const
ByteString URL::basename() const
{
if (!m_valid)
return {};
@ -72,7 +72,7 @@ void URL::set_scheme(String scheme)
ErrorOr<void> URL::set_username(StringView username)
{
// To set the username given a url and username, set urls username to the result of running UTF-8 percent-encode on username using the userinfo percent-encode set.
m_username = TRY(String::from_deprecated_string(percent_encode(username, PercentEncodeSet::Userinfo)));
m_username = TRY(String::from_byte_string(percent_encode(username, PercentEncodeSet::Userinfo)));
m_valid = compute_validity();
return {};
}
@ -81,7 +81,7 @@ ErrorOr<void> URL::set_username(StringView username)
ErrorOr<void> URL::set_password(StringView password)
{
// To set the password given a url and password, set urls password to the result of running UTF-8 percent-encode on password using the userinfo percent-encode set.
m_password = TRY(String::from_deprecated_string(percent_encode(password, PercentEncodeSet::Userinfo)));
m_password = TRY(String::from_byte_string(percent_encode(password, PercentEncodeSet::Userinfo)));
m_valid = compute_validity();
return {};
}
@ -108,18 +108,18 @@ void URL::set_port(Optional<u16> port)
m_valid = compute_validity();
}
void URL::set_paths(Vector<DeprecatedString> const& paths)
void URL::set_paths(Vector<ByteString> const& paths)
{
m_paths.clear_with_capacity();
m_paths.ensure_capacity(paths.size());
for (auto const& segment : paths)
m_paths.unchecked_append(String::from_deprecated_string(percent_encode(segment, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
m_paths.unchecked_append(String::from_byte_string(percent_encode(segment, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
m_valid = compute_validity();
}
void URL::append_path(StringView path)
{
m_paths.append(String::from_deprecated_string(percent_encode(path, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
m_paths.append(String::from_byte_string(percent_encode(path, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
}
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
@ -182,7 +182,7 @@ Optional<u16> URL::default_port_for_scheme(StringView scheme)
return {};
}
URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString const& fragment, DeprecatedString const& hostname)
URL URL::create_with_file_scheme(ByteString const& path, ByteString const& fragment, ByteString const& hostname)
{
LexicalPath lexical_path(path);
if (!lexical_path.is_absolute())
@ -190,38 +190,38 @@ URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString
URL url;
url.set_scheme("file"_string);
url.set_host(hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
url.set_host(hostname == "localhost" ? String {} : String::from_byte_string(hostname).release_value_but_fixme_should_propagate_errors());
url.set_paths(lexical_path.parts());
if (path.ends_with('/'))
url.append_slash();
if (!fragment.is_empty())
url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors());
url.set_fragment(String::from_byte_string(fragment).release_value_but_fixme_should_propagate_errors());
return url;
}
URL URL::create_with_help_scheme(DeprecatedString const& path, DeprecatedString const& fragment, DeprecatedString const& hostname)
URL URL::create_with_help_scheme(ByteString const& path, ByteString const& fragment, ByteString const& hostname)
{
LexicalPath lexical_path(path);
URL url;
url.set_scheme("help"_string);
url.set_host(hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
url.set_host(hostname == "localhost" ? String {} : String::from_byte_string(hostname).release_value_but_fixme_should_propagate_errors());
url.set_paths(lexical_path.parts());
if (path.ends_with('/'))
url.append_slash();
if (!fragment.is_empty())
url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors());
url.set_fragment(String::from_byte_string(fragment).release_value_but_fixme_should_propagate_errors());
return url;
}
URL URL::create_with_url_or_path(DeprecatedString const& url_or_path)
URL URL::create_with_url_or_path(ByteString const& url_or_path)
{
URL url = url_or_path;
if (url.is_valid())
return url;
DeprecatedString path = LexicalPath::canonicalized_path(url_or_path);
ByteString path = LexicalPath::canonicalized_path(url_or_path);
return URL::create_with_file_scheme(path);
}
@ -237,7 +237,7 @@ URL URL::create_with_data(StringView mime_type, StringView payload, bool is_base
builder.append(";base64"sv);
builder.append(',');
builder.append(payload);
url.set_paths({ builder.to_deprecated_string() });
url.set_paths({ builder.to_byte_string() });
return url;
}
@ -248,12 +248,12 @@ bool URL::is_special_scheme(StringView scheme)
}
// https://url.spec.whatwg.org/#url-path-serializer
DeprecatedString URL::serialize_path(ApplyPercentDecoding apply_percent_decoding) const
ByteString URL::serialize_path(ApplyPercentDecoding apply_percent_decoding) const
{
// 1. If url has an opaque path, then return urls path.
// FIXME: Reimplement this step once we modernize the URL implementation to meet the spec.
if (cannot_be_a_base_url())
return m_paths[0].to_deprecated_string();
return m_paths[0].to_byte_string();
// 2. Let output be the empty string.
StringBuilder output;
@ -261,15 +261,15 @@ DeprecatedString URL::serialize_path(ApplyPercentDecoding apply_percent_decoding
// 3. For each segment of urls path: append U+002F (/) followed by segment to output.
for (auto const& segment : m_paths) {
output.append('/');
output.append(apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(segment) : segment.to_deprecated_string());
output.append(apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(segment) : segment.to_byte_string());
}
// 4. Return output.
return output.to_deprecated_string();
return output.to_byte_string();
}
// https://url.spec.whatwg.org/#concept-url-serializer
DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
ByteString URL::serialize(ExcludeFragment exclude_fragment) const
{
// 1. Let output be urls scheme and U+003A (:) concatenated.
StringBuilder output;
@ -331,14 +331,14 @@ DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
}
// 7. Return output.
return output.to_deprecated_string();
return output.to_byte_string();
}
// https://url.spec.whatwg.org/#url-rendering
// NOTE: This does e.g. not display credentials.
// FIXME: Parts of the URL other than the host should have their sequences of percent-encoded bytes replaced with code points
// resulting from percent-decoding those sequences converted to bytes, unless that renders those sequences invisible.
DeprecatedString URL::serialize_for_display() const
ByteString URL::serialize_for_display() const
{
VERIFY(m_valid);
@ -374,17 +374,17 @@ DeprecatedString URL::serialize_for_display() const
builder.append(*m_fragment);
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
ErrorOr<String> URL::to_string() const
{
return String::from_deprecated_string(serialize());
return String::from_byte_string(serialize());
}
// https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin
// https://url.spec.whatwg.org/#concept-url-origin
DeprecatedString URL::serialize_origin() const
ByteString URL::serialize_origin() const
{
VERIFY(m_valid);
@ -407,7 +407,7 @@ DeprecatedString URL::serialize_origin() const
builder.append(serialized_host().release_value_but_fixme_should_propagate_errors());
if (m_port.has_value())
builder.appendff(":{}", *m_port);
return builder.to_deprecated_string();
return builder.to_byte_string();
}
bool URL::equals(URL const& other, ExcludeFragment exclude_fragments) const
@ -544,7 +544,7 @@ void URL::append_percent_encoded_if_necessary(StringBuilder& builder, u32 code_p
builder.append_code_point(code_point);
}
DeprecatedString URL::percent_encode(StringView input, URL::PercentEncodeSet set, SpaceAsPlus space_as_plus)
ByteString URL::percent_encode(StringView input, URL::PercentEncodeSet set, SpaceAsPlus space_as_plus)
{
StringBuilder builder;
for (auto code_point : Utf8View(input)) {
@ -553,10 +553,10 @@ DeprecatedString URL::percent_encode(StringView input, URL::PercentEncodeSet set
else
append_percent_encoded_if_necessary(builder, code_point, set);
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
DeprecatedString URL::percent_decode(StringView input)
ByteString URL::percent_decode(StringView input)
{
if (!input.contains('%'))
return input;
@ -575,7 +575,7 @@ DeprecatedString URL::percent_decode(StringView input)
builder.append(byte);
}
}
return builder.to_deprecated_string();
return builder.to_byte_string();
}
}

View file

@ -8,7 +8,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
@ -45,7 +45,7 @@ public:
URL() = default;
URL(StringView);
URL(DeprecatedString const& string)
URL(ByteString const& string)
: URL(string.view())
{
}
@ -77,11 +77,11 @@ public:
ErrorOr<String> password() const;
Host const& host() const { return m_host; }
ErrorOr<String> serialized_host() const;
DeprecatedString basename() const;
ByteString basename() const;
Optional<String> const& query() const { return m_query; }
Optional<String> const& fragment() const { return m_fragment; }
Optional<u16> port() const { return m_port; }
DeprecatedString path_segment_at_index(size_t index) const;
ByteString path_segment_at_index(size_t index) const;
size_t path_segment_count() const { return m_paths.size(); }
u16 port_or_default() const { return m_port.value_or(default_port_for_scheme(m_scheme).value_or(0)); }
@ -96,7 +96,7 @@ public:
ErrorOr<void> set_password(StringView);
void set_host(Host);
void set_port(Optional<u16>);
void set_paths(Vector<DeprecatedString> const&);
void set_paths(Vector<ByteString> const&);
void set_query(Optional<String> query) { m_query = move(query); }
void set_fragment(Optional<String> fragment) { m_fragment = move(fragment); }
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; }
@ -111,14 +111,14 @@ public:
Yes,
No
};
DeprecatedString serialize_path(ApplyPercentDecoding = ApplyPercentDecoding::Yes) const;
DeprecatedString serialize(ExcludeFragment = ExcludeFragment::No) const;
DeprecatedString serialize_for_display() const;
DeprecatedString to_deprecated_string() const { return serialize(); }
ByteString serialize_path(ApplyPercentDecoding = ApplyPercentDecoding::Yes) const;
ByteString serialize(ExcludeFragment = ExcludeFragment::No) const;
ByteString serialize_for_display() const;
ByteString to_byte_string() const { return serialize(); }
ErrorOr<String> to_string() const;
// HTML origin
DeprecatedString serialize_origin() const;
ByteString serialize_origin() const;
bool equals(URL const& other, ExcludeFragment = ExcludeFragment::No) const;
@ -130,9 +130,9 @@ public:
};
ErrorOr<DataURL> process_data_url() const;
static URL create_with_url_or_path(DeprecatedString const&);
static URL create_with_file_scheme(DeprecatedString const& path, DeprecatedString const& fragment = {}, DeprecatedString const& hostname = {});
static URL create_with_help_scheme(DeprecatedString const& path, DeprecatedString const& fragment = {}, DeprecatedString const& hostname = {});
static URL create_with_url_or_path(ByteString const&);
static URL create_with_file_scheme(ByteString const& path, ByteString const& fragment = {}, ByteString const& hostname = {});
static URL create_with_help_scheme(ByteString const& path, ByteString const& fragment = {}, ByteString const& hostname = {});
static URL create_with_data(StringView mime_type, StringView payload, bool is_base64 = false);
static Optional<u16> default_port_for_scheme(StringView);
@ -142,8 +142,8 @@ public:
No,
Yes,
};
static DeprecatedString percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo, SpaceAsPlus = SpaceAsPlus::No);
static DeprecatedString percent_decode(StringView input);
static ByteString percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo, SpaceAsPlus = SpaceAsPlus::No);
static ByteString percent_decode(StringView input);
bool operator==(URL const& other) const { return equals(other, ExcludeFragment::No); }
@ -198,7 +198,7 @@ struct Formatter<URL> : Formatter<StringView> {
template<>
struct Traits<URL> : public DefaultTraits<URL> {
static unsigned hash(URL const& url) { return url.to_deprecated_string().hash(); }
static unsigned hash(URL const& url) { return url.to_byte_string().hash(); }
};
}

View file

@ -5,9 +5,9 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/IntegralMath.h>
#include <AK/Optional.h>
#include <AK/SourceLocation.h>
@ -57,7 +57,7 @@ static Optional<URL::Host> parse_opaque_host(StringView input)
// currently report validation errors, they are only useful for debugging efforts in the URL parsing code.
// 4. Return the result of running UTF-8 percent-encode on input using the C0 control percent-encode set.
return String::from_deprecated_string(URL::percent_encode(input, URL::PercentEncodeSet::C0Control)).release_value_but_fixme_should_propagate_errors();
return String::from_byte_string(URL::percent_encode(input, URL::PercentEncodeSet::C0Control)).release_value_but_fixme_should_propagate_errors();
}
struct ParsedIPv4Number {
@ -606,7 +606,7 @@ static Optional<URL::Host> parse_host(StringView input, bool is_opaque = false)
// NOTE: This is handled in Unicode::create_unicode_url, to work around the fact that we can't call into LibUnicode here
// FIXME: 5. Let asciiDomain be the result of running domain to ASCII with domain and false.
// FIXME: 6. If asciiDomain is failure, then return failure.
auto ascii_domain_or_error = String::from_deprecated_string(domain);
auto ascii_domain_or_error = String::from_byte_string(domain);
if (ascii_domain_or_error.is_error())
return {};
@ -792,7 +792,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
if (start_index >= end_index)
return {};
DeprecatedString processed_input = raw_input.substring_view(start_index, end_index - start_index);
ByteString processed_input = raw_input.substring_view(start_index, end_index - start_index);
// 2. If input contains any ASCII tab or newline, invalid-URL-unit validation error.
// 3. Remove all ASCII tab or newline from input.
@ -1116,7 +1116,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
// 2. If atSignSeen is true, then prepend "%40" to buffer.
if (at_sign_seen) {
auto content = buffer.to_deprecated_string();
auto content = buffer.to_byte_string();
buffer.clear();
buffer.append("%40"sv);
buffer.append(content);

View file

@ -81,9 +81,9 @@ u32 Utf16View::decode_surrogate_pair(u16 high_surrogate, u16 low_surrogate)
return ((high_surrogate - high_surrogate_min) << 10) + (low_surrogate - low_surrogate_min) + first_supplementary_plane_code_point;
}
ErrorOr<DeprecatedString> Utf16View::to_deprecated_string(AllowInvalidCodeUnits allow_invalid_code_units) const
ErrorOr<ByteString> Utf16View::to_byte_string(AllowInvalidCodeUnits allow_invalid_code_units) const
{
return TRY(to_utf8(allow_invalid_code_units)).to_deprecated_string();
return TRY(to_utf8(allow_invalid_code_units)).to_byte_string();
}
ErrorOr<String> Utf16View::to_utf8(AllowInvalidCodeUnits allow_invalid_code_units) const

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Error.h>
#include <AK/Format.h>
#include <AK/Forward.h>
@ -78,7 +78,7 @@ public:
No,
};
ErrorOr<DeprecatedString> to_deprecated_string(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
ErrorOr<ByteString> to_byte_string(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
ErrorOr<String> to_utf8(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
bool is_null() const { return m_code_units.is_null(); }

View file

@ -12,7 +12,7 @@
#include <AK/Types.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/ByteString.h>
#endif
namespace AK {
@ -72,12 +72,12 @@ public:
}
#ifndef KERNEL
explicit Utf8View(DeprecatedString& string)
explicit Utf8View(ByteString& string)
: m_string(string.view())
{
}
explicit Utf8View(DeprecatedString&&) = delete;
explicit Utf8View(ByteString&&) = delete;
#endif
~Utf8View() = default;
@ -255,14 +255,14 @@ public:
return Utf8View(m_string).byte_offset_of(m_it);
}
DeprecatedStringCodePointIterator(DeprecatedString string)
DeprecatedStringCodePointIterator(ByteString string)
: m_string(move(string))
, m_it(Utf8View(m_string).begin())
{
}
private:
DeprecatedString m_string;
ByteString m_string;
Utf8CodePointIterator m_it;
};
#endif