AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
Notes: sideshowbarker 2024-07-18 04:38:32 +09:00
2006 changed files with 11635 additions and 11636 deletions

View File

@ -100,7 +100,7 @@ ErrorOr<ByteBuffer> decode_base64(StringView input)
return ByteBuffer::copy(output);
}
String encode_base64(ReadonlyBytes input)
DeprecatedString encode_base64(ReadonlyBytes input)
{
StringBuilder output(calculate_base64_encoded_length(input));

View File

@ -7,8 +7,8 @@
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/String.h>
#include <AK/StringView.h>
namespace AK {
@ -19,7 +19,7 @@ namespace AK {
[[nodiscard]] ErrorOr<ByteBuffer> decode_base64(StringView);
[[nodiscard]] String encode_base64(ReadonlyBytes);
[[nodiscard]] DeprecatedString encode_base64(ReadonlyBytes);
}
#if USING_AK_GLOBALLY

View File

@ -1,6 +1,7 @@
set(AK_SOURCES
Assertions.cpp
Base64.cpp
DeprecatedString.cpp
FloatingPointStringConversions.cpp
FlyString.cpp
Format.cpp
@ -14,7 +15,6 @@ set(AK_SOURCES
LexicalPath.cpp
Random.cpp
StackInfo.cpp
String.cpp
StringBuilder.cpp
StringFloatingPointConversions.cpp
StringImpl.cpp

View File

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

View File

@ -5,43 +5,43 @@
*/
#include <AK/ByteBuffer.h>
#include <AK/DeprecatedString.h>
#include <AK/FlyString.h>
#include <AK/Format.h>
#include <AK/Function.h>
#include <AK/Memory.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
namespace AK {
bool String::operator==(FlyString const& fly_string) const
bool DeprecatedString::operator==(FlyString const& fly_string) const
{
return m_impl == fly_string.impl() || view() == fly_string.view();
}
bool String::operator==(String const& other) const
bool DeprecatedString::operator==(DeprecatedString const& other) const
{
return m_impl == other.impl() || view() == other.view();
}
bool String::operator==(StringView other) const
bool DeprecatedString::operator==(StringView other) const
{
return view() == other;
}
bool String::operator<(String const& other) const
bool DeprecatedString::operator<(DeprecatedString const& other) const
{
return view() < other.view();
}
bool String::operator>(String const& other) const
bool DeprecatedString::operator>(DeprecatedString const& other) const
{
return view() > other.view();
}
bool String::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
bool DeprecatedString::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
{
// We must fit at least the NUL-terminator.
VERIFY(buffer_size > 0);
@ -53,7 +53,7 @@ bool String::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
return characters_to_copy == length();
}
String String::isolated_copy() const
DeprecatedString DeprecatedString::isolated_copy() const
{
if (!m_impl)
return {};
@ -62,27 +62,27 @@ String String::isolated_copy() const
char* buffer;
auto impl = StringImpl::create_uninitialized(length(), buffer);
memcpy(buffer, m_impl->characters(), m_impl->length());
return String(move(*impl));
return DeprecatedString(move(*impl));
}
String String::substring(size_t start, size_t length) const
DeprecatedString DeprecatedString::substring(size_t start, size_t length) const
{
if (!length)
return String::empty();
return DeprecatedString::empty();
VERIFY(m_impl);
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
VERIFY(start + length <= m_impl->length());
return { characters() + start, length };
}
String String::substring(size_t start) const
DeprecatedString DeprecatedString::substring(size_t start) const
{
VERIFY(m_impl);
VERIFY(start <= length());
return { characters() + start, length() - start };
}
StringView String::substring_view(size_t start, size_t length) const
StringView DeprecatedString::substring_view(size_t start, size_t length) const
{
VERIFY(m_impl);
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
@ -90,24 +90,24 @@ StringView String::substring_view(size_t start, size_t length) const
return { characters() + start, length };
}
StringView String::substring_view(size_t start) const
StringView DeprecatedString::substring_view(size_t start) const
{
VERIFY(m_impl);
VERIFY(start <= length());
return { characters() + start, length() - start };
}
Vector<String> String::split(char separator, SplitBehavior split_behavior) const
Vector<DeprecatedString> DeprecatedString::split(char separator, SplitBehavior split_behavior) const
{
return split_limit(separator, 0, split_behavior);
}
Vector<String> String::split_limit(char separator, size_t limit, SplitBehavior split_behavior) const
Vector<DeprecatedString> DeprecatedString::split_limit(char separator, size_t limit, SplitBehavior split_behavior) const
{
if (is_empty())
return {};
Vector<String> v;
Vector<DeprecatedString> v;
size_t substart = 0;
bool keep_empty = has_flag(split_behavior, SplitBehavior::KeepEmpty);
bool keep_separator = has_flag(split_behavior, SplitBehavior::KeepTrailingSeparator);
@ -126,7 +126,7 @@ Vector<String> String::split_limit(char separator, size_t limit, SplitBehavior s
return v;
}
Vector<StringView> String::split_view(Function<bool(char)> separator, SplitBehavior split_behavior) const
Vector<StringView> DeprecatedString::split_view(Function<bool(char)> separator, SplitBehavior split_behavior) const
{
if (is_empty())
return {};
@ -150,12 +150,12 @@ Vector<StringView> String::split_view(Function<bool(char)> separator, SplitBehav
return v;
}
Vector<StringView> String::split_view(char const separator, SplitBehavior split_behavior) const
Vector<StringView> DeprecatedString::split_view(char const separator, SplitBehavior split_behavior) const
{
return split_view([separator](char ch) { return ch == separator; }, split_behavior);
}
ByteBuffer String::to_byte_buffer() const
ByteBuffer DeprecatedString::to_byte_buffer() const
{
if (!m_impl)
return {};
@ -164,65 +164,65 @@ ByteBuffer String::to_byte_buffer() const
}
template<typename T>
Optional<T> String::to_int(TrimWhitespace trim_whitespace) const
Optional<T> DeprecatedString::to_int(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_int<T>(view(), trim_whitespace);
}
template Optional<i8> String::to_int(TrimWhitespace) const;
template Optional<i16> String::to_int(TrimWhitespace) const;
template Optional<i32> String::to_int(TrimWhitespace) const;
template Optional<i64> String::to_int(TrimWhitespace) const;
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<i64> DeprecatedString::to_int(TrimWhitespace) const;
template<typename T>
Optional<T> String::to_uint(TrimWhitespace trim_whitespace) const
Optional<T> DeprecatedString::to_uint(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_uint<T>(view(), trim_whitespace);
}
template Optional<u8> String::to_uint(TrimWhitespace) const;
template Optional<u16> String::to_uint(TrimWhitespace) const;
template Optional<u32> String::to_uint(TrimWhitespace) const;
template Optional<unsigned long> String::to_uint(TrimWhitespace) const;
template Optional<unsigned long long> String::to_uint(TrimWhitespace) const;
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;
#ifndef KERNEL
Optional<double> String::to_double(TrimWhitespace trim_whitespace) const
Optional<double> DeprecatedString::to_double(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_floating_point<double>(*this, trim_whitespace);
}
Optional<float> String::to_float(TrimWhitespace trim_whitespace) const
Optional<float> DeprecatedString::to_float(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
}
#endif
bool String::starts_with(StringView str, CaseSensitivity case_sensitivity) const
bool DeprecatedString::starts_with(StringView str, CaseSensitivity case_sensitivity) const
{
return StringUtils::starts_with(*this, str, case_sensitivity);
}
bool String::starts_with(char ch) const
bool DeprecatedString::starts_with(char ch) const
{
if (is_empty())
return false;
return characters()[0] == ch;
}
bool String::ends_with(StringView str, CaseSensitivity case_sensitivity) const
bool DeprecatedString::ends_with(StringView str, CaseSensitivity case_sensitivity) const
{
return StringUtils::ends_with(*this, str, case_sensitivity);
}
bool String::ends_with(char ch) const
bool DeprecatedString::ends_with(char ch) const
{
if (is_empty())
return false;
return characters()[length() - 1] == ch;
}
String String::repeated(char ch, size_t count)
DeprecatedString DeprecatedString::repeated(char ch, size_t count)
{
if (!count)
return empty();
@ -232,7 +232,7 @@ String String::repeated(char ch, size_t count)
return *impl;
}
String String::repeated(StringView string, size_t count)
DeprecatedString DeprecatedString::repeated(StringView string, size_t count)
{
if (!count || string.is_empty())
return empty();
@ -243,7 +243,7 @@ String String::repeated(StringView string, size_t count)
return *impl;
}
String String::bijective_base_from(size_t value, unsigned base, StringView map)
DeprecatedString DeprecatedString::bijective_base_from(size_t value, unsigned base, StringView map)
{
if (map.is_null())
map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"sv;
@ -267,13 +267,13 @@ String String::bijective_base_from(size_t value, unsigned base, StringView map)
for (size_t j = 0; j < i / 2; ++j)
swap(buffer[j], buffer[i - j - 1]);
return String { ReadonlyBytes(buffer.data(), i) };
return DeprecatedString { ReadonlyBytes(buffer.data(), i) };
}
String String::roman_number_from(size_t value)
DeprecatedString DeprecatedString::roman_number_from(size_t value)
{
if (value > 3999)
return String::number(value);
return DeprecatedString::number(value);
StringBuilder builder;
@ -323,32 +323,32 @@ String String::roman_number_from(size_t value)
return builder.to_string();
}
bool String::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
bool DeprecatedString::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
{
return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans);
}
bool String::matches(StringView mask, CaseSensitivity case_sensitivity) const
bool DeprecatedString::matches(StringView mask, CaseSensitivity case_sensitivity) const
{
return StringUtils::matches(*this, mask, case_sensitivity);
}
bool String::contains(StringView needle, CaseSensitivity case_sensitivity) const
bool DeprecatedString::contains(StringView needle, CaseSensitivity case_sensitivity) const
{
return StringUtils::contains(*this, needle, case_sensitivity);
}
bool String::contains(char needle, CaseSensitivity case_sensitivity) const
bool DeprecatedString::contains(char needle, CaseSensitivity case_sensitivity) const
{
return StringUtils::contains(*this, StringView(&needle, 1), case_sensitivity);
}
bool String::equals_ignoring_case(StringView other) const
bool DeprecatedString::equals_ignoring_case(StringView other) const
{
return StringUtils::equals_ignoring_case(view(), other);
}
String String::reverse() const
DeprecatedString DeprecatedString::reverse() const
{
StringBuilder reversed_string(length());
for (size_t i = length(); i-- > 0;) {
@ -357,7 +357,7 @@ String String::reverse() const
return reversed_string.to_string();
}
String escape_html_entities(StringView html)
DeprecatedString escape_html_entities(StringView html)
{
StringBuilder builder;
for (size_t i = 0; i < html.length(); ++i) {
@ -375,46 +375,46 @@ String escape_html_entities(StringView html)
return builder.to_string();
}
String::String(FlyString const& string)
DeprecatedString::DeprecatedString(FlyString const& string)
: m_impl(string.impl())
{
}
String String::to_lowercase() const
DeprecatedString DeprecatedString::to_lowercase() const
{
if (!m_impl)
return {};
return m_impl->to_lowercase();
}
String String::to_uppercase() const
DeprecatedString DeprecatedString::to_uppercase() const
{
if (!m_impl)
return {};
return m_impl->to_uppercase();
}
String String::to_snakecase() const
DeprecatedString DeprecatedString::to_snakecase() const
{
return StringUtils::to_snakecase(*this);
}
String String::to_titlecase() const
DeprecatedString DeprecatedString::to_titlecase() const
{
return StringUtils::to_titlecase(*this);
}
String String::invert_case() const
DeprecatedString DeprecatedString::invert_case() const
{
return StringUtils::invert_case(*this);
}
bool String::operator==(char const* cstring) const
bool DeprecatedString::operator==(char const* cstring) const
{
return view() == cstring;
}
InputStream& operator>>(InputStream& stream, String& string)
InputStream& operator>>(InputStream& stream, DeprecatedString& string)
{
StringBuilder builder;
@ -437,14 +437,14 @@ InputStream& operator>>(InputStream& stream, String& string)
}
}
String String::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
DeprecatedString DeprecatedString::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
{
StringBuilder builder;
MUST(vformat(builder, fmtstr, params));
return builder.to_string();
}
Vector<size_t> String::find_all(StringView needle) const
Vector<size_t> DeprecatedString::find_all(StringView needle) const
{
return StringUtils::find_all(*this, needle);
}

View File

@ -17,92 +17,92 @@
namespace AK {
// String is a convenience wrapper around StringImpl, suitable for passing
// DeprecatedString 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>, 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 String is very efficient, since the internal StringImpl is
// Copying a DeprecatedString 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 String:
// There are three main ways to construct a new DeprecatedString:
//
// s = String("some literal");
// s = DeprecatedString("some literal");
//
// s = String::formatted("{} little piggies", m_piggies);
// s = DeprecatedString::formatted("{} little piggies", m_piggies);
//
// StringBuilder builder;
// builder.append("abc");
// builder.append("123");
// s = builder.to_string();
class String {
class DeprecatedString {
public:
~String() = default;
~DeprecatedString() = default;
String() = default;
DeprecatedString() = default;
String(StringView view)
DeprecatedString(StringView view)
: m_impl(StringImpl::create(view.characters_without_null_termination(), view.length()))
{
}
String(String const& other)
: m_impl(const_cast<String&>(other).m_impl)
DeprecatedString(DeprecatedString const& other)
: m_impl(const_cast<DeprecatedString&>(other).m_impl)
{
}
String(String&& other)
DeprecatedString(DeprecatedString&& other)
: m_impl(move(other.m_impl))
{
}
String(char const* cstring, ShouldChomp shouldChomp = NoChomp)
DeprecatedString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
: m_impl(StringImpl::create(cstring, shouldChomp))
{
}
String(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
DeprecatedString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
: m_impl(StringImpl::create(cstring, length, shouldChomp))
{
}
explicit String(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
explicit DeprecatedString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
: m_impl(StringImpl::create(bytes, shouldChomp))
{
}
String(StringImpl const& impl)
DeprecatedString(StringImpl const& impl)
: m_impl(const_cast<StringImpl&>(impl))
{
}
String(StringImpl const* impl)
DeprecatedString(StringImpl const* impl)
: m_impl(const_cast<StringImpl*>(impl))
{
}
String(RefPtr<StringImpl>&& impl)
DeprecatedString(RefPtr<StringImpl>&& impl)
: m_impl(move(impl))
{
}
String(NonnullRefPtr<StringImpl>&& impl)
DeprecatedString(NonnullRefPtr<StringImpl>&& impl)
: m_impl(move(impl))
{
}
String(FlyString const&);
DeprecatedString(FlyString const&);
[[nodiscard]] static String repeated(char, size_t count);
[[nodiscard]] static String repeated(StringView, size_t count);
[[nodiscard]] static DeprecatedString repeated(char, size_t count);
[[nodiscard]] static DeprecatedString repeated(StringView, size_t count);
[[nodiscard]] static String bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
[[nodiscard]] static String roman_number_from(size_t value);
[[nodiscard]] static DeprecatedString bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
[[nodiscard]] static DeprecatedString roman_number_from(size_t value);
template<class SeparatorType, class CollectionType>
[[nodiscard]] static String join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
[[nodiscard]] static DeprecatedString join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
{
StringBuilder builder;
builder.join(separator, collection, fmtstr);
@ -121,15 +121,15 @@ public:
[[nodiscard]] Optional<float> to_float(TrimWhitespace = TrimWhitespace::Yes) const;
#endif
[[nodiscard]] String to_lowercase() const;
[[nodiscard]] String to_uppercase() const;
[[nodiscard]] String to_snakecase() const;
[[nodiscard]] String to_titlecase() const;
[[nodiscard]] String invert_case() const;
[[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]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
[[nodiscard]] String trim(StringView characters, TrimMode mode = TrimMode::Both) const
[[nodiscard]] DeprecatedString trim(StringView characters, TrimMode mode = TrimMode::Both) const
{
auto trimmed_view = StringUtils::trim(view(), characters, mode);
if (view() == trimmed_view)
@ -137,7 +137,7 @@ public:
return trimmed_view;
}
[[nodiscard]] String trim_whitespace(TrimMode mode = TrimMode::Both) const
[[nodiscard]] DeprecatedString trim_whitespace(TrimMode mode = TrimMode::Both) const
{
auto trimmed_view = StringUtils::trim_whitespace(view(), mode);
if (view() == trimmed_view)
@ -150,8 +150,8 @@ public:
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
[[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
[[nodiscard]] Vector<String> split_limit(char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<String> split(char separator, SplitBehavior = SplitBehavior::Nothing) 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<StringView> split_view(char separator, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<StringView> split_view(Function<bool(char)> separator, SplitBehavior = SplitBehavior::Nothing) const;
@ -165,8 +165,8 @@ public:
[[nodiscard]] StringView find_last_split_view(char separator) const { return view().find_last_split_view(separator); }
[[nodiscard]] String substring(size_t start, size_t length) const;
[[nodiscard]] String substring(size_t start) const;
[[nodiscard]] DeprecatedString substring(size_t start, size_t length) const;
[[nodiscard]] DeprecatedString substring(size_t start) const;
[[nodiscard]] StringView substring_view(size_t start, size_t length) const;
[[nodiscard]] StringView substring_view(size_t start) const;
@ -192,7 +192,7 @@ public:
return (*m_impl)[i];
}
using ConstIterator = SimpleIterator<const String, char const>;
using ConstIterator = SimpleIterator<const DeprecatedString, char const>;
[[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); }
[[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); }
@ -202,27 +202,27 @@ public:
[[nodiscard]] bool starts_with(char) const;
[[nodiscard]] bool ends_with(char) const;
bool operator==(String const&) const;
bool operator==(DeprecatedString const&) const;
bool operator==(StringView) const;
bool operator==(FlyString const&) const;
bool operator<(String const&) const;
bool operator<(DeprecatedString const&) const;
bool operator<(char const*) const;
bool operator>=(String const& other) const { return !(*this < other); }
bool operator>=(DeprecatedString const& other) const { return !(*this < other); }
bool operator>=(char const* other) const { return !(*this < other); }
bool operator>(String const&) const;
bool operator>(DeprecatedString const&) const;
bool operator>(char const*) const;
bool operator<=(String const& other) const { return !(*this > other); }
bool operator<=(DeprecatedString const& other) const { return !(*this > other); }
bool operator<=(char const* other) const { return !(*this > other); }
bool operator==(char const* cstring) const;
[[nodiscard]] String isolated_copy() const;
[[nodiscard]] DeprecatedString isolated_copy() const;
[[nodiscard]] static String empty()
[[nodiscard]] static DeprecatedString empty()
{
return StringImpl::the_empty_stringimpl();
}
@ -230,27 +230,27 @@ public:
[[nodiscard]] StringImpl* impl() { return m_impl.ptr(); }
[[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); }
String& operator=(String&& other)
DeprecatedString& operator=(DeprecatedString&& other)
{
if (this != &other)
m_impl = move(other.m_impl);
return *this;
}
String& operator=(String const& other)
DeprecatedString& operator=(DeprecatedString const& other)
{
if (this != &other)
m_impl = const_cast<String&>(other).m_impl;
m_impl = const_cast<DeprecatedString&>(other).m_impl;
return *this;
}
String& operator=(std::nullptr_t)
DeprecatedString& operator=(std::nullptr_t)
{
m_impl = nullptr;
return *this;
}
String& operator=(ReadonlyBytes bytes)
DeprecatedString& operator=(ReadonlyBytes bytes)
{
m_impl = StringImpl::create(bytes);
return *this;
@ -266,24 +266,24 @@ public:
[[nodiscard]] ByteBuffer to_byte_buffer() const;
template<typename BufferType>
[[nodiscard]] static String copy(BufferType const& buffer, ShouldChomp should_chomp = NoChomp)
[[nodiscard]] static DeprecatedString copy(BufferType const& buffer, ShouldChomp should_chomp = NoChomp)
{
if (buffer.is_empty())
return empty();
return String((char const*)buffer.data(), buffer.size(), should_chomp);
return DeprecatedString((char const*)buffer.data(), buffer.size(), should_chomp);
}
[[nodiscard]] static String vformatted(StringView fmtstr, TypeErasedFormatParams&);
[[nodiscard]] static DeprecatedString vformatted(StringView fmtstr, TypeErasedFormatParams&);
template<typename... Parameters>
[[nodiscard]] static String formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
[[nodiscard]] static DeprecatedString formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
{
VariadicFormatParams variadic_format_parameters { parameters... };
return vformatted(fmtstr.view(), variadic_format_parameters);
}
template<typename T>
[[nodiscard]] static String number(T value)
[[nodiscard]] static DeprecatedString number(T value)
requires IsArithmetic<T>
{
return formatted("{}", value);
@ -294,9 +294,9 @@ public:
return { characters(), length() };
}
[[nodiscard]] String replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }
[[nodiscard]] DeprecatedString replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }
[[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); }
[[nodiscard]] String reverse() const;
[[nodiscard]] DeprecatedString reverse() const;
template<typename... Ts>
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
@ -321,23 +321,22 @@ private:
};
template<>
struct Traits<String> : public GenericTraits<String> {
static unsigned hash(String const& s) { return s.impl() ? s.impl()->hash() : 0; }
struct Traits<DeprecatedString> : public GenericTraits<DeprecatedString> {
static unsigned hash(DeprecatedString const& s) { return s.impl() ? s.impl()->hash() : 0; }
};
struct CaseInsensitiveStringTraits : public Traits<String> {
static unsigned hash(String const& s) { return s.impl() ? s.impl()->case_insensitive_hash() : 0; }
static bool equals(String const& a, String const& b) { return a.equals_ignoring_case(b); }
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); }
};
String escape_html_entities(StringView html);
DeprecatedString escape_html_entities(StringView html);
InputStream& operator>>(InputStream& stream, String& string);
InputStream& operator>>(InputStream& stream, DeprecatedString& string);
}
#if USING_AK_GLOBALLY
using AK::CaseInsensitiveStringTraits;
using AK::escape_html_entities;
using AK::String;
#endif

View File

@ -4,11 +4,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/FlyString.h>
#include <AK/HashTable.h>
#include <AK/Optional.h>
#include <AK/Singleton.h>
#include <AK/String.h>
#include <AK/StringUtils.h>
#include <AK/StringView.h>
@ -36,7 +36,7 @@ void FlyString::did_destroy_impl(Badge<StringImpl>, StringImpl& impl)
fly_impls().remove(&impl);
}
FlyString::FlyString(String const& string)
FlyString::FlyString(DeprecatedString const& string)
{
if (string.is_null())
return;
@ -124,10 +124,10 @@ bool FlyString::ends_with(StringView str, CaseSensitivity case_sensitivity) cons
FlyString FlyString::to_lowercase() const
{
return String(*m_impl).to_lowercase();
return DeprecatedString(*m_impl).to_lowercase();
}
bool FlyString::operator==(String const& other) const
bool FlyString::operator==(DeprecatedString const& other) const
{
return m_impl == other.impl() || view() == other.view();
}

View File

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

View File

@ -256,7 +256,7 @@ ErrorOr<void> FormatBuilder::put_u64(
size_t used_by_prefix = 0;
if (align == Align::Right && zero_pad) {
// We want String::formatted("{:#08x}", 32) to produce '0x00000020' instead of '0x000020'. This
// We want DeprecatedString::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 {

View File

@ -427,7 +427,7 @@ struct Formatter<unsigned char[Size]> : Formatter<StringView> {
}
};
template<>
struct Formatter<String> : Formatter<StringView> {
struct Formatter<DeprecatedString> : Formatter<StringView> {
};
template<>
struct Formatter<FlyString> : Formatter<StringView> {

View File

@ -24,7 +24,7 @@ class JsonArray;
class JsonObject;
class JsonValue;
class StackInfo;
class String;
class DeprecatedString;
class StringBuilder;
class StringImpl;
class StringView;
@ -155,6 +155,7 @@ using AK::ByteBuffer;
using AK::Bytes;
using AK::CircularDuplexStream;
using AK::CircularQueue;
using AK::DeprecatedString;
using AK::DoublyLinkedList;
using AK::DuplexMemoryStream;
using AK::Error;
@ -187,7 +188,6 @@ using AK::RefPtr;
using AK::SinglyLinkedList;
using AK::Span;
using AK::StackInfo;
using AK::String;
using AK::StringBuilder;
using AK::StringImpl;
using AK::StringView;

View File

@ -10,7 +10,7 @@
#include <AK/StringBuilder.h>
#ifndef KERNEL
# include <AK/String.h>
# include <AK/DeprecatedString.h>
# include <AK/Utf16View.h>
#endif
@ -129,7 +129,7 @@ StringView GenericLexer::consume_quoted_string(char escape_char)
}
#ifndef KERNEL
String GenericLexer::consume_and_unescape_string(char escape_char)
DeprecatedString GenericLexer::consume_and_unescape_string(char escape_char)
{
auto view = consume_quoted_string(escape_char);
if (view.is_null())

View File

@ -84,7 +84,7 @@ public:
}
#ifndef KERNEL
bool consume_specific(String const& next)
bool consume_specific(DeprecatedString const& next)
{
return consume_specific(StringView { next });
}
@ -118,7 +118,7 @@ public:
StringView consume_until(StringView);
StringView consume_quoted_string(char escape_char = 0);
#ifndef KERNEL
String consume_and_unescape_string(char escape_char = '\\');
DeprecatedString consume_and_unescape_string(char escape_char = '\\');
#endif
enum class UnicodeEscapeError {

View File

@ -46,7 +46,7 @@ ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(const ReadonlyBytes input)
return Kernel::KString::try_create(output.string_view());
}
#else
String encode_hex(const ReadonlyBytes input)
DeprecatedString encode_hex(const ReadonlyBytes input)
{
StringBuilder output(input.size() * 2);

View File

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

View File

@ -16,7 +16,7 @@
# include <AK/Error.h>
# include <Kernel/KString.h>
#else
# include <AK/String.h>
# include <AK/DeprecatedString.h>
#endif
namespace AK {
@ -65,18 +65,18 @@ public:
octet(SubnetClass::D));
}
#else
String to_string() const
DeprecatedString to_string() const
{
return String::formatted("{}.{}.{}.{}",
return DeprecatedString::formatted("{}.{}.{}.{}",
octet(SubnetClass::A),
octet(SubnetClass::B),
octet(SubnetClass::C),
octet(SubnetClass::D));
}
String to_string_reversed() const
DeprecatedString to_string_reversed() const
{
return String::formatted("{}.{}.{}.{}",
return DeprecatedString::formatted("{}.{}.{}.{}",
octet(SubnetClass::D),
octet(SubnetClass::C),
octet(SubnetClass::B),
@ -166,10 +166,10 @@ struct Formatter<IPv4Address> : Formatter<ErrorOr<NonnullOwnPtr<Kernel::KString>
};
#else
template<>
struct Formatter<IPv4Address> : Formatter<String> {
struct Formatter<IPv4Address> : Formatter<DeprecatedString> {
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
{
return Formatter<String>::format(builder, value.to_string());
return Formatter<DeprecatedString>::format(builder, value.to_string());
}
};
#endif

View File

@ -16,7 +16,7 @@
# include <AK/Error.h>
# include <Kernel/KString.h>
#else
# include <AK/String.h>
# include <AK/DeprecatedString.h>
#endif
#include <AK/IPv4Address.h>
#include <AK/StringBuilder.h>
@ -51,7 +51,7 @@ public:
#ifdef KERNEL
ErrorOr<NonnullOwnPtr<Kernel::KString>> to_string() const
#else
String to_string() const
DeprecatedString to_string() const
#endif
{
if (is_zero()) {
@ -69,7 +69,7 @@ public:
#ifdef KERNEL
return Kernel::KString::formatted("::ffff:{}.{}.{}.{}", m_data[12], m_data[13], m_data[14], m_data[15]);
#else
return String::formatted("::ffff:{}.{}.{}.{}", m_data[12], m_data[13], m_data[14], m_data[15]);
return DeprecatedString::formatted("::ffff:{}.{}.{}.{}", m_data[12], m_data[13], m_data[14], m_data[15]);
#endif
}
@ -289,10 +289,10 @@ struct Formatter<IPv6Address> : Formatter<ErrorOr<NonnullOwnPtr<Kernel::KString>
};
#else
template<>
struct Formatter<IPv6Address> : Formatter<String> {
struct Formatter<IPv6Address> : Formatter<DeprecatedString> {
ErrorOr<void> format(FormatBuilder& builder, IPv6Address const& value)
{
return Formatter<String>::format(builder, value.to_string());
return Formatter<DeprecatedString>::format(builder, value.to_string());
}
};
#endif

View File

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

View File

@ -71,7 +71,7 @@ public:
template<typename Builder>
void serialize(Builder&) const;
[[nodiscard]] String to_string() const { return serialized<StringBuilder>(); }
[[nodiscard]] DeprecatedString to_string() const { return serialized<StringBuilder>(); }
template<typename Callback>
void for_each(Callback callback) const

View File

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

View File

@ -8,18 +8,18 @@
#pragma once
#include <AK/Concepts.h>
#include <AK/DeprecatedString.h>
#include <AK/Error.h>
#include <AK/HashMap.h>
#include <AK/JsonArray.h>
#include <AK/JsonObjectSerializer.h>
#include <AK/JsonValue.h>
#include <AK/String.h>
namespace AK {
class JsonObject {
template<typename Callback>
using CallbackErrorType = decltype(declval<Callback>()(declval<String const&>(), declval<JsonValue const&>()).release_error());
using CallbackErrorType = decltype(declval<Callback>()(declval<DeprecatedString const&>(), declval<JsonValue const&>()).release_error());
public:
JsonObject() = default;
@ -135,7 +135,7 @@ public:
}
#endif
void set(String const& key, JsonValue value)
void set(DeprecatedString const& key, JsonValue value)
{
m_members.set(key, move(value));
}
@ -147,7 +147,7 @@ public:
callback(member.key, member.value);
}
template<FallibleFunction<String const&, JsonValue const&> Callback>
template<FallibleFunction<DeprecatedString const&, JsonValue const&> Callback>
ErrorOr<void, CallbackErrorType<Callback>> try_for_each_member(Callback&& callback) const
{
for (auto const& member : m_members)
@ -166,10 +166,10 @@ public:
template<typename Builder>
void serialize(Builder&) const;
[[nodiscard]] String to_string() const { return serialized<StringBuilder>(); }
[[nodiscard]] DeprecatedString to_string() const { return serialized<StringBuilder>(); }
private:
OrderedHashMap<String, JsonValue> m_members;
OrderedHashMap<DeprecatedString, JsonValue> m_members;
};
template<typename Builder>

View File

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

View File

@ -18,7 +18,7 @@ constexpr bool is_space(int ch)
return ch == '\t' || ch == '\n' || ch == '\r' || ch == ' ';
}
ErrorOr<String> JsonParser::consume_and_unescape_string()
ErrorOr<DeprecatedString> JsonParser::consume_and_unescape_string()
{
if (!consume_specific('"'))
return Error::from_string_literal("JsonParser: Expected '\"'");

View File

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

View File

@ -31,7 +31,7 @@ JsonValue JsonPath::resolve(JsonValue const& top_root) const
return root;
}
String JsonPath::to_string() const
DeprecatedString JsonPath::to_string() const
{
StringBuilder builder;
builder.append("{ ."sv);

View File

@ -6,7 +6,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/Types.h>
#include <AK/Vector.h>
@ -34,7 +34,7 @@ public:
}
Kind kind() const { return m_kind; }
String const& key() const
DeprecatedString const& key() const
{
VERIFY(m_kind == Kind::Key);
return m_key;
@ -46,13 +46,13 @@ public:
return m_index;
}
String to_string() const
DeprecatedString to_string() const
{
switch (m_kind) {
case Kind::Key:
return key();
case Kind::Index:
return String::number(index());
return DeprecatedString::number(index());
default:
return "*";
}
@ -78,7 +78,7 @@ public:
private:
Kind m_kind;
String m_key;
DeprecatedString 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;
String to_string() const;
DeprecatedString to_string() const;
};
}

View File

@ -156,7 +156,7 @@ JsonValue::JsonValue(long long unsigned value)
}
JsonValue::JsonValue(char const* cstring)
: JsonValue(String(cstring))
: JsonValue(DeprecatedString(cstring))
{
}
@ -174,7 +174,7 @@ JsonValue::JsonValue(bool value)
m_value.as_bool = value;
}
JsonValue::JsonValue(String const& value)
JsonValue::JsonValue(DeprecatedString const& value)
{
if (value.is_null()) {
m_type = Type::Null;

View File

@ -11,7 +11,7 @@
#include <AK/StringBuilder.h>
#ifndef KERNEL
# include <AK/String.h>
# include <AK/DeprecatedString.h>
#endif
namespace AK {
@ -58,7 +58,7 @@ public:
JsonValue(bool);
JsonValue(char const*);
#ifndef KERNEL
JsonValue(String const&);
JsonValue(DeprecatedString const&);
#endif
JsonValue(StringView);
JsonValue(JsonArray const&);
@ -77,14 +77,14 @@ public:
void serialize(Builder&) const;
#ifndef KERNEL
String as_string_or(String const& alternative) const
DeprecatedString as_string_or(DeprecatedString const& alternative) const
{
if (is_string())
return as_string();
return alternative;
}
String to_string() const
DeprecatedString to_string() const
{
if (is_string())
return as_string();
@ -157,7 +157,7 @@ public:
}
#ifndef KERNEL
String as_string() const
DeprecatedString as_string() const
{
VERIFY(is_string());
return *m_value.as_string;

View File

@ -14,7 +14,7 @@ namespace AK {
char s_single_dot = '.';
LexicalPath::LexicalPath(String path)
LexicalPath::LexicalPath(DeprecatedString path)
: m_string(canonicalized_path(move(path)))
{
if (m_string.is_empty()) {
@ -58,9 +58,9 @@ LexicalPath::LexicalPath(String path)
}
}
Vector<String> LexicalPath::parts() const
Vector<DeprecatedString> LexicalPath::parts() const
{
Vector<String> vector;
Vector<DeprecatedString> vector;
vector.ensure_capacity(m_parts.size());
for (auto& part : m_parts)
vector.unchecked_append(part);
@ -72,7 +72,7 @@ bool LexicalPath::has_extension(StringView extension) const
return m_string.ends_with(extension, CaseSensitivity::CaseInsensitive);
}
String LexicalPath::canonicalized_path(String path)
DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path)
{
if (path.is_null())
return {};
@ -88,7 +88,7 @@ String LexicalPath::canonicalized_path(String path)
auto is_absolute = path[0] == '/';
auto parts = path.split_view('/');
size_t approximate_canonical_length = 0;
Vector<String> canonical_parts;
Vector<DeprecatedString> canonical_parts;
for (auto& part : parts) {
if (part == ".")
@ -121,7 +121,7 @@ String LexicalPath::canonicalized_path(String path)
return builder.to_string();
}
String LexicalPath::absolute_path(String dir_path, String target)
DeprecatedString LexicalPath::absolute_path(DeprecatedString dir_path, DeprecatedString target)
{
if (LexicalPath(target).is_absolute()) {
return LexicalPath::canonicalized_path(target);
@ -129,10 +129,10 @@ String LexicalPath::absolute_path(String dir_path, String target)
return LexicalPath::canonicalized_path(join(dir_path, target).string());
}
String LexicalPath::relative_path(StringView a_path, StringView a_prefix)
DeprecatedString LexicalPath::relative_path(StringView a_path, StringView a_prefix)
{
if (!a_path.starts_with('/') || !a_prefix.starts_with('/')) {
// FIXME: This should probably VERIFY or return an Optional<String>.
// FIXME: This should probably VERIFY or return an Optional<DeprecatedString>.
return ""sv;
}

View File

@ -7,7 +7,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.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.
@ -19,10 +19,10 @@ namespace AK {
class LexicalPath {
public:
explicit LexicalPath(String);
explicit LexicalPath(DeprecatedString);
bool is_absolute() const { return !m_string.is_empty() && m_string[0] == '/'; }
String const& string() const { return m_string; }
DeprecatedString const& string() const { return m_string; }
StringView dirname() const { return m_dirname; }
StringView basename() const { return m_basename; }
@ -30,7 +30,7 @@ public:
StringView extension() const { return m_extension; }
Vector<StringView> const& parts_view() const { return m_parts; }
[[nodiscard]] Vector<String> parts() const;
[[nodiscard]] Vector<DeprecatedString> parts() const;
bool has_extension(StringView) const;
@ -38,9 +38,9 @@ public:
[[nodiscard]] LexicalPath prepend(StringView) const;
[[nodiscard]] LexicalPath parent() const;
[[nodiscard]] static String canonicalized_path(String);
[[nodiscard]] static String absolute_path(String dir_path, String target);
[[nodiscard]] static String relative_path(StringView absolute_path, StringView prefix);
[[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);
template<typename... S>
[[nodiscard]] static LexicalPath join(StringView first, S&&... rest)
@ -52,25 +52,25 @@ public:
return LexicalPath { builder.to_string() };
}
[[nodiscard]] static String dirname(String path)
[[nodiscard]] static DeprecatedString dirname(DeprecatedString path)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.dirname();
}
[[nodiscard]] static String basename(String path)
[[nodiscard]] static DeprecatedString basename(DeprecatedString path)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.basename();
}
[[nodiscard]] static String title(String path)
[[nodiscard]] static DeprecatedString title(DeprecatedString path)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.title();
}
[[nodiscard]] static String extension(String path)
[[nodiscard]] static DeprecatedString extension(DeprecatedString path)
{
auto lexical_path = LexicalPath(move(path));
return lexical_path.extension();
@ -78,7 +78,7 @@ public:
private:
Vector<StringView> m_parts;
String m_string;
DeprecatedString m_string;
StringView m_dirname;
StringView m_basename;
StringView m_title;

View File

@ -15,7 +15,7 @@
#ifdef KERNEL
# include <Kernel/KString.h>
#else
# include <AK/String.h>
# include <AK/DeprecatedString.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
String to_string() const
DeprecatedString to_string() const
{
return String::formatted("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", m_data[0], m_data[1], m_data[2], m_data[3], m_data[4], m_data[5]);
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]);
}
#endif

View File

@ -6,21 +6,21 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
namespace AK {
// FIXME: Remove this hackery once printf() supports floats.
static String number_string_with_one_decimal(u64 number, u64 unit, char const* suffix)
static DeprecatedString number_string_with_one_decimal(u64 number, u64 unit, char const* suffix)
{
int decimal = (number % unit) * 10 / unit;
return String::formatted("{}.{} {}", number / unit, decimal, suffix);
return DeprecatedString::formatted("{}.{} {}", number / unit, decimal, suffix);
}
static inline String human_readable_size(u64 size)
static inline DeprecatedString human_readable_size(u64 size)
{
if (size < 1 * KiB)
return String::formatted("{} B", size);
return DeprecatedString::formatted("{} B", size);
if (size < 1 * MiB)
return number_string_with_one_decimal(size, KiB, "KiB");
if (size < 1 * GiB)
@ -34,15 +34,15 @@ static inline String human_readable_size(u64 size)
return number_string_with_one_decimal(size, EiB, "EiB");
}
static inline String human_readable_size_long(u64 size)
static inline DeprecatedString human_readable_size_long(u64 size)
{
if (size < 1 * KiB)
return String::formatted("{} bytes", size);
return DeprecatedString::formatted("{} bytes", size);
else
return String::formatted("{} ({} bytes)", human_readable_size(size), size);
return DeprecatedString::formatted("{} ({} bytes)", human_readable_size(size), size);
}
static inline String human_readable_time(i64 time_in_seconds)
static inline DeprecatedString human_readable_time(i64 time_in_seconds)
{
auto hours = time_in_seconds / 3600;
time_in_seconds = time_in_seconds % 3600;
@ -63,7 +63,7 @@ static inline String human_readable_time(i64 time_in_seconds)
return builder.to_string();
}
static inline String human_readable_digital_time(i64 time_in_seconds)
static inline DeprecatedString human_readable_digital_time(i64 time_in_seconds)
{
auto hours = time_in_seconds / 3600;
time_in_seconds = time_in_seconds % 3600;

View File

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

View File

@ -7,8 +7,8 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/SourceLocation.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
namespace AK {
@ -50,7 +50,7 @@ public:
private:
static inline size_t m_depth = 0;
SourceLocation m_location;
String m_extra;
DeprecatedString m_extra;
};
template<>

View File

@ -6,9 +6,9 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/GenericLexer.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
namespace AK {
@ -17,7 +17,7 @@ class SourceGenerator {
AK_MAKE_NONCOPYABLE(SourceGenerator);
public:
using MappingType = HashMap<StringView, String>;
using MappingType = HashMap<StringView, DeprecatedString>;
explicit SourceGenerator(StringBuilder& builder, char opening = '@', char closing = '@')
: m_builder(builder)
@ -37,7 +37,7 @@ public:
SourceGenerator fork() { return SourceGenerator { m_builder, m_mapping, m_opening, m_closing }; }
void set(StringView key, String value)
void set(StringView key, DeprecatedString value)
{
if (key.contains(m_opening) || key.contains(m_closing)) {
warnln("SourceGenerator keys cannot contain the opening/closing delimiters `{}` and `{}`. (Keys are only wrapped in these when using them, not when setting them.)", m_opening, m_closing);
@ -46,7 +46,7 @@ public:
m_mapping.set(key, move(value));
}
String get(StringView key) const
DeprecatedString get(StringView key) const
{
auto result = m_mapping.get(key);
if (!result.has_value()) {
@ -57,7 +57,7 @@ public:
}
StringView as_string_view() const { return m_builder.string_view(); }
String as_string() const { return m_builder.build(); }
DeprecatedString as_string() const { return m_builder.build(); }
void append(StringView pattern)
{
@ -92,13 +92,13 @@ public:
}
template<size_t N>
String get(char const (&key)[N])
DeprecatedString get(char const (&key)[N])
{
return get(StringView { key, N - 1 });
}
template<size_t N>
void set(char const (&key)[N], String value)
void set(char const (&key)[N], DeprecatedString value)
{
set(StringView { key, N - 1 }, value);
}

View File

@ -14,7 +14,7 @@
#include <AK/Utf32View.h>
#ifndef KERNEL
# include <AK/String.h>
# include <AK/DeprecatedString.h>
# include <AK/Utf16View.h>
#endif
@ -104,14 +104,14 @@ ByteBuffer StringBuilder::to_byte_buffer() const
}
#ifndef KERNEL
String StringBuilder::to_string() const
DeprecatedString StringBuilder::to_string() const
{
if (is_empty())
return String::empty();
return String((char const*)data(), length());
return DeprecatedString::empty();
return DeprecatedString((char const*)data(), length());
}
String StringBuilder::build() const
DeprecatedString StringBuilder::build() const
{
return to_string();
}

View File

@ -16,7 +16,7 @@ namespace AK {
class StringBuilder {
public:
using OutputType = String;
using OutputType = DeprecatedString;
explicit StringBuilder(size_t initial_capacity = inline_capacity);
~StringBuilder() = default;
@ -60,8 +60,8 @@ public:
}
#ifndef KERNEL
[[nodiscard]] String build() const;
[[nodiscard]] String to_string() const;
[[nodiscard]] DeprecatedString build() const;
[[nodiscard]] DeprecatedString to_string() const;
#endif
[[nodiscard]] ByteBuffer to_byte_buffer() const;

View File

@ -15,8 +15,8 @@
#include <AK/Vector.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/FloatingPointStringConversions.h>
# include <AK/String.h>
#endif
namespace AK {
@ -450,7 +450,7 @@ Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDire
}
#ifndef KERNEL
String to_snakecase(StringView str)
DeprecatedString to_snakecase(StringView str)
{
auto should_insert_underscore = [&](auto i, auto current_char) {
if (i == 0)
@ -476,7 +476,7 @@ String to_snakecase(StringView str)
return builder.to_string();
}
String to_titlecase(StringView str)
DeprecatedString to_titlecase(StringView str)
{
StringBuilder builder;
bool next_is_upper = true;
@ -492,7 +492,7 @@ String to_titlecase(StringView str)
return builder.to_string();
}
String invert_case(StringView str)
DeprecatedString invert_case(StringView str)
{
StringBuilder builder(str.length());
@ -506,7 +506,7 @@ String invert_case(StringView str)
return builder.to_string();
}
String replace(StringView str, StringView needle, StringView replacement, ReplaceMode replace_mode)
DeprecatedString replace(StringView str, StringView needle, StringView replacement, ReplaceMode replace_mode)
{
if (str.is_empty())
return str;

View File

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

View File

@ -14,14 +14,14 @@
#include <AK/Vector.h>
#ifndef KERNEL
# include <AK/DeprecatedString.h>
# include <AK/FlyString.h>
# include <AK/String.h>
#endif
namespace AK {
#ifndef KERNEL
StringView::StringView(String const& string)
StringView::StringView(DeprecatedString const& string)
: m_characters(string.characters())
, m_length(string.length())
{
@ -163,17 +163,17 @@ bool StringView::equals_ignoring_case(StringView other) const
}
#ifndef KERNEL
String StringView::to_lowercase_string() const
DeprecatedString StringView::to_lowercase_string() const
{
return StringImpl::create_lowercased(characters_without_null_termination(), length());
}
String StringView::to_uppercase_string() const
DeprecatedString StringView::to_uppercase_string() const
{
return StringImpl::create_uppercased(characters_without_null_termination(), length());
}
String StringView::to_titlecase_string() const
DeprecatedString StringView::to_titlecase_string() const
{
return StringUtils::to_titlecase(*this);
}
@ -246,14 +246,14 @@ Optional<float> StringView::to_float(TrimWhitespace trim_whitespace) const
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
}
bool StringView::operator==(String const& string) const
bool StringView::operator==(DeprecatedString const& string) const
{
return *this == string.view();
}
String StringView::to_string() const { return String { *this }; }
DeprecatedString StringView::to_string() const { return DeprecatedString { *this }; }
String StringView::replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const
DeprecatedString StringView::replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const
{
return StringUtils::replace(*this, needle, replacement, replace_mode);
}

View File

@ -42,13 +42,13 @@ public:
StringView(ByteBuffer const&);
#ifndef KERNEL
StringView(String const&);
StringView(DeprecatedString const&);
StringView(FlyString const&);
#endif
explicit StringView(ByteBuffer&&) = delete;
#ifndef KERNEL
explicit StringView(String&&) = delete;
explicit StringView(DeprecatedString&&) = delete;
explicit StringView(FlyString&&) = delete;
#endif
@ -97,9 +97,9 @@ public:
[[nodiscard]] StringView trim_whitespace(TrimMode mode = TrimMode::Both) const { return StringUtils::trim_whitespace(*this, mode); }
#ifndef KERNEL
[[nodiscard]] String to_lowercase_string() const;
[[nodiscard]] String to_uppercase_string() const;
[[nodiscard]] String to_titlecase_string() const;
[[nodiscard]] DeprecatedString to_lowercase_string() const;
[[nodiscard]] DeprecatedString to_uppercase_string() const;
[[nodiscard]] DeprecatedString to_titlecase_string() const;
#endif
[[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const
@ -246,7 +246,7 @@ public:
}
#ifndef KERNEL
bool operator==(String const&) const;
bool operator==(DeprecatedString const&) const;
#endif
[[nodiscard]] constexpr int compare(StringView other) const
@ -288,7 +288,7 @@ public:
constexpr bool operator>=(StringView other) const { return compare(other) >= 0; }
#ifndef KERNEL
[[nodiscard]] String to_string() const;
[[nodiscard]] DeprecatedString to_string() const;
#endif
[[nodiscard]] bool is_whitespace() const
@ -297,7 +297,7 @@ public:
}
#ifndef KERNEL
[[nodiscard]] String replace(StringView needle, StringView replacement, ReplaceMode) const;
[[nodiscard]] DeprecatedString replace(StringView needle, StringView replacement, ReplaceMode) const;
#endif
[[nodiscard]] size_t count(StringView needle) const
{
@ -323,7 +323,7 @@ public:
}
private:
friend class String;
friend class DeprecatedString;
char const* m_characters { nullptr };
size_t m_length { 0 };
};

View File

@ -27,7 +27,7 @@ URL::URL(StringView string)
}
}
String URL::path() const
DeprecatedString URL::path() const
{
if (cannot_be_a_base_url())
return paths()[0];
@ -39,7 +39,7 @@ String URL::path() const
return builder.to_string();
}
URL URL::complete_url(String const& string) const
URL URL::complete_url(DeprecatedString const& string) const
{
if (!is_valid())
return {};
@ -47,25 +47,25 @@ URL URL::complete_url(String const& string) const
return URLParser::parse(string, this);
}
void URL::set_scheme(String scheme)
void URL::set_scheme(DeprecatedString scheme)
{
m_scheme = move(scheme);
m_valid = compute_validity();
}
void URL::set_username(String username)
void URL::set_username(DeprecatedString username)
{
m_username = move(username);
m_valid = compute_validity();
}
void URL::set_password(String password)
void URL::set_password(DeprecatedString password)
{
m_password = move(password);
m_valid = compute_validity();
}
void URL::set_host(String host)
void URL::set_host(DeprecatedString host)
{
m_host = move(host);
m_valid = compute_validity();
@ -81,18 +81,18 @@ void URL::set_port(Optional<u16> port)
m_valid = compute_validity();
}
void URL::set_paths(Vector<String> paths)
void URL::set_paths(Vector<DeprecatedString> paths)
{
m_paths = move(paths);
m_valid = compute_validity();
}
void URL::set_query(String query)
void URL::set_query(DeprecatedString query)
{
m_query = move(query);
}
void URL::set_fragment(String fragment)
void URL::set_fragment(DeprecatedString fragment)
{
m_fragment = move(fragment);
}
@ -159,7 +159,7 @@ u16 URL::default_port_for_scheme(StringView scheme)
return 0;
}
URL URL::create_with_file_scheme(String const& path, String const& fragment, String const& hostname)
URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString const& fragment, DeprecatedString const& hostname)
{
LexicalPath lexical_path(path);
if (!lexical_path.is_absolute())
@ -169,7 +169,7 @@ URL URL::create_with_file_scheme(String const& path, String const& fragment, Str
url.set_scheme("file");
// NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
// This is because a file URL always needs a non-null hostname.
url.set_host(hostname.is_null() || hostname == "localhost" ? String::empty() : hostname);
url.set_host(hostname.is_null() || hostname == "localhost" ? DeprecatedString::empty() : hostname);
url.set_paths(lexical_path.parts());
// NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment.
if (path.ends_with('/'))
@ -178,7 +178,7 @@ URL URL::create_with_file_scheme(String const& path, String const& fragment, Str
return url;
}
URL URL::create_with_help_scheme(String const& path, String const& fragment, String const& hostname)
URL URL::create_with_help_scheme(DeprecatedString const& path, DeprecatedString const& fragment, DeprecatedString const& hostname)
{
LexicalPath lexical_path(path);
@ -186,7 +186,7 @@ URL URL::create_with_help_scheme(String const& path, String const& fragment, Str
url.set_scheme("help");
// NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
// This is because a file URL always needs a non-null hostname.
url.set_host(hostname.is_null() || hostname == "localhost" ? String::empty() : hostname);
url.set_host(hostname.is_null() || hostname == "localhost" ? DeprecatedString::empty() : hostname);
url.set_paths(lexical_path.parts());
// NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment.
if (path.ends_with('/'))
@ -195,13 +195,13 @@ URL URL::create_with_help_scheme(String const& path, String const& fragment, Str
return url;
}
URL URL::create_with_url_or_path(String const& url_or_path)
URL URL::create_with_url_or_path(DeprecatedString const& url_or_path)
{
URL url = url_or_path;
if (url.is_valid())
return url;
String path = LexicalPath::canonicalized_path(url_or_path);
DeprecatedString path = LexicalPath::canonicalized_path(url_or_path);
return URL::create_with_file_scheme(path);
}
@ -211,7 +211,7 @@ bool URL::is_special_scheme(StringView scheme)
return scheme.is_one_of("ftp", "file", "http", "https", "ws", "wss");
}
String URL::serialize_data_url() const
DeprecatedString URL::serialize_data_url() const
{
VERIFY(m_scheme == "data");
VERIFY(!m_data_mime_type.is_null());
@ -230,7 +230,7 @@ String URL::serialize_data_url() const
}
// https://url.spec.whatwg.org/#concept-url-serializer
String URL::serialize(ExcludeFragment exclude_fragment) const
DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
{
if (m_scheme == "data")
return serialize_data_url();
@ -283,7 +283,7 @@ String URL::serialize(ExcludeFragment exclude_fragment) const
// 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.
String URL::serialize_for_display() const
DeprecatedString URL::serialize_for_display() const
{
VERIFY(m_valid);
if (m_scheme == "data")
@ -325,7 +325,7 @@ String URL::serialize_for_display() const
// https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin
// https://url.spec.whatwg.org/#concept-url-origin
String URL::serialize_origin() const
DeprecatedString URL::serialize_origin() const
{
VERIFY(m_valid);
@ -360,7 +360,7 @@ bool URL::equals(URL const& other, ExcludeFragment exclude_fragments) const
return serialize(exclude_fragments) == other.serialize(exclude_fragments);
}
String URL::basename() const
DeprecatedString URL::basename() const
{
if (!m_valid)
return {};
@ -420,7 +420,7 @@ void URL::append_percent_encoded_if_necessary(StringBuilder& builder, u32 code_p
builder.append_code_point(code_point);
}
String URL::percent_encode(StringView input, URL::PercentEncodeSet set, SpaceAsPlus space_as_plus)
DeprecatedString URL::percent_encode(StringView input, URL::PercentEncodeSet set, SpaceAsPlus space_as_plus)
{
StringBuilder builder;
for (auto code_point : Utf8View(input)) {
@ -432,7 +432,7 @@ String URL::percent_encode(StringView input, URL::PercentEncodeSet set, SpaceAsP
return builder.to_string();
}
String URL::percent_decode(StringView input)
DeprecatedString URL::percent_decode(StringView input)
{
if (!input.contains('%'))
return input;

View File

@ -7,7 +7,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
@ -43,20 +43,20 @@ public:
URL() = default;
URL(StringView);
URL(String const& string)
URL(DeprecatedString const& string)
: URL(string.view())
{
}
bool is_valid() const { return m_valid; }
String const& scheme() const { return m_scheme; }
String const& username() const { return m_username; }
String const& password() const { return m_password; }
String const& host() const { return m_host; }
Vector<String> const& paths() const { return m_paths; }
String const& query() const { return m_query; }
String const& fragment() const { return m_fragment; }
DeprecatedString const& scheme() const { return m_scheme; }
DeprecatedString const& username() const { return m_username; }
DeprecatedString const& password() const { return m_password; }
DeprecatedString const& host() const { return m_host; }
Vector<DeprecatedString> const& paths() const { return m_paths; }
DeprecatedString const& query() const { return m_query; }
DeprecatedString const& fragment() const { return m_fragment; }
Optional<u16> port() const { return m_port; }
u16 port_or_default() const { return m_port.value_or(default_port_for_scheme(m_scheme)); }
bool cannot_be_a_base_url() const { return m_cannot_be_a_base_url; }
@ -65,39 +65,39 @@ public:
bool includes_credentials() const { return !m_username.is_empty() || !m_password.is_empty(); }
bool is_special() const { return is_special_scheme(m_scheme); }
void set_scheme(String);
void set_username(String);
void set_password(String);
void set_host(String);
void set_scheme(DeprecatedString);
void set_username(DeprecatedString);
void set_password(DeprecatedString);
void set_host(DeprecatedString);
void set_port(Optional<u16>);
void set_paths(Vector<String>);
void set_query(String);
void set_fragment(String);
void set_paths(Vector<DeprecatedString>);
void set_query(DeprecatedString);
void set_fragment(DeprecatedString);
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; }
void append_path(String path) { m_paths.append(move(path)); }
void append_path(DeprecatedString path) { m_paths.append(move(path)); }
String path() const;
String basename() const;
DeprecatedString path() const;
DeprecatedString basename() const;
String serialize(ExcludeFragment = ExcludeFragment::No) const;
String serialize_for_display() const;
String to_string() const { return serialize(); }
DeprecatedString serialize(ExcludeFragment = ExcludeFragment::No) const;
DeprecatedString serialize_for_display() const;
DeprecatedString to_string() const { return serialize(); }
// HTML origin
String serialize_origin() const;
DeprecatedString serialize_origin() const;
bool equals(URL const& other, ExcludeFragment = ExcludeFragment::No) const;
URL complete_url(String const&) const;
URL complete_url(DeprecatedString const&) const;
bool data_payload_is_base64() const { return m_data_payload_is_base64; }
String const& data_mime_type() const { return m_data_mime_type; }
String const& data_payload() const { return m_data_payload; }
DeprecatedString const& data_mime_type() const { return m_data_mime_type; }
DeprecatedString const& data_payload() const { return m_data_payload; }
static URL create_with_url_or_path(String const&);
static URL create_with_file_scheme(String const& path, String const& fragment = {}, String const& hostname = {});
static URL create_with_help_scheme(String const& path, String const& fragment = {}, String const& hostname = {});
static URL create_with_data(String mime_type, String payload, bool is_base64 = false) { return URL(move(mime_type), move(payload), is_base64); };
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_data(DeprecatedString mime_type, DeprecatedString payload, bool is_base64 = false) { return URL(move(mime_type), move(payload), is_base64); };
static bool scheme_requires_port(StringView);
static u16 default_port_for_scheme(StringView);
@ -107,15 +107,15 @@ public:
No,
Yes,
};
static String percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo, SpaceAsPlus = SpaceAsPlus::No);
static String percent_decode(StringView input);
static DeprecatedString percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo, SpaceAsPlus = SpaceAsPlus::No);
static DeprecatedString percent_decode(StringView input);
bool operator==(URL const& other) const { return equals(other, ExcludeFragment::No); }
static bool code_point_is_in_percent_encode_set(u32 code_point, URL::PercentEncodeSet);
private:
URL(String&& data_mime_type, String&& data_payload, bool payload_is_base64)
URL(DeprecatedString&& data_mime_type, DeprecatedString&& data_payload, bool payload_is_base64)
: m_valid(true)
, m_scheme("data")
, m_data_payload_is_base64(payload_is_base64)
@ -125,29 +125,29 @@ private:
}
bool compute_validity() const;
String serialize_data_url() const;
DeprecatedString serialize_data_url() const;
static void append_percent_encoded_if_necessary(StringBuilder&, u32 code_point, PercentEncodeSet set = PercentEncodeSet::Userinfo);
static void append_percent_encoded(StringBuilder&, u32 code_point);
bool m_valid { false };
String m_scheme;
String m_username;
String m_password;
String m_host;
DeprecatedString m_scheme;
DeprecatedString m_username;
DeprecatedString m_password;
DeprecatedString m_host;
// NOTE: If the port is the default port for the scheme, m_port should be empty.
Optional<u16> m_port;
String m_path;
Vector<String> m_paths;
String m_query;
String m_fragment;
DeprecatedString m_path;
Vector<DeprecatedString> m_paths;
DeprecatedString m_query;
DeprecatedString m_fragment;
bool m_cannot_be_a_base_url { false };
bool m_data_payload_is_base64 { false };
String m_data_mime_type;
String m_data_payload;
DeprecatedString m_data_mime_type;
DeprecatedString m_data_payload;
};
template<>

View File

@ -6,9 +6,9 @@
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/SourceLocation.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/StringUtils.h>
#include <AK/URLParser.h>
@ -30,7 +30,7 @@ static void report_validation_error(SourceLocation const& location = SourceLocat
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Validation error! {}", location);
}
static Optional<String> parse_opaque_host(StringView input)
static Optional<DeprecatedString> parse_opaque_host(StringView input)
{
auto forbidden_host_characters_excluding_percent = "\0\t\n\r #/:<>?@[\\]^|"sv;
for (auto character : forbidden_host_characters_excluding_percent) {
@ -44,7 +44,7 @@ static Optional<String> parse_opaque_host(StringView input)
return URL::percent_encode(input, URL::PercentEncodeSet::C0Control);
}
static Optional<String> parse_ipv4_address(StringView input)
static Optional<DeprecatedString> parse_ipv4_address(StringView input)
{
// FIXME: Implement the correct IPv4 parser as specified by https://url.spec.whatwg.org/#concept-ipv4-parser.
return input;
@ -52,7 +52,7 @@ static Optional<String> parse_ipv4_address(StringView input)
// https://url.spec.whatwg.org/#concept-host-parser
// NOTE: This is a very bare-bones implementation.
static Optional<String> parse_host(StringView input, bool is_not_special = false)
static Optional<DeprecatedString> parse_host(StringView input, bool is_not_special = false)
{
if (input.starts_with('[')) {
if (!input.ends_with(']')) {
@ -117,7 +117,7 @@ constexpr bool is_double_dot_path_segment(StringView input)
}
// https://url.spec.whatwg.org/#string-percent-encode-after-encoding
static String percent_encode_after_encoding(StringView input, URL::PercentEncodeSet percent_encode_set, bool space_as_plus = false)
static DeprecatedString percent_encode_after_encoding(StringView input, URL::PercentEncodeSet percent_encode_set, bool space_as_plus = false)
{
// NOTE: This is written somewhat ad-hoc since we don't yet implement the Encoding spec.
@ -241,7 +241,7 @@ URL URLParser::parse(StringView raw_input, URL const* base_url, Optional<URL> ur
if (start_index >= end_index)
return {};
String processed_input = raw_input.substring_view(start_index, end_index - start_index);
DeprecatedString processed_input = raw_input.substring_view(start_index, end_index - start_index);
// NOTE: This replaces all tab and newline characters with nothing.
if (processed_input.contains("\t"sv) || processed_input.contains("\n"sv)) {

View File

@ -97,7 +97,7 @@ ErrorOr<NonnullOwnPtr<Kernel::KString>> UUID::to_string() const
return Kernel::KString::try_create(builder.string_view());
}
#else
String UUID::to_string() const
DeprecatedString UUID::to_string() const
{
StringBuilder builder(36);
builder.append(encode_hex(m_uuid_buffer.span().trim(4)).view());

View File

@ -14,7 +14,7 @@
#ifdef KERNEL
# include <Kernel/KString.h>
#else
# include <AK/String.h>
# include <AK/DeprecatedString.h>
#endif
namespace AK {
@ -36,7 +36,7 @@ public:
#ifdef KERNEL
ErrorOr<NonnullOwnPtr<Kernel::KString>> to_string() const;
#else
String to_string() const;
DeprecatedString to_string() const;
#endif
bool is_zero() const;

View File

@ -79,7 +79,7 @@ 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;
}
String Utf16View::to_utf8(AllowInvalidCodeUnits allow_invalid_code_units) const
DeprecatedString Utf16View::to_utf8(AllowInvalidCodeUnits allow_invalid_code_units) const
{
StringBuilder builder;

View File

@ -6,11 +6,11 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/Forward.h>
#include <AK/Optional.h>
#include <AK/Span.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Vector.h>
@ -72,7 +72,7 @@ public:
No,
};
String to_utf8(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
DeprecatedString to_utf8(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
bool is_null() const { return m_code_units.is_null(); }
bool is_empty() const { return m_code_units.is_empty(); }

View File

@ -7,7 +7,7 @@
#pragma once
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/StringView.h>
#include <AK/Types.h>
@ -60,7 +60,7 @@ public:
Utf8View() = default;
explicit Utf8View(String& string)
explicit Utf8View(DeprecatedString& string)
: m_string(string.view())
{
}
@ -72,7 +72,7 @@ public:
~Utf8View() = default;
explicit Utf8View(String&&) = delete;
explicit Utf8View(DeprecatedString&&) = delete;
StringView as_string() const { return m_string; }

View File

@ -5,17 +5,17 @@ clipboard - Data formats specific to Clipboard and drag & drop
## Clipboard
The clipboard feature works through the Clipboard server, which generally acts as a global storage or three things:
- a `String` mime type,
- a `DeprecatedString` mime type,
- a (potentially large) block of data, shared as an anonymous file,
- a `HashMap<String, String>` of arbitrary metadata, depending on the mime type.
- a `HashMap<DeprecatedString, DeprecatedString>` of arbitrary metadata, depending on the mime type.
See also [`Userland/Libraries/LibGUI/Clipboard.h`](../../../../../Userland/Libraries/LibGUI/Clipboard.h).
## Drag & drop
In contrast to the clipboard, the drag & drop feature works through WindowServer, and a bouquet of data is transmitted:
- a `[UTF8] String` to be displayed while dragging,
- a `HashMap<String, ByteBuffer>` map that contains arbitrary data for a variety of possible mime types,
- a `[UTF8] DeprecatedString` to be displayed while dragging,
- a `HashMap<DeprecatedString, ByteBuffer>` map that contains arbitrary data for a variety of possible mime types,
- a `Gfx::ShareableBitmap` to be displayed while dragging
Drag & drop is most prominently supported by File Manager, Spreadsheet, and Terminal.

View File

@ -31,7 +31,7 @@ Start from defining an endpoint in the IPC file in `MyServer.ipc`.
```
endpoint MyServer
{
SyncAPI(String text) => (i32 status)
SyncAPI(DeprecatedString text) => (i32 status)
AsyncAPI(i32 mode) =|
}
```
@ -42,7 +42,7 @@ Part of the generated C++ messages:
class SyncAPI final : public IPC::Message {
public:
using ResponseType = SyncAPIResponse;
SyncAPI(const String& text) : m_text(text) {}
SyncAPI(const DeprecatedString& text) : m_text(text) {}
virtual ~SyncAPI() override {}
static OwnPtr<SyncAPI> decode(...);
virtual IPC::MessageBuffer encode(...) const override;

View File

@ -1,6 +1,6 @@
# String Formatting
Many places in Serenity allow you to format strings, similar to `printf()`, for example `String::formatted()`
Many places in Serenity allow you to format strings, similar to `printf()`, for example `DeprecatedString::formatted()`
, `StringBuilder::appendff()`, or `dbgln()`. These are checked at compile time to ensure the format string matches the
number of parameters. The syntax is largely based on
the [C++ `std::formatter` syntax](https://en.cppreference.com/w/cpp/utility/format/formatter#Standard_format_specification)
@ -10,27 +10,27 @@ For basic usage, any occurrences of `{}` in the format string are replaced with
form, in order:
```c++
String::formatted("Well, {} my {} friends!", "hello", 42) == "Well, hello my 42 friends!";
DeprecatedString::formatted("Well, {} my {} friends!", "hello", 42) == "Well, hello my 42 friends!";
```
If you want to include a literal `{` in the output, use `{{`:
```c++
String::formatted("{{ {}", "hello") == "{ hello";
DeprecatedString::formatted("{{ {}", "hello") == "{ hello";
```
You can refer to the arguments by index, if you want to repeat one or change the order:
```c++
String::formatted("{2}{0}{1}", "a", "b", "c") == "cab";
DeprecatedString::formatted("{2}{0}{1}", "a", "b", "c") == "cab";
```
To control how the arguments are formatted, add colon after the optional index, and then add format specifier
characters:
```c++
String::formatted("{:.4}", "cool dude") == "cool";
String::formatted("{0:.4}", "cool dude") == "cool";
DeprecatedString::formatted("{:.4}", "cool dude") == "cool";
DeprecatedString::formatted("{0:.4}", "cool dude") == "cool";
```
## Format specifiers
@ -135,6 +135,6 @@ type cannot be formatted. For example:
```c++
// B has a Formatter defined, but A does not.
String::formatted("{}", FormatIfSupported { A {} }) == "?";
String::formatted("{}", FormatIfSupported { B {} }) == "B";
DeprecatedString::formatted("{}", FormatIfSupported { A {} }) == "?";
DeprecatedString::formatted("{}", FormatIfSupported { B {} }) == "B";
```

View File

@ -6,9 +6,9 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Platform.h>
#include <AK/ScopeGuard.h>
#include <AK/String.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
@ -34,7 +34,7 @@ ALWAYS_INLINE int graphics_connector_get_head_edid(int fd, GraphicsHeadEDID* inf
}
auto minor_number = minor(display_connector_stat.st_rdev);
auto edid_fd = open(String::formatted("/sys/devices/graphics/connectors/{}/edid", minor_number).characters(), O_RDONLY);
auto edid_fd = open(DeprecatedString::formatted("/sys/devices/graphics/connectors/{}/edid", minor_number).characters(), O_RDONLY);
if (edid_fd < 0) {
return edid_fd;
}

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <LibTextCodec/Decoder.h>
#include <stddef.h>
#include <stdint.h>

View File

@ -5,8 +5,8 @@
*/
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/String.h>
#include <LibGfx/GIFLoader.h>
#include <stddef.h>
#include <stdint.h>

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <LibTextCodec/Decoder.h>
#include <stddef.h>
#include <stdint.h>

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <LibTextCodec/Decoder.h>
#include <stddef.h>
#include <stdint.h>

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <LibTextCodec/Decoder.h>
#include <stddef.h>
#include <stdint.h>

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/StringView.h>
#include <LibIMAP/QuotedPrintable.h>

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <LibTextCodec/Decoder.h>
#include <stddef.h>
#include <stdint.h>

View File

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <LibJS/Forward.h>
#include <LibJS/Interpreter.h>

View File

@ -16,12 +16,12 @@
#include <stdio.h>
struct Parameter {
Vector<String> attributes;
String type;
String name;
Vector<DeprecatedString> attributes;
DeprecatedString type;
DeprecatedString name;
};
static String pascal_case(String const& identifier)
static DeprecatedString pascal_case(DeprecatedString const& identifier)
{
StringBuilder builder;
bool was_new_word = true;
@ -40,12 +40,12 @@ static String pascal_case(String const& identifier)
}
struct Message {
String name;
DeprecatedString name;
bool is_synchronous { false };
Vector<Parameter> inputs;
Vector<Parameter> outputs;
String response_name() const
DeprecatedString response_name() const
{
StringBuilder builder;
builder.append(pascal_case(name));
@ -55,18 +55,18 @@ struct Message {
};
struct Endpoint {
Vector<String> includes;
String name;
Vector<DeprecatedString> includes;
DeprecatedString name;
u32 magic;
Vector<Message> messages;
};
static bool is_primitive_type(String const& type)
static bool is_primitive_type(DeprecatedString const& type)
{
return type.is_one_of("u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "bool", "double", "float", "int", "unsigned", "unsigned int");
}
static String message_name(String const& endpoint, String const& message, bool is_response)
static DeprecatedString message_name(DeprecatedString const& endpoint, DeprecatedString const& message, bool is_response)
{
StringBuilder builder;
builder.append("Messages::"sv);
@ -121,7 +121,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
consume_whitespace();
}
}
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, String>`.
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, DeprecatedString>`.
// Maybe we should use LibCpp::Parser for parsing types.
parameter.type = lexer.consume_until([](char ch) { return isspace(ch); });
VERIFY(!lexer.is_eof());
@ -191,7 +191,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
};
auto parse_include = [&] {
String include;
DeprecatedString include;
consume_whitespace();
include = lexer.consume_while([](char ch) { return ch != '\n'; });
consume_whitespace();
@ -217,7 +217,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
lexer.consume_specific("endpoint");
consume_whitespace();
endpoints.last().name = lexer.consume_while([](char ch) { return !isspace(ch); });
endpoints.last().magic = Traits<String>::hash(endpoints.last().name);
endpoints.last().magic = Traits<DeprecatedString>::hash(endpoints.last().name);
consume_whitespace();
assert_specific('{');
parse_messages();
@ -231,22 +231,22 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
return endpoints;
}
HashMap<String, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
HashMap<DeprecatedString, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
{
HashMap<String, int> message_ids;
HashMap<DeprecatedString, int> message_ids;
generator.appendln("\nenum class MessageID : i32 {");
for (auto const& message : endpoint.messages) {
message_ids.set(message.name, message_ids.size() + 1);
generator.set("message.pascal_name", pascal_case(message.name));
generator.set("message.id", String::number(message_ids.size()));
generator.set("message.id", DeprecatedString::number(message_ids.size()));
generator.appendln(" @message.pascal_name@ = @message.id@,");
if (message.is_synchronous) {
message_ids.set(message.response_name(), message_ids.size() + 1);
generator.set("message.pascal_name", pascal_case(message.response_name()));
generator.set("message.id", String::number(message_ids.size()));
generator.set("message.id", DeprecatedString::number(message_ids.size()));
generator.appendln(" @message.pascal_name@ = @message.id@,");
}
@ -255,7 +255,7 @@ HashMap<String, int> build_message_ids_for_endpoint(SourceGenerator generator, E
return message_ids;
}
String constructor_for_message(String const& name, Vector<Parameter> const& parameters)
DeprecatedString constructor_for_message(DeprecatedString const& name, Vector<Parameter> const& parameters)
{
StringBuilder builder;
builder.append(name);
@ -282,7 +282,7 @@ String constructor_for_message(String const& name, Vector<Parameter> const& para
return builder.to_string();
}
void do_message(SourceGenerator message_generator, String const& name, Vector<Parameter> const& parameters, String const& response_type = {})
void do_message(SourceGenerator message_generator, DeprecatedString const& name, Vector<Parameter> const& parameters, DeprecatedString const& response_type = {})
{
auto pascal_name = pascal_case(name);
message_generator.set("message.name", name);
@ -418,17 +418,17 @@ private:
void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& endpoint, Message const& message)
{
auto do_implement_proxy = [&](String const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
String return_type = "void";
auto do_implement_proxy = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
DeprecatedString return_type = "void";
if (is_synchronous) {
if (message.outputs.size() == 1)
return_type = message.outputs[0].type;
else if (!message.outputs.is_empty())
return_type = message_name(endpoint.name, message.name, true);
}
String inner_return_type = return_type;
DeprecatedString inner_return_type = return_type;
if (is_try)
return_type = String::formatted("IPC::IPCErrorOr<{}>", return_type);
return_type = DeprecatedString::formatted("IPC::IPCErrorOr<{}>", return_type);
message_generator.set("message.name", message.name);
message_generator.set("message.pascal_name", pascal_case(message.name));
@ -527,14 +527,14 @@ void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& end
void build_endpoint(SourceGenerator generator, Endpoint const& endpoint)
{
generator.set("endpoint.name", endpoint.name);
generator.set("endpoint.magic", String::number(endpoint.magic));
generator.set("endpoint.magic", DeprecatedString::number(endpoint.magic));
generator.appendln("\nnamespace Messages::@endpoint.name@ {");
HashMap<String, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
HashMap<DeprecatedString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
for (auto const& message : endpoint.messages) {
String response_name;
DeprecatedString response_name;
if (message.is_synchronous) {
response_name = message.response_name();
do_message(generator.fork(), response_name, message.outputs);
@ -614,7 +614,7 @@ public:
switch (message_id) {)~~~");
for (auto const& message : endpoint.messages) {
auto do_decode_message = [&](String const& name) {
auto do_decode_message = [&](DeprecatedString const& name) {
auto message_generator = generator.fork();
message_generator.set("message.name", name);
@ -661,13 +661,13 @@ public:
virtual ~@endpoint.name@Stub() override { }
virtual u32 magic() const override { return @endpoint.magic@; }
virtual String name() const override { return "@endpoint.name@"; }
virtual DeprecatedString name() const override { return "@endpoint.name@"; }
virtual OwnPtr<IPC::MessageBuffer> handle(const IPC::Message& message) override
{
switch (message.message_id()) {)~~~");
for (auto const& message : endpoint.messages) {
auto do_handle_message = [&](String const& name, Vector<Parameter> const& parameters, bool returns_something) {
auto do_handle_message = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool returns_something) {
auto message_generator = generator.fork();
StringBuilder argument_generator;
@ -721,8 +721,8 @@ public:
for (auto const& message : endpoint.messages) {
auto message_generator = generator.fork();
auto do_handle_message_decl = [&](String const& name, Vector<Parameter> const& parameters, bool is_response) {
String return_type = "void";
auto do_handle_message_decl = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_response) {
DeprecatedString return_type = "void";
if (message.is_synchronous && !message.outputs.is_empty() && !is_response)
return_type = message_name(endpoint.name, message.name, true);
message_generator.set("message.complex_return_type", return_type);
@ -731,7 +731,7 @@ public:
message_generator.appendln(R"~~~(
virtual @message.complex_return_type@ @handler_name@()~~~");
auto make_argument_type = [](String const& type) {
auto make_argument_type = [](DeprecatedString const& type) {
StringBuilder builder;
bool const_ref = !is_primitive_type(type);

View File

@ -23,11 +23,11 @@ struct ApprovalDate {
};
struct PnpIdData {
String manufacturer_name;
DeprecatedString manufacturer_name;
ApprovalDate approval_date;
};
static ErrorOr<String> decode_html_entities(StringView const& str)
static ErrorOr<DeprecatedString> decode_html_entities(StringView const& str)
{
static constexpr struct {
StringView entity_name;
@ -116,12 +116,12 @@ static ErrorOr<ApprovalDate> parse_approval_date(StringView const& str)
return ApprovalDate { .year = year.value(), .month = month.value(), .day = day.value() };
}
static ErrorOr<HashMap<String, PnpIdData>> parse_pnp_ids_database(Core::Stream::File& pnp_ids_file)
static ErrorOr<HashMap<DeprecatedString, PnpIdData>> parse_pnp_ids_database(Core::Stream::File& pnp_ids_file)
{
auto pnp_ids_file_bytes = TRY(pnp_ids_file.read_all());
StringView pnp_ids_file_contents(pnp_ids_file_bytes);
HashMap<String, PnpIdData> pnp_id_data;
HashMap<DeprecatedString, PnpIdData> pnp_id_data;
for (size_t row_content_offset = 0;;) {
static auto const row_start_tag = "<tr class=\""sv;
@ -142,7 +142,7 @@ static ErrorOr<HashMap<String, PnpIdData>> parse_pnp_ids_database(Core::Stream::
return Error::from_string_literal("Invalid row start tag");
auto row_string = pnp_ids_file_contents.substring_view(row_start_tag_end.value() + 1, row_end.value() - row_start_tag_end.value() - 1);
Vector<String, (size_t)PnpIdColumns::ColumnCount> columns;
Vector<DeprecatedString, (size_t)PnpIdColumns::ColumnCount> columns;
for (size_t column_row_offset = 0;;) {
static auto const column_start_tag = "<td>"sv;
auto column_start = row_string.find(column_start_tag, column_row_offset);
@ -181,12 +181,12 @@ static ErrorOr<HashMap<String, PnpIdData>> parse_pnp_ids_database(Core::Stream::
return pnp_id_data;
}
static ErrorOr<void> generate_header(Core::Stream::File& file, HashMap<String, PnpIdData> const& pnp_ids)
static ErrorOr<void> generate_header(Core::Stream::File& file, HashMap<DeprecatedString, PnpIdData> const& pnp_ids)
{
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("pnp_id_count", String::formatted("{}", pnp_ids.size()));
generator.set("pnp_id_count", DeprecatedString::formatted("{}", pnp_ids.size()));
generator.append(R"~~~(
#pragma once
@ -215,7 +215,7 @@ namespace PnpIDs {
return {};
}
static ErrorOr<void> generate_source(Core::Stream::File& file, HashMap<String, PnpIdData> const& pnp_ids)
static ErrorOr<void> generate_source(Core::Stream::File& file, HashMap<DeprecatedString, PnpIdData> const& pnp_ids)
{
StringBuilder builder;
SourceGenerator generator { builder };
@ -231,9 +231,9 @@ static constexpr PnpIDData s_pnp_ids[] = {
for (auto& pnp_id_data : pnp_ids) {
generator.set("manufacturer_id", pnp_id_data.key);
generator.set("manufacturer_name", pnp_id_data.value.manufacturer_name);
generator.set("approval_year", String::formatted("{}", pnp_id_data.value.approval_date.year));
generator.set("approval_month", String::formatted("{}", pnp_id_data.value.approval_date.month));
generator.set("approval_day", String::formatted("{}", pnp_id_data.value.approval_date.day));
generator.set("approval_year", DeprecatedString::formatted("{}", pnp_id_data.value.approval_date.year));
generator.set("approval_month", DeprecatedString::formatted("{}", pnp_id_data.value.approval_date.month));
generator.set("approval_day", DeprecatedString::formatted("{}", pnp_id_data.value.approval_date.day));
generator.append(R"~~~(
{ "@manufacturer_id@"sv, "@manufacturer_name@"sv, { @approval_year@, @approval_month@, @approval_day@ } },

View File

@ -7,6 +7,7 @@
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/AllOf.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Find.h>
#include <AK/Format.h>
#include <AK/GenericLexer.h>
@ -17,7 +18,6 @@
#include <AK/JsonValue.h>
#include <AK/LexicalPath.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Traits.h>
#include <AK/Utf8View.h>
@ -487,7 +487,7 @@ struct AK::Formatter<Locale::HourCycle> : Formatter<FormatString> {
};
struct LocaleData {
HashMap<String, size_t> calendars;
HashMap<DeprecatedString, size_t> calendars;
size_t time_zones { 0 };
size_t time_zone_formats { 0 };
@ -513,27 +513,27 @@ struct CLDR {
UniqueStorage<DayPeriodList> unique_day_period_lists;
UniqueStorage<HourCycleList> unique_hour_cycle_lists;
HashMap<String, LocaleData> locales;
HashMap<DeprecatedString, LocaleData> locales;
HashMap<String, size_t> hour_cycles;
Vector<String> hour_cycle_regions;
HashMap<DeprecatedString, size_t> hour_cycles;
Vector<DeprecatedString> hour_cycle_regions;
HashMap<String, u8> minimum_days;
Vector<String> minimum_days_regions;
HashMap<DeprecatedString, u8> minimum_days;
Vector<DeprecatedString> minimum_days_regions;
HashMap<String, Locale::Weekday> first_day;
Vector<String> first_day_regions;
HashMap<DeprecatedString, Locale::Weekday> first_day;
Vector<DeprecatedString> first_day_regions;
HashMap<String, Locale::Weekday> weekend_start;
Vector<String> weekend_start_regions;
HashMap<DeprecatedString, Locale::Weekday> weekend_start;
Vector<DeprecatedString> weekend_start_regions;
HashMap<String, Locale::Weekday> weekend_end;
Vector<String> weekend_end_regions;
HashMap<DeprecatedString, Locale::Weekday> weekend_end;
Vector<DeprecatedString> weekend_end_regions;
HashMap<String, Vector<TimeZone::TimeZone>> meta_zones;
Vector<String> time_zones { "UTC"sv };
HashMap<DeprecatedString, Vector<TimeZone::TimeZone>> meta_zones;
Vector<DeprecatedString> time_zones { "UTC"sv };
Vector<String> calendars;
Vector<DeprecatedString> calendars;
};
static Optional<Locale::DayPeriod> day_period_from_string(StringView day_period)
@ -563,7 +563,7 @@ static Optional<Locale::DayPeriod> day_period_from_string(StringView day_period)
return {};
}
static ErrorOr<void> parse_hour_cycles(String core_path, CLDR& cldr)
static ErrorOr<void> parse_hour_cycles(DeprecatedString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Data
LexicalPath time_data_path(move(core_path));
@ -607,7 +607,7 @@ static ErrorOr<void> parse_hour_cycles(String core_path, CLDR& cldr)
return {};
}
static ErrorOr<void> parse_week_data(String core_path, CLDR& cldr)
static ErrorOr<void> parse_week_data(DeprecatedString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Week_Data
LexicalPath week_data_path(move(core_path));
@ -672,7 +672,7 @@ static ErrorOr<void> parse_week_data(String core_path, CLDR& cldr)
return {};
}
static ErrorOr<void> parse_meta_zones(String core_path, CLDR& cldr)
static ErrorOr<void> parse_meta_zones(DeprecatedString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Metazones
LexicalPath meta_zone_path(move(core_path));
@ -714,7 +714,7 @@ static constexpr auto is_char(char ch)
// "{hour}:{minute} {ampm}" becomes "{hour}:{minute}" (remove the space before {ampm})
// "{ampm} {hour}" becomes "{hour}" (remove the space after {ampm})
// "{hour}:{minute} {ampm} {timeZoneName}" becomes "{hour}:{minute} {timeZoneName}" (remove one of the spaces around {ampm})
static String remove_period_from_pattern(String pattern)
static DeprecatedString remove_period_from_pattern(DeprecatedString pattern)
{
auto is_surrounding_space = [&](auto code_point_iterator) {
if (code_point_iterator.done())
@ -751,15 +751,15 @@ static String remove_period_from_pattern(String pattern)
after_removal = it;
if (is_surrounding_space(before_removal) && !is_opening(after_removal)) {
pattern = String::formatted("{}{}",
pattern = DeprecatedString::formatted("{}{}",
pattern.substring_view(0, *index - before_removal.underlying_code_point_length_in_bytes()),
pattern.substring_view(*index + remove.length()));
} else if (is_surrounding_space(after_removal) && !is_closing(before_removal)) {
pattern = String::formatted("{}{}",
pattern = DeprecatedString::formatted("{}{}",
pattern.substring_view(0, *index),
pattern.substring_view(*index + remove.length() + after_removal.underlying_code_point_length_in_bytes()));
} else {
pattern = String::formatted("{}{}",
pattern = DeprecatedString::formatted("{}{}",
pattern.substring_view(0, *index),
pattern.substring_view(*index + remove.length()));
}
@ -768,7 +768,7 @@ static String remove_period_from_pattern(String pattern)
return pattern;
}
static Optional<CalendarPattern> parse_date_time_pattern_raw(String pattern, String skeleton, CLDR& cldr)
static Optional<CalendarPattern> parse_date_time_pattern_raw(DeprecatedString pattern, DeprecatedString skeleton, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
using Locale::CalendarPatternStyle;
@ -987,7 +987,7 @@ static Optional<CalendarPattern> parse_date_time_pattern_raw(String pattern, Str
return format;
}
static Optional<size_t> parse_date_time_pattern(String pattern, String skeleton, CLDR& cldr)
static Optional<size_t> parse_date_time_pattern(DeprecatedString pattern, DeprecatedString skeleton, CLDR& cldr)
{
auto format = parse_date_time_pattern_raw(move(pattern), move(skeleton), cldr);
if (!format.has_value())
@ -1377,7 +1377,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
calendar.symbols = cldr.unique_calendar_symbols_lists.ensure(move(symbols_list));
}
static ErrorOr<void> parse_calendars(String locale_calendars_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_calendars(DeprecatedString locale_calendars_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath calendars_path(move(locale_calendars_path));
if (!calendars_path.basename().starts_with("ca-"sv))
@ -1394,7 +1394,7 @@ static ErrorOr<void> parse_calendars(String locale_calendars_path, CLDR& cldr, L
auto format = patterns_object.get(name);
auto skeleton = skeletons_object.get(name);
auto format_index = parse_date_time_pattern(format.as_string(), skeleton.as_string_or(String::empty()), cldr).value();
auto format_index = parse_date_time_pattern(format.as_string(), skeleton.as_string_or(DeprecatedString::empty()), cldr).value();
if (patterns)
patterns->append(cldr.unique_patterns.get(format_index));
@ -1468,7 +1468,7 @@ static ErrorOr<void> parse_calendars(String locale_calendars_path, CLDR& cldr, L
return {};
}
static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_names_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath time_zone_names_path(move(locale_time_zone_names_path));
time_zone_names_path = time_zone_names_path.append("timeZoneNames.json"sv);
@ -1577,7 +1577,7 @@ static ErrorOr<void> parse_time_zone_names(String locale_time_zone_names_path, C
return {};
}
static ErrorOr<void> parse_day_periods(String core_path, CLDR& cldr)
static ErrorOr<void> parse_day_periods(DeprecatedString core_path, CLDR& cldr)
{
// https://unicode.org/reports/tr35/tr35-dates.html#Day_Period_Rule_Sets
LexicalPath day_periods_path(move(core_path));
@ -1633,7 +1633,7 @@ static ErrorOr<void> parse_day_periods(String core_path, CLDR& cldr)
return {};
}
static ErrorOr<void> parse_all_locales(String core_path, String dates_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString dates_path, CLDR& cldr)
{
TRY(parse_hour_cycles(core_path, cldr));
TRY(parse_week_data(core_path, cldr));
@ -1641,7 +1641,7 @@ static ErrorOr<void> parse_all_locales(String core_path, String dates_path, CLDR
auto dates_iterator = TRY(path_to_dir_iterator(move(dates_path)));
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -1673,15 +1673,15 @@ static ErrorOr<void> parse_all_locales(String core_path, String dates_path, CLDR
return {};
}
static String format_identifier(StringView owner, String identifier)
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
{
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return String::formatted("{}_{}", owner[0], identifier);
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return String::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -1937,9 +1937,9 @@ struct DayPeriodData {
cldr.unique_day_period_lists.generate(generator, cldr.unique_day_periods.type_that_fits(), "s_day_period_lists"sv);
cldr.unique_hour_cycle_lists.generate(generator, cldr.unique_hour_cycle_lists.type_that_fits(), "s_hour_cycle_lists"sv);
auto append_calendars = [&](String name, auto const& calendars) {
auto append_calendars = [&](DeprecatedString name, auto const& calendars) {
generator.set("name", name);
generator.set("size", String::number(calendars.size()));
generator.set("size", DeprecatedString::number(calendars.size()));
generator.append(R"~~~(
static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
@ -1949,7 +1949,7 @@ static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
auto calendar = calendars.find(calendar_key)->value;
generator.append(first ? " "sv : ", "sv);
generator.append(String::number(calendar));
generator.append(DeprecatedString::number(calendar));
first = false;
}
@ -1959,7 +1959,7 @@ static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
auto append_mapping = [&](auto const& keys, auto const& map, auto type, auto name, auto mapping_getter) {
generator.set("type", type);
generator.set("name", name);
generator.set("size", String::number(keys.size()));
generator.set("size", DeprecatedString::number(keys.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {)~~~");
@ -1970,7 +1970,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
auto mapping = mapping_getter(value);
generator.append(first ? " "sv : ", "sv);
generator.append(String::number(mapping));
generator.append(DeprecatedString::number(mapping));
first = false;
}
@ -1992,7 +1992,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
generator.append("\n");
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) {
HashValueMap<String> hashes;
HashValueMap<DeprecatedString> hashes;
hashes.ensure_capacity(values.size());
for (auto const& value : values)

View File

@ -7,6 +7,7 @@
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/AllOf.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
@ -15,21 +16,20 @@
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DirIterator.h>
#include <LibCore/File.h>
#include <LibCore/Stream.h>
static String format_identifier(StringView owner, String identifier)
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
{
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return String::formatted("{}_{}", owner[0], identifier);
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return String::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -153,9 +153,9 @@ using KeywordList = Vector<size_t>;
using ListPatternList = Vector<size_t>;
struct LocaleData {
String language;
Optional<String> territory;
Optional<String> variant;
DeprecatedString language;
Optional<DeprecatedString> territory;
Optional<DeprecatedString> variant;
size_t display_patterns { 0 };
size_t languages { 0 };
size_t territories { 0 };
@ -195,15 +195,15 @@ struct CLDR {
UniqueStorage<ListPatternList> unique_list_pattern_lists;
UniqueStorage<TextLayout> unique_text_layouts;
HashMap<String, LocaleData> locales;
HashMap<DeprecatedString, LocaleData> locales;
Vector<Alias> locale_aliases;
Vector<String> languages;
Vector<String> territories;
Vector<String> scripts;
Vector<String> variants;
Vector<String> currencies;
Vector<String> date_fields;
Vector<DeprecatedString> languages;
Vector<DeprecatedString> territories;
Vector<DeprecatedString> scripts;
Vector<DeprecatedString> variants;
Vector<DeprecatedString> currencies;
Vector<DeprecatedString> date_fields;
Vector<Alias> date_field_aliases {
// ECMA-402 and the CLDR refer to some date fields with different names. Defining these aliases
// means we can remain agnostic about the naming differences elsewhere.
@ -212,17 +212,17 @@ struct CLDR {
{ "zone"sv, "timeZoneName"sv },
};
HashMap<String, Vector<String>> keywords;
HashMap<String, Vector<Alias>> keyword_aliases;
HashMap<String, String> keyword_names;
HashMap<DeprecatedString, Vector<DeprecatedString>> keywords;
HashMap<DeprecatedString, Vector<Alias>> keyword_aliases;
HashMap<DeprecatedString, DeprecatedString> keyword_names;
Vector<String> list_pattern_types;
Vector<String> character_orders;
HashMap<String, size_t> language_aliases;
HashMap<String, size_t> territory_aliases;
HashMap<String, size_t> script_aliases;
HashMap<String, size_t> variant_aliases;
HashMap<String, size_t> subdivision_aliases;
Vector<DeprecatedString> list_pattern_types;
Vector<DeprecatedString> character_orders;
HashMap<DeprecatedString, size_t> language_aliases;
HashMap<DeprecatedString, size_t> territory_aliases;
HashMap<DeprecatedString, size_t> script_aliases;
HashMap<DeprecatedString, size_t> variant_aliases;
HashMap<DeprecatedString, size_t> subdivision_aliases;
Vector<LanguageMapping> complex_mappings;
Vector<LanguageMapping> likely_subtags;
size_t max_variant_size { 0 };
@ -245,7 +245,7 @@ static ErrorOr<LanguageMapping> parse_language_mapping(CLDR& cldr, StringView ke
return LanguageMapping { move(parsed_key), move(parsed_alias) };
}
static ErrorOr<void> parse_core_aliases(String core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_core_aliases(DeprecatedString core_supplemental_path, CLDR& cldr)
{
LexicalPath core_aliases_path(move(core_supplemental_path));
core_aliases_path = core_aliases_path.append("aliases.json"sv);
@ -279,7 +279,7 @@ static ErrorOr<void> parse_core_aliases(String core_supplemental_path, CLDR& cld
return {};
}
static ErrorOr<void> parse_likely_subtags(String core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_likely_subtags(DeprecatedString core_supplemental_path, CLDR& cldr)
{
LexicalPath likely_subtags_path(move(core_supplemental_path));
likely_subtags_path = likely_subtags_path.append("likelySubtags.json"sv);
@ -298,7 +298,7 @@ static ErrorOr<void> parse_likely_subtags(String core_supplemental_path, CLDR& c
return {};
}
static ErrorOr<void> parse_identity(String locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_identity(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath languages_path(move(locale_path)); // Note: Every JSON file defines identity data, so we can use any of them.
languages_path = languages_path.append("languages.json"sv);
@ -335,7 +335,7 @@ static ErrorOr<void> parse_identity(String locale_path, CLDR& cldr, LocaleData&
return {};
}
static ErrorOr<void> parse_locale_display_patterns(String locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_display_patterns(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath locale_display_names_path(move(locale_path));
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
@ -356,7 +356,7 @@ static ErrorOr<void> parse_locale_display_patterns(String locale_path, CLDR& cld
return {};
}
static ErrorOr<void> preprocess_languages(String locale_path, CLDR& cldr)
static ErrorOr<void> preprocess_languages(DeprecatedString locale_path, CLDR& cldr)
{
LexicalPath languages_path(move(locale_path));
languages_path = languages_path.append("languages.json"sv);
@ -375,7 +375,7 @@ static ErrorOr<void> preprocess_languages(String locale_path, CLDR& cldr)
return {};
}
static ErrorOr<void> parse_unicode_extension_keywords(String bcp47_path, CLDR& cldr)
static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_path, CLDR& cldr)
{
constexpr auto desired_keywords = Array { "ca"sv, "co"sv, "hc"sv, "kf"sv, "kn"sv, "nu"sv };
auto keywords = TRY(read_json_file(bcp47_path));
@ -426,7 +426,7 @@ static ErrorOr<void> parse_unicode_extension_keywords(String bcp47_path, CLDR& c
return {};
}
static Optional<String> find_keyword_alias(StringView key, StringView calendar, CLDR& cldr)
static Optional<DeprecatedString> find_keyword_alias(StringView key, StringView calendar, CLDR& cldr)
{
auto it = cldr.keyword_aliases.find(key);
if (it == cldr.keyword_aliases.end())
@ -439,7 +439,7 @@ static Optional<String> find_keyword_alias(StringView key, StringView calendar,
return alias->name;
}
static ErrorOr<void> parse_locale_languages(String locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_languages(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath languages_path(move(locale_path));
languages_path = languages_path.append("languages.json"sv);
@ -465,7 +465,7 @@ static ErrorOr<void> parse_locale_languages(String locale_path, CLDR& cldr, Loca
return {};
}
static ErrorOr<void> parse_locale_territories(String locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_territories(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath territories_path(move(locale_path));
territories_path = territories_path.append("territories.json"sv);
@ -488,7 +488,7 @@ static ErrorOr<void> parse_locale_territories(String locale_path, CLDR& cldr, Lo
return {};
}
static ErrorOr<void> parse_locale_scripts(String locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_scripts(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath scripts_path(move(locale_path));
scripts_path = scripts_path.append("scripts.json"sv);
@ -511,7 +511,7 @@ static ErrorOr<void> parse_locale_scripts(String locale_path, CLDR& cldr, Locale
return {};
}
static ErrorOr<void> parse_locale_list_patterns(String misc_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_list_patterns(DeprecatedString misc_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath list_patterns_path(move(misc_path));
list_patterns_path = list_patterns_path.append("listPatterns.json"sv);
@ -562,7 +562,7 @@ static ErrorOr<void> parse_locale_list_patterns(String misc_path, CLDR& cldr, Lo
return {};
}
static ErrorOr<void> parse_locale_layout(String misc_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_layout(DeprecatedString misc_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath layout_path(move(misc_path));
layout_path = layout_path.append("layout.json"sv);
@ -594,7 +594,7 @@ static ErrorOr<void> parse_locale_layout(String misc_path, CLDR& cldr, LocaleDat
return {};
}
static ErrorOr<void> parse_locale_currencies(String numbers_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_currencies(DeprecatedString numbers_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath currencies_path(move(numbers_path));
currencies_path = currencies_path.append("currencies.json"sv);
@ -642,7 +642,7 @@ static ErrorOr<void> parse_locale_currencies(String numbers_path, CLDR& cldr, Lo
return {};
}
static ErrorOr<void> parse_locale_calendars(String locale_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_calendars(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath locale_display_names_path(move(locale_path));
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
@ -673,7 +673,7 @@ static ErrorOr<void> parse_locale_calendars(String locale_path, CLDR& cldr, Loca
return {};
}
static ErrorOr<void> parse_locale_date_fields(String dates_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_locale_date_fields(DeprecatedString dates_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath date_fields_path(move(dates_path));
date_fields_path = date_fields_path.append("dateFields.json"sv);
@ -714,8 +714,8 @@ static ErrorOr<void> parse_locale_date_fields(String dates_path, CLDR& cldr, Loc
return;
auto const& long_name = value.as_object().get("displayName"sv);
auto const& short_name = fields_object.as_object().get(String::formatted("{}-short", key)).as_object().get("displayName"sv);
auto const& narrow_name = fields_object.as_object().get(String::formatted("{}-narrow", key)).as_object().get("displayName"sv);
auto const& short_name = fields_object.as_object().get(DeprecatedString::formatted("{}-short", key)).as_object().get("displayName"sv);
auto const& narrow_name = fields_object.as_object().get(DeprecatedString::formatted("{}-narrow", key)).as_object().get("displayName"sv);
auto index = cldr.date_fields.find_first_index(key).value();
long_date_fields[index] = cldr.unique_strings.ensure(long_name.as_string());
@ -729,7 +729,7 @@ static ErrorOr<void> parse_locale_date_fields(String dates_path, CLDR& cldr, Loc
return {};
}
static ErrorOr<void> parse_number_system_keywords(String locale_numbers_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_numbers_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath numbers_path(move(locale_numbers_path));
numbers_path = numbers_path.append("numbers.json"sv);
@ -743,7 +743,7 @@ static ErrorOr<void> parse_number_system_keywords(String locale_numbers_path, CL
KeywordList keywords {};
auto append_numbering_system = [&](String system_name) {
auto append_numbering_system = [&](DeprecatedString system_name) {
if (auto system_alias = find_keyword_alias("nu"sv, system_name, cldr); system_alias.has_value())
system_name = system_alias.release_value();
@ -768,7 +768,7 @@ static ErrorOr<void> parse_number_system_keywords(String locale_numbers_path, CL
return {};
}
static ErrorOr<void> parse_calendar_keywords(String locale_dates_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_calendar_keywords(DeprecatedString locale_dates_path, CLDR& cldr, LocaleData& locale)
{
auto calendars_iterator = TRY(path_to_dir_iterator(locale_dates_path, {}));
KeywordList keywords {};
@ -833,7 +833,7 @@ static void fill_in_collation_keywords(CLDR& cldr, LocaleData& locale)
locale.collation_numeric_keywords = kn_index;
}
static ErrorOr<void> parse_default_content_locales(String core_path, CLDR& cldr)
static ErrorOr<void> parse_default_content_locales(DeprecatedString core_path, CLDR& cldr)
{
LexicalPath default_content_path(move(core_path));
default_content_path = default_content_path.append("defaultContent.json"sv);
@ -882,7 +882,7 @@ static ErrorOr<void> define_aliases_without_scripts(CLDR& cldr)
if ((parsed_locale.language == 0) || (parsed_locale.script == 0) || (parsed_locale.region == 0))
return {};
auto locale_without_script = String::formatted("{}-{}",
auto locale_without_script = DeprecatedString::formatted("{}-{}",
cldr.unique_strings.get(parsed_locale.language),
cldr.unique_strings.get(parsed_locale.region));
@ -907,7 +907,7 @@ static ErrorOr<void> define_aliases_without_scripts(CLDR& cldr)
return {};
}
static ErrorOr<void> parse_all_locales(String bcp47_path, String core_path, String locale_names_path, String misc_path, String numbers_path, String dates_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedString core_path, DeprecatedString locale_names_path, DeprecatedString misc_path, DeprecatedString numbers_path, DeprecatedString dates_path, CLDR& cldr)
{
auto bcp47_iterator = TRY(path_to_dir_iterator(move(bcp47_path), "bcp47"sv));
auto identity_iterator = TRY(path_to_dir_iterator(locale_names_path));
@ -924,7 +924,7 @@ static ErrorOr<void> parse_all_locales(String bcp47_path, String core_path, Stri
TRY(parse_core_aliases(core_supplemental_path.string(), cldr));
TRY(parse_likely_subtags(core_supplemental_path.string(), cldr));
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -1034,7 +1034,7 @@ namespace Locale {
for (auto& keyword : cldr.keywords) {
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
auto enum_name = String::formatted("Keyword{}", format_identifier({}, keyword_name));
auto enum_name = DeprecatedString::formatted("Keyword{}", format_identifier({}, keyword_name));
if (auto aliases = cldr.keyword_aliases.find(keyword.key); aliases != cldr.keyword_aliases.end())
generate_enum(generator, format_identifier, enum_name, {}, keyword.value, aliases->value);
@ -1057,9 +1057,9 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("string_index_type"sv, string_index_type);
generator.set("locales_size"sv, String::number(cldr.locales.size()));
generator.set("territories_size", String::number(cldr.territories.size()));
generator.set("variants_size", String::number(cldr.max_variant_size));
generator.set("locales_size"sv, DeprecatedString::number(cldr.locales.size()));
generator.set("territories_size", DeprecatedString::number(cldr.territories.size()));
generator.set("variants_size", DeprecatedString::number(cldr.max_variant_size));
generator.append(R"~~~(
#include <AK/Array.h>
@ -1162,7 +1162,7 @@ Span<StringView const> get_available_keyword_values(StringView key)
cldr.unique_text_layouts.generate(generator, "TextLayout"sv, "s_text_layouts"sv, 30);
auto append_index = [&](auto index) {
generator.append(String::formatted(", {}", index));
generator.append(DeprecatedString::formatted(", {}", index));
};
auto append_list_and_size = [&](auto const& list) {
@ -1175,16 +1175,16 @@ Span<StringView const> get_available_keyword_values(StringView key)
generator.append(", {");
for (auto const& item : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(String::number(item));
generator.append(DeprecatedString::number(item));
first = false;
}
generator.append(String::formatted(" }}, {}", list.size()));
generator.append(DeprecatedString::formatted(" }}, {}", list.size()));
};
auto append_mapping = [&](auto const& keys, auto const& map, auto type, auto name, auto mapping_getter) {
generator.set("type", type);
generator.set("name", name);
generator.set("size", String::number(keys.size()));
generator.set("size", DeprecatedString::number(keys.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {)~~~");
@ -1195,7 +1195,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
auto mapping = mapping_getter(value);
generator.append(first ? " "sv : ", "sv);
generator.append(String::number(mapping));
generator.append(DeprecatedString::number(mapping));
first = false;
}
@ -1243,7 +1243,7 @@ struct CanonicalLanguageID {
return language_id;
}
bool matches_variants(Vector<String> const& other_variants) const {
bool matches_variants(Vector<DeprecatedString> const& other_variants) const {
if (variants_size == 0)
return true;
if (other_variants.size() != variants_size)
@ -1272,7 +1272,7 @@ struct LanguageMapping {
)~~~");
auto append_complex_mapping = [&](StringView name, auto& mappings) {
generator.set("size", String::number(mappings.size()));
generator.set("size", DeprecatedString::number(mappings.size()));
generator.set("name"sv, name);
generator.append(R"~~~(
@ -1292,14 +1292,14 @@ static constexpr Array<LanguageMapping, @size@> s_@name@ { {
});
for (auto const& mapping : mappings) {
generator.set("language"sv, String::number(mapping.key.language));
generator.set("language"sv, DeprecatedString::number(mapping.key.language));
generator.append(" { { @language@");
append_index(mapping.key.script);
append_index(mapping.key.region);
append_list_and_size(mapping.key.variants);
generator.set("language"sv, String::number(mapping.alias.language));
generator.set("language"sv, DeprecatedString::number(mapping.alias.language));
generator.append(" }, { @language@");
append_index(mapping.alias.script);
@ -1439,7 +1439,7 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
};
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) {
HashValueMap<String> hashes;
HashValueMap<DeprecatedString> hashes;
hashes.ensure_capacity(values.size());
for (auto const& value : values)
@ -1493,8 +1493,8 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
for (auto const& keyword : cldr.keywords) {
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
auto enum_name = String::formatted("Keyword{}", format_identifier({}, keyword_name));
auto enum_snake = String::formatted("keyword_{}", keyword.key);
auto enum_name = DeprecatedString::formatted("Keyword{}", format_identifier({}, keyword_name));
auto enum_snake = DeprecatedString::formatted("keyword_{}", keyword.key);
if (auto aliases = cldr.keyword_aliases.find(keyword.key); aliases != cldr.keyword_aliases.end())
append_from_string(enum_name, enum_snake, keyword.value, aliases->value);
@ -1728,7 +1728,7 @@ Optional<LanguageID> add_likely_subtags(LanguageID const& language_id)
return maximized;
}
Optional<String> resolve_most_likely_territory(LanguageID const& language_id)
Optional<DeprecatedString> resolve_most_likely_territory(LanguageID const& language_id)
{
if (auto const* likely_subtag = resolve_likely_subtag(language_id); likely_subtag != nullptr)
return decode_string(likely_subtag->alias.region);

View File

@ -8,6 +8,7 @@
#include <AK/AllOf.h>
#include <AK/Array.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Find.h>
#include <AK/Format.h>
#include <AK/HashFunctions.h>
@ -18,7 +19,6 @@
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Traits.h>
#include <AK/Utf8View.h>
@ -220,7 +220,7 @@ struct AK::Traits<Unit> : public GenericTraits<Unit> {
struct LocaleData {
Vector<size_t> number_systems;
HashMap<String, size_t> units {};
HashMap<DeprecatedString, size_t> units {};
u8 minimum_grouping_digits { 0 };
};
@ -232,14 +232,14 @@ struct CLDR {
UniqueStorage<NumberSystem> unique_systems;
UniqueStorage<Unit> unique_units;
HashMap<String, Array<u32, 10>> number_system_digits;
Vector<String> number_systems;
HashMap<DeprecatedString, Array<u32, 10>> number_system_digits;
Vector<DeprecatedString> number_systems;
HashMap<String, LocaleData> locales;
HashMap<DeprecatedString, LocaleData> locales;
size_t max_identifier_count { 0 };
};
static ErrorOr<void> parse_number_system_digits(String core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_number_system_digits(DeprecatedString core_supplemental_path, CLDR& cldr)
{
LexicalPath number_systems_path(move(core_supplemental_path));
number_systems_path = number_systems_path.append("numberingSystems.json"sv);
@ -271,7 +271,7 @@ static ErrorOr<void> parse_number_system_digits(String core_supplemental_path, C
return {};
}
static String parse_identifiers(String pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
static DeprecatedString parse_identifiers(DeprecatedString pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
{
static constexpr Utf8View whitespace { "\u0020\u00a0\u200f"sv };
@ -317,7 +317,7 @@ static String parse_identifiers(String pattern, StringView replacement, CLDR& cl
cldr.max_identifier_count = max(cldr.max_identifier_count, format.identifier_indices.size());
}
pattern = String::formatted("{}{{{}:{}}}{}",
pattern = DeprecatedString::formatted("{}{{{}:{}}}{}",
*start_index > 0 ? pattern.substring_view(0, *start_index) : ""sv,
replacement,
replacement_index,
@ -325,13 +325,13 @@ static String parse_identifiers(String pattern, StringView replacement, CLDR& cl
}
}
static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
{
// https://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
// https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
VERIFY((patterns.size() == 1) || (patterns.size() == 2));
auto replace_patterns = [&](String pattern) {
auto replace_patterns = [&](DeprecatedString pattern) {
static HashMap<StringView, StringView> replacements = {
{ "{0}"sv, "{number}"sv },
{ "{1}"sv, "{currency}"sv },
@ -345,7 +345,7 @@ static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberForm
for (auto const& replacement : replacements)
pattern = pattern.replace(replacement.key, replacement.value, ReplaceMode::All);
if (auto start_number_index = pattern.find_any_of("#0"sv, String::SearchDirection::Forward); start_number_index.has_value()) {
if (auto start_number_index = pattern.find_any_of("#0"sv, DeprecatedString::SearchDirection::Forward); start_number_index.has_value()) {
auto end_number_index = *start_number_index + 1;
for (; end_number_index < pattern.length(); ++end_number_index) {
@ -372,7 +372,7 @@ static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberForm
}
}
pattern = String::formatted("{}{{number}}{}",
pattern = DeprecatedString::formatted("{}{{number}}{}",
*start_number_index > 0 ? pattern.substring_view(0, *start_number_index) : ""sv,
pattern.substring_view(end_number_index));
@ -389,19 +389,19 @@ static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberForm
};
auto zero_format = replace_patterns(move(patterns[0]));
format.positive_format_index = cldr.unique_strings.ensure(String::formatted("{{plusSign}}{}", zero_format));
format.positive_format_index = cldr.unique_strings.ensure(DeprecatedString::formatted("{{plusSign}}{}", zero_format));
if (patterns.size() == 2) {
auto negative_format = replace_patterns(move(patterns[1]));
format.negative_format_index = cldr.unique_strings.ensure(move(negative_format));
} else {
format.negative_format_index = cldr.unique_strings.ensure(String::formatted("{{minusSign}}{}", zero_format));
format.negative_format_index = cldr.unique_strings.ensure(DeprecatedString::formatted("{{minusSign}}{}", zero_format));
}
format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
}
static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberFormatType type, size_t& format_index, NumberSystem* number_system_for_groupings = nullptr)
static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr, NumberFormatType type, size_t& format_index, NumberSystem* number_system_for_groupings = nullptr)
{
NumberFormat format {};
parse_number_pattern(move(patterns), cldr, type, format, number_system_for_groupings);
@ -409,7 +409,7 @@ static void parse_number_pattern(Vector<String> patterns, CLDR& cldr, NumberForm
format_index = cldr.unique_formats.ensure(move(format));
}
static ErrorOr<void> parse_number_systems(String locale_numbers_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath numbers_path(move(locale_numbers_path));
numbers_path = numbers_path.append("numbers.json"sv);
@ -522,7 +522,7 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, CLDR& cldr
// The range separator does not appear in the symbols list, we have to extract it from
// the range pattern.
auto misc_patterns_key = String::formatted("{}{}", misc_patterns_prefix, system);
auto misc_patterns_key = DeprecatedString::formatted("{}{}", misc_patterns_prefix, system);
auto misc_patterns = locale_numbers_object.as_object().get(misc_patterns_key);
auto range_separator = misc_patterns.as_object().get("range"sv).as_string();
@ -594,7 +594,7 @@ static ErrorOr<void> parse_number_systems(String locale_numbers_path, CLDR& cldr
return {};
}
static ErrorOr<void> parse_units(String locale_units_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath units_path(move(locale_units_path));
units_path = units_path.append("units.json"sv);
@ -607,7 +607,7 @@ static ErrorOr<void> parse_units(String locale_units_path, CLDR& cldr, LocaleDat
auto const& short_object = locale_units_object.as_object().get("short"sv);
auto const& narrow_object = locale_units_object.as_object().get("narrow"sv);
HashMap<String, Unit> units;
HashMap<DeprecatedString, Unit> units;
auto ensure_unit = [&](auto const& unit) -> Unit& {
return units.ensure(unit, [&]() {
@ -697,7 +697,7 @@ static ErrorOr<void> parse_units(String locale_units_path, CLDR& cldr, LocaleDat
return {};
}
static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, String units_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString numbers_path, DeprecatedString units_path, CLDR& cldr)
{
auto numbers_iterator = TRY(path_to_dir_iterator(move(numbers_path)));
auto units_iterator = TRY(path_to_dir_iterator(move(units_path)));
@ -708,7 +708,7 @@ static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, St
TRY(parse_number_system_digits(core_supplemental_path.string(), cldr));
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -740,7 +740,7 @@ static ErrorOr<void> parse_all_locales(String core_path, String numbers_path, St
return {};
}
static String format_identifier(StringView, String identifier)
static DeprecatedString format_identifier(StringView, DeprecatedString identifier)
{
return identifier.to_titlecase();
}
@ -776,7 +776,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::Stream::Buffer
generator.set("number_format_index_type"sv, cldr.unique_formats.type_that_fits());
generator.set("number_format_list_index_type"sv, cldr.unique_format_lists.type_that_fits());
generator.set("numeric_symbol_list_index_type"sv, cldr.unique_symbols.type_that_fits());
generator.set("identifier_count", String::number(cldr.max_identifier_count));
generator.set("identifier_count", DeprecatedString::number(cldr.max_identifier_count));
generator.append(R"~~~(
#include <AK/Array.h>
@ -860,22 +860,22 @@ struct Unit {
auto locales = cldr.locales.keys();
quick_sort(locales);
generator.set("size", String::number(locales.size()));
generator.set("size", DeprecatedString::number(locales.size()));
generator.append(R"~~~(
static constexpr Array<u8, @size@> s_minimum_grouping_digits { { )~~~");
bool first = true;
for (auto const& locale : locales) {
generator.append(first ? " "sv : ", "sv);
generator.append(String::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
generator.append(DeprecatedString::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
first = false;
}
generator.append(" } };\n");
auto append_map = [&](String name, auto type, auto const& map) {
auto append_map = [&](DeprecatedString name, auto type, auto const& map) {
generator.set("name", name);
generator.set("type", type);
generator.set("size", String::number(map.size()));
generator.set("size", DeprecatedString::number(map.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {)~~~");
@ -884,9 +884,9 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
for (auto const& item : map) {
generator.append(first ? " "sv : ", "sv);
if constexpr (requires { item.value; })
generator.append(String::number(item.value));
generator.append(DeprecatedString::number(item.value));
else
generator.append(String::number(item));
generator.append(DeprecatedString::number(item));
first = false;
}

View File

@ -5,13 +5,13 @@
*/
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <AK/JsonValue.h>
#include <AK/LexicalPath.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Variant.h>
#include <LibCore/ArgsParser.h>
@ -19,14 +19,14 @@
#include <LibCore/Stream.h>
#include <LibLocale/PluralRules.h>
static String format_identifier(StringView owner, String identifier)
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
{
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return String::formatted("{}_{}", owner[0], identifier);
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return String::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -39,20 +39,20 @@ struct Relation {
Inequality,
};
String const& modulus_variable_name() const
DeprecatedString const& modulus_variable_name() const
{
VERIFY(modulus.has_value());
if (!cached_modulus_variable_name.has_value())
cached_modulus_variable_name = String::formatted("mod_{}_{}", symbol, *modulus);
cached_modulus_variable_name = DeprecatedString::formatted("mod_{}_{}", symbol, *modulus);
return *cached_modulus_variable_name;
}
String const& exponential_variable_name() const
DeprecatedString const& exponential_variable_name() const
{
if (!cached_exponential_variable_name.has_value())
cached_exponential_variable_name = String::formatted("exp_{}", symbol);
cached_exponential_variable_name = DeprecatedString::formatted("exp_{}", symbol);
return *cached_exponential_variable_name;
}
@ -65,25 +65,25 @@ struct Relation {
else if (symbol == 'e' || symbol == 'c')
generator.append(exponential_variable_name());
else
generator.append(String::formatted("ops.{}", Locale::PluralOperands::symbol_to_variable_name(symbol)));
generator.append(DeprecatedString::formatted("ops.{}", Locale::PluralOperands::symbol_to_variable_name(symbol)));
};
auto append_value = [&](u32 value) {
append_variable_name();
generator.append(" == "sv);
generator.append(String::number(value));
generator.append(DeprecatedString::number(value));
};
auto append_range = [&](auto const& range) {
// This check avoids generating "0 <= unsigned_value", which is always true.
if (range[0] != 0 || Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
generator.append(String::formatted("{} <= ", range[0]));
generator.append(DeprecatedString::formatted("{} <= ", range[0]));
append_variable_name();
generator.append(" && "sv);
}
append_variable_name();
generator.append(String::formatted(" <= {}", range[1]));
generator.append(DeprecatedString::formatted(" <= {}", range[1]));
};
if (type == Type::Inequality)
@ -106,7 +106,7 @@ struct Relation {
generator.append(")"sv);
}
void generate_precomputed_variables(SourceGenerator& generator, HashTable<String>& generated_variables) const
void generate_precomputed_variables(SourceGenerator& generator, HashTable<DeprecatedString>& generated_variables) const
{
// FIXME: How do we handle the exponential symbols? They seem unused by ECMA-402.
if (symbol == 'e' || symbol == 'c') {
@ -128,7 +128,7 @@ struct Relation {
generated_variables.set(variable);
generator.set("variable"sv, move(variable));
generator.set("operand"sv, Locale::PluralOperands::symbol_to_variable_name(symbol));
generator.set("modulus"sv, String::number(*modulus));
generator.set("modulus"sv, DeprecatedString::number(*modulus));
if (Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
generator.append(R"~~~(
@ -145,8 +145,8 @@ struct Relation {
Vector<Comparator> comparators;
private:
mutable Optional<String> cached_modulus_variable_name;
mutable Optional<String> cached_exponential_variable_name;
mutable Optional<DeprecatedString> cached_modulus_variable_name;
mutable Optional<DeprecatedString> cached_exponential_variable_name;
};
struct Condition {
@ -171,7 +171,7 @@ struct Condition {
}
}
void generate_precomputed_variables(SourceGenerator& generator, HashTable<String>& generated_variables) const
void generate_precomputed_variables(SourceGenerator& generator, HashTable<DeprecatedString>& generated_variables) const
{
for (auto const& conjunctions : relations) {
for (auto const& relation : conjunctions)
@ -183,18 +183,18 @@ struct Condition {
};
struct Range {
String start;
String end;
String category;
DeprecatedString start;
DeprecatedString end;
DeprecatedString category;
};
using Conditions = HashMap<String, Condition>;
using Conditions = HashMap<DeprecatedString, Condition>;
using Ranges = Vector<Range>;
struct LocaleData {
static String generated_method_name(StringView form, StringView locale)
static DeprecatedString generated_method_name(StringView form, StringView locale)
{
return String::formatted("{}_plurality_{}", form, format_identifier({}, locale));
return DeprecatedString::formatted("{}_plurality_{}", form, format_identifier({}, locale));
}
Conditions& rules_for_form(StringView form)
@ -214,7 +214,7 @@ struct LocaleData {
struct CLDR {
UniqueStringStorage unique_strings;
HashMap<String, LocaleData> locales;
HashMap<DeprecatedString, LocaleData> locales;
};
static Relation parse_relation(StringView relation)
@ -322,7 +322,7 @@ static void parse_condition(StringView category, StringView rule, Conditions& ru
});
}
static ErrorOr<void> parse_plural_rules(String core_supplemental_path, StringView file_name, CLDR& cldr)
static ErrorOr<void> parse_plural_rules(DeprecatedString core_supplemental_path, StringView file_name, CLDR& cldr)
{
static constexpr auto form_prefix = "plurals-type-"sv;
static constexpr auto rule_prefix = "pluralRule-count-"sv;
@ -357,7 +357,7 @@ static ErrorOr<void> parse_plural_rules(String core_supplemental_path, StringVie
}
// https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges
static ErrorOr<void> parse_plural_ranges(String core_supplemental_path, CLDR& cldr)
static ErrorOr<void> parse_plural_ranges(DeprecatedString core_supplemental_path, CLDR& cldr)
{
static constexpr auto start_segment = "-start-"sv;
static constexpr auto end_segment = "-end-"sv;
@ -393,7 +393,7 @@ static ErrorOr<void> parse_plural_ranges(String core_supplemental_path, CLDR& cl
return {};
}
static ErrorOr<void> parse_all_locales(String core_path, String locale_names_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString locale_names_path, CLDR& cldr)
{
auto identity_iterator = TRY(path_to_dir_iterator(move(locale_names_path)));
@ -401,7 +401,7 @@ static ErrorOr<void> parse_all_locales(String core_path, String locale_names_pat
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
VERIFY(Core::File::is_directory(core_supplemental_path.string()));
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -486,7 +486,7 @@ static PluralCategory default_range(PluralCategory, PluralCategory end)
return;
generator.set("method"sv, LocaleData::generated_method_name(form, locale));
HashTable<String> generated_variables;
HashTable<DeprecatedString> generated_variables;
generator.append(R"~~~(
static PluralCategory @method@([[maybe_unused]] PluralOperands ops)
@ -541,7 +541,7 @@ static PluralCategory @method@(PluralCategory start, PluralCategory end)
generator.set("type"sv, type);
generator.set("form"sv, form);
generator.set("default"sv, default_);
generator.set("size"sv, String::number(locales.size()));
generator.set("size"sv, DeprecatedString::number(locales.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
@ -566,7 +566,7 @@ static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
auto append_categories = [&](auto const& name, auto const& rules) {
generator.set("name", name);
generator.set("size", String::number(rules.size() + 1));
generator.set("size", DeprecatedString::number(rules.size() + 1));
generator.append(R"~~~(
static constexpr Array<PluralCategory, @size@> @name@ { { PluralCategory::Other)~~~");

View File

@ -5,6 +5,7 @@
*/
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
@ -12,7 +13,6 @@
#include <AK/JsonValue.h>
#include <AK/LexicalPath.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DirIterator.h>
@ -40,9 +40,9 @@ struct RelativeTimeFormat {
&& (pattern == other.pattern);
}
String time_unit;
String style;
String plurality;
DeprecatedString time_unit;
DeprecatedString style;
DeprecatedString plurality;
size_t tense_or_number { 0 };
size_t pattern { 0 };
};
@ -74,10 +74,10 @@ struct CLDR {
UniqueStringStorage unique_strings;
UniqueStorage<RelativeTimeFormat> unique_formats;
HashMap<String, LocaleData> locales;
HashMap<DeprecatedString, LocaleData> locales;
};
static ErrorOr<void> parse_date_fields(String locale_dates_path, CLDR& cldr, LocaleData& locale)
static ErrorOr<void> parse_date_fields(DeprecatedString locale_dates_path, CLDR& cldr, LocaleData& locale)
{
LexicalPath date_fields_path(move(locale_dates_path));
date_fields_path = date_fields_path.append("dateFields.json"sv);
@ -136,11 +136,11 @@ static ErrorOr<void> parse_date_fields(String locale_dates_path, CLDR& cldr, Loc
return {};
}
static ErrorOr<void> parse_all_locales(String dates_path, CLDR& cldr)
static ErrorOr<void> parse_all_locales(DeprecatedString dates_path, CLDR& cldr)
{
auto dates_iterator = TRY(path_to_dir_iterator(move(dates_path)));
auto remove_variants_from_path = [&](String path) -> ErrorOr<String> {
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
StringBuilder builder;
@ -227,9 +227,9 @@ struct RelativeTimeFormatImpl {
cldr.unique_formats.generate(generator, "RelativeTimeFormatImpl"sv, "s_relative_time_formats"sv, 10);
auto append_list = [&](String name, auto const& list) {
auto append_list = [&](DeprecatedString name, auto const& list) {
generator.set("name", name);
generator.set("size", String::number(list.size()));
generator.set("size", DeprecatedString::number(list.size()));
generator.append(R"~~~(
static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~");
@ -237,7 +237,7 @@ static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~
bool first = true;
for (auto index : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(String::number(index));
generator.append(DeprecatedString::number(index));
first = false;
}

View File

@ -6,10 +6,10 @@
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
#include <AK/DateConstants.h>
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/HashMap.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
@ -36,7 +36,7 @@ struct TimeZoneOffset {
i64 offset { 0 };
Optional<DateTime> until;
Optional<String> dst_rule;
Optional<DeprecatedString> dst_rule;
Optional<i32> dst_rule_index;
i64 dst_offset { 0 };
@ -56,17 +56,17 @@ struct DaylightSavingsOffset {
struct TimeZoneData {
UniqueStringStorage unique_strings;
HashMap<String, Vector<TimeZoneOffset>> time_zones;
Vector<String> time_zone_names;
HashMap<DeprecatedString, Vector<TimeZoneOffset>> time_zones;
Vector<DeprecatedString> time_zone_names;
Vector<Alias> time_zone_aliases;
HashMap<String, Vector<DaylightSavingsOffset>> dst_offsets;
Vector<String> dst_offset_names;
HashMap<DeprecatedString, Vector<DaylightSavingsOffset>> dst_offsets;
Vector<DeprecatedString> dst_offset_names;
HashMap<String, TimeZone::Location> time_zone_coordinates;
HashMap<DeprecatedString, TimeZone::Location> time_zone_coordinates;
HashMap<String, Vector<size_t>> time_zone_regions;
Vector<String> time_zone_region_names;
HashMap<DeprecatedString, Vector<size_t>> time_zone_regions;
Vector<DeprecatedString> time_zone_region_names;
};
}
@ -110,10 +110,10 @@ struct AK::Formatter<DaylightSavingsOffset> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, DaylightSavingsOffset const& dst_offset)
{
auto format_time = [&](auto year) {
return String::formatted("AK::Time::from_timestamp({}, 1, 1, 0, 0, 0, 0)", year);
return DeprecatedString::formatted("AK::Time::from_timestamp({}, 1, 1, 0, 0, 0, 0)", year);
};
static String max_year_as_time("max_year_as_time"sv);
static DeprecatedString max_year_as_time("max_year_as_time"sv);
return Formatter<FormatString>::format(builder,
"{{ {}, {}, {}, {}, {} }}"sv,
@ -422,7 +422,7 @@ static void set_dst_rule_indices(TimeZoneData& time_zone_data)
}
}
static String format_identifier(StringView owner, String identifier)
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
{
constexpr auto gmt_time_zones = Array { "Etc/GMT"sv, "GMT"sv };
@ -431,9 +431,9 @@ static String format_identifier(StringView owner, String identifier)
auto offset = identifier.substring_view(gmt_time_zone.length());
if (offset.starts_with('+'))
identifier = String::formatted("{}_Ahead_{}", gmt_time_zone, offset.substring_view(1));
identifier = DeprecatedString::formatted("{}_Ahead_{}", gmt_time_zone, offset.substring_view(1));
else if (offset.starts_with('-'))
identifier = String::formatted("{}_Behind_{}", gmt_time_zone, offset.substring_view(1));
identifier = DeprecatedString::formatted("{}_Behind_{}", gmt_time_zone, offset.substring_view(1));
}
}
@ -441,9 +441,9 @@ static String format_identifier(StringView owner, String identifier)
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
if (all_of(identifier, is_ascii_digit))
return String::formatted("{}_{}", owner[0], identifier);
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
if (is_ascii_lower_alpha(identifier[0]))
return String::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
return identifier;
}
@ -551,14 +551,14 @@ struct DaylightSavingsOffset {
auto append_offsets = [&](auto const& name, auto type, auto const& offsets) {
generator.set("name", name);
generator.set("type", type);
generator.set("size", String::number(offsets.size()));
generator.set("size", DeprecatedString::number(offsets.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {
)~~~");
for (auto const& offset : offsets)
generator.append(String::formatted(" {},\n", offset));
generator.append(DeprecatedString::formatted(" {},\n", offset));
generator.append("} };\n");
};
@ -580,7 +580,7 @@ static constexpr Array<@type@, @size@> @name@ { {
auto const& time_zones = time_zone_data.time_zone_regions.find(value)->value;
generator.set("name", name);
generator.set("size", String::number(time_zones.size()));
generator.set("size", DeprecatedString::number(time_zones.size()));
generator.append(R"~~~(
static constexpr Array<@string_index_type@, @size@> @name@ { {)~~~");
@ -588,14 +588,14 @@ static constexpr Array<@string_index_type@, @size@> @name@ { {)~~~");
bool first = true;
for (auto const& time_zone : time_zones) {
generator.append(first ? " "sv : ", "sv);
generator.append(String::number(time_zone));
generator.append(DeprecatedString::number(time_zone));
first = false;
}
generator.append(" } };");
});
generator.set("size", String::number(time_zone_data.time_zone_names.size()));
generator.set("size", DeprecatedString::number(time_zone_data.time_zone_names.size()));
generator.append(R"~~~(
static constexpr Array<Location, @size@> s_time_zone_locations { {
)~~~");
@ -603,12 +603,12 @@ static constexpr Array<Location, @size@> s_time_zone_locations { {
for (auto const& time_zone : time_zone_data.time_zone_names) {
auto location = time_zone_data.time_zone_coordinates.get(time_zone).value_or({});
generator.append(String::formatted(" {},\n", location));
generator.append(DeprecatedString::formatted(" {},\n", location));
}
generator.append("} };\n");
auto append_string_conversions = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) {
HashValueMap<String> hashes;
HashValueMap<DeprecatedString> hashes;
hashes.ensure_capacity(values.size());
auto hash = [](auto const& value) {
@ -731,10 +731,10 @@ Optional<Array<NamedOffset, 2>> get_named_time_zone_offsets(TimeZone time_zone,
auto const& time_zone_offset = find_time_zone_offset(time_zone, time);
Array<NamedOffset, 2> named_offsets;
auto format_name = [](auto format, auto offset) -> String {
auto format_name = [](auto format, auto offset) -> DeprecatedString {
if (offset == 0)
return decode_string(format).replace("{}"sv, ""sv, ReplaceMode::FirstOnly);
return String::formatted(decode_string(format), decode_string(offset));
return DeprecatedString::formatted(decode_string(format), decode_string(offset));
};
auto set_named_offset = [&](auto& named_offset, auto dst_offset, auto in_dst, auto format, auto offset) {

View File

@ -6,8 +6,8 @@
#include "GeneratorUtil.h"
#include <AK/AnyOf.h>
#include <AK/DeprecatedString.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringUtils.h>
#include <AK/Types.h>
#include <LibCore/ArgsParser.h>
@ -17,13 +17,13 @@
struct Emoji {
size_t name { 0 };
Optional<String> image_path;
Optional<DeprecatedString> image_path;
Unicode::EmojiGroup group;
String subgroup;
DeprecatedString subgroup;
u32 display_order { 0 };
Vector<u32> code_points;
String encoded_code_points;
String status;
DeprecatedString encoded_code_points;
DeprecatedString status;
size_t code_point_array_index { 0 };
};
@ -44,7 +44,7 @@ static void set_image_path_for_emoji(StringView emoji_resource_path, Emoji& emoj
builder.appendff("U+{:X}", code_point);
}
auto path = String::formatted("{}/{}.png", emoji_resource_path, builder.build());
auto path = DeprecatedString::formatted("{}/{}.png", emoji_resource_path, builder.build());
if (Core::Stream::File::exists(path))
emoji.image_path = move(path);
}
@ -57,7 +57,7 @@ static ErrorOr<void> parse_emoji_test_data(Core::Stream::BufferedFile& file, Emo
Array<u8, 1024> buffer;
Unicode::EmojiGroup group;
String subgroup;
DeprecatedString subgroup;
u32 display_order { 0 };
while (TRY(file.can_read_line())) {
@ -178,7 +178,7 @@ static ErrorOr<void> generate_emoji_data_implementation(Core::Stream::BufferedFi
SourceGenerator generator { builder };
generator.set("string_index_type"sv, emoji_data.unique_strings.type_that_fits());
generator.set("emojis_size"sv, String::number(emoji_data.emojis.size()));
generator.set("emojis_size"sv, DeprecatedString::number(emoji_data.emojis.size()));
generator.append(R"~~~(
#include <AK/Array.h>
@ -198,7 +198,7 @@ namespace Unicode {
for (auto const& emoji : emoji_data.emojis) {
total_code_point_count += emoji.code_points.size();
}
generator.set("total_code_point_count", String::number(total_code_point_count));
generator.set("total_code_point_count", DeprecatedString::number(total_code_point_count));
generator.append(R"~~~(
static constexpr Array<u32, @total_code_point_count@> s_emoji_code_points { {)~~~");
@ -207,7 +207,7 @@ static constexpr Array<u32, @total_code_point_count@> s_emoji_code_points { {)~~
for (auto const& emoji : emoji_data.emojis) {
for (auto code_point : emoji.code_points) {
generator.append(first ? " "sv : ", "sv);
generator.append(String::formatted("{:#x}", code_point));
generator.append(DeprecatedString::formatted("{:#x}", code_point));
first = false;
}
}
@ -245,11 +245,11 @@ struct EmojiData {
static constexpr Array<EmojiData, @emojis_size@> s_emojis { {)~~~");
for (auto const& emoji : emoji_data.emojis) {
generator.set("name"sv, String::number(emoji.name));
generator.set("group"sv, String::number(to_underlying(emoji.group)));
generator.set("display_order"sv, String::number(emoji.display_order));
generator.set("code_point_start"sv, String::number(emoji.code_point_array_index));
generator.set("code_point_count"sv, String::number(emoji.code_points.size()));
generator.set("name"sv, DeprecatedString::number(emoji.name));
generator.set("group"sv, DeprecatedString::number(to_underlying(emoji.group)));
generator.set("display_order"sv, DeprecatedString::number(emoji.display_order));
generator.set("code_point_start"sv, DeprecatedString::number(emoji.code_point_array_index));
generator.set("code_point_count"sv, DeprecatedString::number(emoji.code_points.size()));
generator.append(R"~~~(
{ @name@, @group@, @display_order@, @code_point_start@, @code_point_count@ },)~~~");
@ -312,7 +312,7 @@ static ErrorOr<void> generate_emoji_installation(Core::Stream::BufferedFile& fil
generator.append("@emoji@"sv);
generator.append(" - "sv);
generator.append(String::join(" "sv, emoji.code_points, "U+{:X}"sv));
generator.append(DeprecatedString::join(" "sv, emoji.code_points, "U+{:X}"sv));
generator.append(" @name@ (@status@)\n"sv);
}

View File

@ -8,12 +8,12 @@
#include <AK/AllOf.h>
#include <AK/Array.h>
#include <AK/CharacterTypes.h>
#include <AK/DeprecatedString.h>
#include <AK/Find.h>
#include <AK/HashMap.h>
#include <AK/Optional.h>
#include <AK/QuickSort.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringUtils.h>
#include <AK/Types.h>
#include <AK/Vector.h>
@ -37,21 +37,21 @@ struct SpecialCasing {
Vector<u32> lowercase_mapping;
Vector<u32> uppercase_mapping;
Vector<u32> titlecase_mapping;
String locale;
String condition;
DeprecatedString locale;
DeprecatedString condition;
};
// Field descriptions: https://www.unicode.org/reports/tr44/#Character_Decomposition_Mappings
struct CodePointDecomposition {
// `tag` is a string since it's used for codegen as an enum value.
String tag { "Canonical"sv };
DeprecatedString tag { "Canonical"sv };
size_t decomposition_index { 0 };
size_t decomposition_size { 0 };
};
// PropList source: https://www.unicode.org/Public/13.0.0/ucd/PropList.txt
// Property descriptions: https://www.unicode.org/reports/tr44/tr44-13.html#PropList.txt
using PropList = HashMap<String, Vector<CodePointRange>>;
using PropList = HashMap<DeprecatedString, Vector<CodePointRange>>;
// Normalization source: https://www.unicode.org/Public/13.0.0/ucd/DerivedNormalizationProps.txt
// Normalization descriptions: https://www.unicode.org/reports/tr44/#DerivedNormalizationProps.txt
@ -67,7 +67,7 @@ struct Normalization {
QuickCheck quick_check { QuickCheck::Yes };
};
using NormalizationProps = HashMap<String, Vector<Normalization>>;
using NormalizationProps = HashMap<DeprecatedString, Vector<Normalization>>;
struct CodePointName {
CodePointRange code_point_range;
@ -79,17 +79,17 @@ struct CodePointName {
// https://www.unicode.org/reports/tr44/#General_Category_Values
struct CodePointData {
u32 code_point { 0 };
String name;
DeprecatedString name;
Optional<size_t> abbreviation;
u8 canonical_combining_class { 0 };
String bidi_class;
DeprecatedString bidi_class;
Optional<CodePointDecomposition> decomposition_mapping;
Optional<i8> numeric_value_decimal;
Optional<i8> numeric_value_digit;
Optional<i8> numeric_value_numeric;
bool bidi_mirrored { false };
String unicode_1_name;
String iso_comment;
DeprecatedString unicode_1_name;
DeprecatedString iso_comment;
Optional<u32> simple_uppercase_mapping;
Optional<u32> simple_lowercase_mapping;
Optional<u32> simple_titlecase_mapping;
@ -108,7 +108,7 @@ struct UnicodeData {
u32 code_points_with_decomposition_mapping { 0 };
Vector<u32> decomposition_mappings;
Vector<String> compatibility_tags;
Vector<DeprecatedString> compatibility_tags;
u32 simple_uppercase_mapping_size { 0 };
u32 simple_lowercase_mapping_size { 0 };
@ -117,8 +117,8 @@ struct UnicodeData {
u32 code_points_with_special_casing { 0 };
u32 largest_casing_transform_size { 0 };
u32 largest_special_casing_size { 0 };
Vector<String> conditions;
Vector<String> locales;
Vector<DeprecatedString> conditions;
Vector<DeprecatedString> locales;
Vector<CodePointData> code_point_data;
@ -159,7 +159,7 @@ struct UnicodeData {
PropList sentence_break_props;
};
static String sanitize_entry(String const& entry)
static DeprecatedString sanitize_entry(DeprecatedString const& entry)
{
auto sanitized = entry.replace("-"sv, "_"sv, ReplaceMode::All);
sanitized = sanitized.replace(" "sv, "_"sv, ReplaceMode::All);
@ -243,7 +243,7 @@ static ErrorOr<void> parse_special_casing(Core::Stream::BufferedFile& file, Unic
}
if (!casing.locale.is_empty()) {
casing.locale = String::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
casing.locale = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
if (!unicode_data.locales.contains_slow(casing.locale))
unicode_data.locales.append(casing.locale);
@ -313,7 +313,7 @@ static ErrorOr<void> parse_prop_list(Core::Stream::BufferedFile& file, PropList&
static ErrorOr<void> parse_alias_list(Core::Stream::BufferedFile& file, PropList const& prop_list, Vector<Alias>& prop_aliases)
{
String current_property;
DeprecatedString current_property;
Array<u8, 1024> buffer;
auto append_alias = [&](auto alias, auto property) {
@ -388,7 +388,7 @@ static ErrorOr<void> parse_name_aliases(Core::Stream::BufferedFile& file, Unicod
return {};
}
static ErrorOr<void> parse_value_alias_list(Core::Stream::BufferedFile& file, StringView desired_category, Vector<String> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false)
static ErrorOr<void> parse_value_alias_list(Core::Stream::BufferedFile& file, StringView desired_category, Vector<DeprecatedString> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false)
{
TRY(file.seek(0, Core::Stream::SeekMode::SetPosition));
Array<u8, 1024> buffer;
@ -553,7 +553,7 @@ static Optional<CodePointDecomposition> parse_decomposition_mapping(StringView s
if (parts.first().starts_with('<')) {
auto const tag = parts.take_first().trim("<>"sv);
mapping.tag = String::formatted("{:c}{}", to_ascii_uppercase(tag[0]), tag.substring_view(1));
mapping.tag = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(tag[0]), tag.substring_view(1));
if (!unicode_data.compatibility_tags.contains_slow(mapping.tag))
unicode_data.compatibility_tags.append(mapping.tag);
@ -689,14 +689,14 @@ static ErrorOr<void> generate_unicode_data_header(Core::Stream::BufferedFile& fi
{
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("casing_transform_size", String::number(unicode_data.largest_casing_transform_size));
generator.set("casing_transform_size", DeprecatedString::number(unicode_data.largest_casing_transform_size));
auto generate_enum = [&](StringView name, StringView default_, Vector<String> values, Vector<Alias> aliases = {}) {
auto generate_enum = [&](StringView name, StringView default_, Vector<DeprecatedString> values, Vector<Alias> aliases = {}) {
quick_sort(values);
quick_sort(aliases, [](auto& alias1, auto& alias2) { return alias1.alias < alias2.alias; });
generator.set("name", name);
generator.set("underlying", String::formatted("{}UnderlyingType", name));
generator.set("underlying", DeprecatedString::formatted("{}UnderlyingType", name));
generator.set("type", ((values.size() + !default_.is_empty()) < 256) ? "u8"sv : "u16"sv);
generator.append(R"~~~(
@ -793,8 +793,8 @@ static ErrorOr<void> generate_unicode_data_implementation(Core::Stream::Buffered
SourceGenerator generator { builder };
generator.set("string_index_type"sv, unicode_data.unique_strings.type_that_fits());
generator.set("largest_special_casing_size", String::number(unicode_data.largest_special_casing_size));
generator.set("special_casing_size", String::number(unicode_data.special_casing.size()));
generator.set("largest_special_casing_size", DeprecatedString::number(unicode_data.largest_special_casing_size));
generator.set("special_casing_size", DeprecatedString::number(unicode_data.special_casing.size()));
generator.append(R"~~~(
#include <AK/Array.h>
@ -802,7 +802,7 @@ static ErrorOr<void> generate_unicode_data_implementation(Core::Stream::Buffered
#include <AK/CharacterTypes.h>
#include <AK/Optional.h>
#include <AK/Span.h>
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/StringView.h>
#include <LibUnicode/CharacterTypes.h>
#include <LibUnicode/UnicodeData.h>
@ -823,17 +823,17 @@ namespace Unicode {
generator.append(", {");
for (auto const& item : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(String::formatted(format, item));
generator.append(DeprecatedString::formatted(format, item));
first = false;
}
generator.append(String::formatted(" }}, {}", list.size()));
generator.append(DeprecatedString::formatted(" }}, {}", list.size()));
};
generator.append(R"~~~(
static constexpr Array<SpecialCasing, @special_casing_size@> s_special_casing { {)~~~");
for (auto const& casing : unicode_data.special_casing) {
generator.set("code_point", String::formatted("{:#x}", casing.code_point));
generator.set("code_point", DeprecatedString::formatted("{:#x}", casing.code_point));
generator.append(R"~~~(
{ @code_point@)~~~");
@ -910,15 +910,15 @@ struct CodePointNameComparator : public CodePointRangeComparator {
};
)~~~");
generator.set("decomposition_mappings_size", String::number(unicode_data.decomposition_mappings.size()));
generator.set("decomposition_mappings_size", DeprecatedString::number(unicode_data.decomposition_mappings.size()));
generator.append("\nstatic constexpr Array<u32, @decomposition_mappings_size@> s_decomposition_mappings_data { ");
generator.append(String::join(", "sv, unicode_data.decomposition_mappings, "{:#x}"sv));
generator.append(DeprecatedString::join(", "sv, unicode_data.decomposition_mappings, "{:#x}"sv));
generator.append(" };\n");
auto append_code_point_mappings = [&](StringView name, StringView mapping_type, u32 size, auto mapping_getter) {
generator.set("name", name);
generator.set("mapping_type", mapping_type);
generator.set("size", String::number(size));
generator.set("size", DeprecatedString::number(size));
generator.append(R"~~~(
static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
@ -941,16 +941,16 @@ static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
if (mappings_in_current_row++ > 0)
generator.append(" ");
generator.set("code_point", String::formatted("{:#x}", data.code_point));
generator.set("code_point", DeprecatedString::formatted("{:#x}", data.code_point));
generator.append("{ @code_point@");
if constexpr (IsSame<decltype(mapping), Optional<u32>> || IsSame<decltype(mapping), Optional<size_t>>) {
generator.set("mapping", String::formatted("{:#x}", *mapping));
generator.set("mapping", DeprecatedString::formatted("{:#x}", *mapping));
generator.append(", @mapping@ },");
} else if constexpr (IsSame<decltype(mapping), Optional<CodePointDecomposition>>) {
generator.set("tag", mapping->tag);
generator.set("start", String::number(mapping->decomposition_index));
generator.set("size", String::number(mapping->decomposition_size));
generator.set("start", DeprecatedString::number(mapping->decomposition_index));
generator.set("size", DeprecatedString::number(mapping->decomposition_size));
generator.append(", CompatibilityFormattingTag::@tag@, @start@, @size@ },");
} else {
append_list_and_size(data.special_casing_indices, "&s_special_casing[{}]"sv);
@ -983,9 +983,9 @@ static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
return data.decomposition_mapping;
});
auto append_code_point_range_list = [&](String name, Vector<CodePointRange> const& ranges) {
auto append_code_point_range_list = [&](DeprecatedString name, Vector<CodePointRange> const& ranges) {
generator.set("name", name);
generator.set("size", String::number(ranges.size()));
generator.set("size", DeprecatedString::number(ranges.size()));
generator.append(R"~~~(
static constexpr Array<CodePointRange, @size@> @name@ { {
)~~~");
@ -997,8 +997,8 @@ static constexpr Array<CodePointRange, @size@> @name@ { {
if (ranges_in_current_row++ > 0)
generator.append(" ");
generator.set("first", String::formatted("{:#x}", range.first));
generator.set("last", String::formatted("{:#x}", range.last));
generator.set("first", DeprecatedString::formatted("{:#x}", range.first));
generator.set("last", DeprecatedString::formatted("{:#x}", range.last));
generator.append("{ @first@, @last@ },");
if (ranges_in_current_row == max_ranges_per_row) {
@ -1014,7 +1014,7 @@ static constexpr Array<CodePointRange, @size@> @name@ { {
auto append_prop_list = [&](StringView collection_name, StringView property_format, PropList const& property_list) {
for (auto const& property : property_list) {
auto name = String::formatted(property_format, property.key);
auto name = DeprecatedString::formatted(property_format, property.key);
append_code_point_range_list(move(name), property.value);
}
@ -1022,12 +1022,12 @@ static constexpr Array<CodePointRange, @size@> @name@ { {
quick_sort(property_names);
generator.set("name", collection_name);
generator.set("size", String::number(property_names.size()));
generator.set("size", DeprecatedString::number(property_names.size()));
generator.append(R"~~~(
static constexpr Array<Span<CodePointRange const>, @size@> @name@ { {)~~~");
for (auto const& property_name : property_names) {
generator.set("name", String::formatted(property_format, property_name));
generator.set("name", DeprecatedString::formatted(property_format, property_name));
generator.append(R"~~~(
@name@.span(),)~~~");
}
@ -1052,7 +1052,7 @@ static constexpr Array<Span<CodePointRange const>, @size@> @name@ { {)~~~");
generator.set("type", type);
generator.set("name", name);
generator.set("size", String::number(display_names.size()));
generator.set("size", DeprecatedString::number(display_names.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@ { {
@ -1061,9 +1061,9 @@ static constexpr Array<@type@, @size@> @name@ { {
if (values_in_current_row++ > 0)
generator.append(", ");
generator.set("first", String::formatted("{:#x}", display_name.code_point_range.first));
generator.set("last", String::formatted("{:#x}", display_name.code_point_range.last));
generator.set("name", String::number(display_name.name));
generator.set("first", DeprecatedString::formatted("{:#x}", display_name.code_point_range.first));
generator.set("last", DeprecatedString::formatted("{:#x}", display_name.code_point_range.last));
generator.set("name", DeprecatedString::number(display_name.name));
generator.append("{ { @first@, @last@ }, @name@ }");
if (values_in_current_row == max_values_per_row) {
@ -1104,13 +1104,13 @@ Span<BlockName const> block_display_names()
return display_names.span();
}
Optional<String> code_point_display_name(u32 code_point)
Optional<DeprecatedString> code_point_display_name(u32 code_point)
{
if (auto const* entry = binary_search(s_code_point_display_names, code_point, nullptr, CodePointNameComparator {})) {
auto display_name = decode_string(entry->display_name);
if (display_name.ends_with("{:X}"sv))
return String::formatted(display_name, code_point);
return DeprecatedString::formatted(display_name, code_point);
return display_name;
}
@ -1197,7 +1197,7 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
ValueFromStringOptions options {};
for (auto const& prop : prop_list) {
if constexpr (IsSame<RemoveCVReference<decltype(prop)>, String>) {
if constexpr (IsSame<RemoveCVReference<decltype(prop)>, DeprecatedString>) {
hashes.set(CaseInsensitiveStringViewTraits::hash(prop), prop);
options.sensitivity = CaseSensitivity::CaseInsensitive;
} else {

View File

@ -6,6 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/HashFunctions.h>
#include <AK/HashMap.h>
@ -15,7 +16,6 @@
#include <AK/Optional.h>
#include <AK/QuickSort.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <AK/Traits.h>
@ -102,7 +102,7 @@ public:
{
generator.set("type"sv, type);
generator.set("name"sv, name);
generator.set("size"sv, String::number(m_storage.size()));
generator.set("size"sv, DeprecatedString::number(m_storage.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@ + 1> @name@ { {
@ -114,10 +114,10 @@ static constexpr Array<@type@, @size@ + 1> @name@ { {
if (values_in_current_row++ > 0)
generator.append(", ");
if constexpr (IsSame<StorageType, String>)
generator.append(String::formatted("\"{}\"sv", value));
if constexpr (IsSame<StorageType, DeprecatedString>)
generator.append(DeprecatedString::formatted("\"{}\"sv", value));
else
generator.append(String::formatted("{}", value));
generator.append(DeprecatedString::formatted("{}", value));
if (values_in_current_row == max_values_per_row) {
values_in_current_row = 0;
@ -139,8 +139,8 @@ static constexpr Array<@type@, @size@ + 1> @name@ { {
for (size_t i = 0; i < m_storage.size(); ++i) {
auto const& list = m_storage[i];
generator.set("index"sv, String::number(i));
generator.set("size"sv, String::number(list.size()));
generator.set("index"sv, DeprecatedString::number(i));
generator.set("size"sv, DeprecatedString::number(list.size()));
generator.append(R"~~~(
static constexpr Array<@type@, @size@> @name@@index@ { {)~~~");
@ -148,14 +148,14 @@ static constexpr Array<@type@, @size@> @name@@index@ { {)~~~");
bool first = true;
for (auto const& value : list) {
generator.append(first ? " "sv : ", "sv);
generator.append(String::formatted("{}", value));
generator.append(DeprecatedString::formatted("{}", value));
first = false;
}
generator.append(" } };");
}
generator.set("size"sv, String::number(m_storage.size()));
generator.set("size"sv, DeprecatedString::number(m_storage.size()));
generator.append(R"~~~(
@ -169,7 +169,7 @@ static constexpr Array<Span<@type@ const>, @size@ + 1> @name@ { {
if (values_in_current_row++ > 0)
generator.append(", ");
generator.set("index"sv, String::number(i));
generator.set("index"sv, DeprecatedString::number(i));
generator.append("@name@@index@.span()");
if (values_in_current_row == max_values_per_row) {
@ -188,8 +188,8 @@ protected:
HashMap<StorageType, size_t> m_storage_indices;
};
class UniqueStringStorage : public UniqueStorage<String> {
using Base = UniqueStorage<String>;
class UniqueStringStorage : public UniqueStorage<DeprecatedString> {
using Base = UniqueStorage<DeprecatedString>;
public:
// The goal of the string table generator is to ensure the table is located within the read-only
@ -205,7 +205,7 @@ public:
if (values_in_current_row++ > 0)
generator.append(", ");
generator.append(String::formatted("{:#x}", value));
generator.append(DeprecatedString::formatted("{:#x}", value));
if (values_in_current_row == max_values_per_row) {
values_in_current_row = 0;
@ -225,7 +225,7 @@ public:
next_index += string.length() + 2;
}
generator.set("size", String::number(next_index));
generator.set("size", DeprecatedString::number(next_index));
generator.append(R"~~~(
static constexpr Array<u8, @size@> s_encoded_strings { {
)~~~");
@ -243,7 +243,7 @@ static constexpr Array<u8, @size@> s_encoded_strings { {
} };
)~~~");
generator.set("size", String::number(string_indices.size()));
generator.set("size", DeprecatedString::number(string_indices.size()));
generator.append(R"~~~(
static constexpr Array<u32, @size@> s_encoded_string_indices { {
)~~~");
@ -277,8 +277,8 @@ static constexpr StringView decode_string(size_t index)
};
struct Alias {
String name;
String alias;
DeprecatedString name;
DeprecatedString alias;
};
struct CanonicalLanguageID {
@ -342,7 +342,7 @@ inline ErrorOr<JsonValue> read_json_file(StringView path)
return JsonValue::from_string(buffer);
}
inline ErrorOr<Core::DirIterator> path_to_dir_iterator(String path, StringView subpath = "main"sv)
inline ErrorOr<Core::DirIterator> path_to_dir_iterator(DeprecatedString path, StringView subpath = "main"sv)
{
LexicalPath lexical_path(move(path));
if (!subpath.is_empty())
@ -359,7 +359,7 @@ inline ErrorOr<Core::DirIterator> path_to_dir_iterator(String path, StringView s
return iterator;
}
inline ErrorOr<String> next_path_from_dir_iterator(Core::DirIterator& iterator)
inline ErrorOr<DeprecatedString> next_path_from_dir_iterator(Core::DirIterator& iterator)
{
auto next_path = iterator.next_full_path();
if (iterator.has_error()) {
@ -416,11 +416,11 @@ void generate_value_from_string(SourceGenerator& generator, StringView method_na
{
ensure_from_string_types_are_generated(generator);
generator.set("method_name", String::formatted(method_name_format, value_name));
generator.set("method_name", DeprecatedString::formatted(method_name_format, value_name));
generator.set("value_type", value_type);
generator.set("value_name", value_name);
generator.set("return_type", options.return_type.has_value() ? *options.return_type : value_type);
generator.set("size", String::number(hashes.size()));
generator.set("size", DeprecatedString::number(hashes.size()));
generator.append(R"~~~(
Optional<@return_type@> @method_name@(StringView key)
@ -439,11 +439,11 @@ Optional<@return_type@> @method_name@(StringView key)
generator.append(" ");
if constexpr (IsIntegral<ValueType>)
generator.set("value"sv, String::number(hashes.get(hash_key).value()));
generator.set("value"sv, DeprecatedString::number(hashes.get(hash_key).value()));
else
generator.set("value"sv, String::formatted("{}::{}", value_type, hashes.get(hash_key).value()));
generator.set("value"sv, DeprecatedString::formatted("{}::{}", value_type, hashes.get(hash_key).value()));
generator.set("hash"sv, String::number(hash_key));
generator.set("hash"sv, DeprecatedString::number(hash_key));
generator.append("{ @hash@U, @value@ },"sv);
if (values_in_current_row == max_values_per_row) {
@ -452,7 +452,7 @@ Optional<@return_type@> @method_name@(StringView key)
}
}
generator.set("return_statement", String::formatted(options.return_format, "value->value"sv));
generator.set("return_statement", DeprecatedString::formatted(options.return_format, "value->value"sv));
generator.append(R"~~~(
} };
)~~~");
@ -476,9 +476,9 @@ Optional<@return_type@> @method_name@(StringView key)
}
template<typename IdentifierFormatter>
void generate_value_to_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, IdentifierFormatter&& format_identifier, Span<String const> values)
void generate_value_to_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, IdentifierFormatter&& format_identifier, Span<DeprecatedString const> values)
{
generator.set("method_name", String::formatted(method_name_format, value_name));
generator.set("method_name", DeprecatedString::formatted(method_name_format, value_name));
generator.set("value_type", value_type);
generator.set("value_name", value_name);
@ -506,7 +506,7 @@ StringView @method_name@(@value_type@ @value_name@)
}
template<typename IdentifierFormatter>
void generate_enum(SourceGenerator& generator, IdentifierFormatter&& format_identifier, StringView name, StringView default_, Vector<String>& values, Vector<Alias> aliases = {})
void generate_enum(SourceGenerator& generator, IdentifierFormatter&& format_identifier, StringView name, StringView default_, Vector<DeprecatedString>& values, Vector<Alias> aliases = {})
{
quick_sort(values, [](auto const& value1, auto const& value2) { return value1.to_lowercase() < value2.to_lowercase(); });
quick_sort(aliases, [](auto const& alias1, auto const& alias2) { return alias1.alias.to_lowercase() < alias2.alias.to_lowercase(); });
@ -545,20 +545,20 @@ template<typename LocalesType, typename IdentifierFormatter, typename ListFormat
void generate_mapping(SourceGenerator& generator, LocalesType const& locales, StringView type, StringView name, StringView format, IdentifierFormatter&& format_identifier, ListFormatter&& format_list)
{
auto format_mapping_name = [&](StringView format, StringView name) {
String mapping_name;
DeprecatedString mapping_name;
if constexpr (IsNullPointer<IdentifierFormatter>)
mapping_name = name.replace("-"sv, "_"sv, ReplaceMode::All);
else
mapping_name = format_identifier(type, name);
return String::formatted(format, mapping_name.to_lowercase());
return DeprecatedString::formatted(format, mapping_name.to_lowercase());
};
Vector<String> mapping_names;
Vector<DeprecatedString> mapping_names;
for (auto const& locale : locales) {
String mapping_name;
DeprecatedString mapping_name;
if constexpr (requires { locale.key; }) {
mapping_name = format_mapping_name(format, locale.key);
@ -575,7 +575,7 @@ void generate_mapping(SourceGenerator& generator, LocalesType const& locales, St
generator.set("type", type);
generator.set("name", name);
generator.set("size", String::number(locales.size()));
generator.set("size", DeprecatedString::number(locales.size()));
generator.append(R"~~~(
static constexpr Array<Span<@type@ const>, @size@> @name@ { {
)~~~");
@ -620,9 +620,9 @@ Span<StringView const> @name@()
first = false;
if (auto it = aliases.find_if([&](auto const& alias) { return alias.alias == value; }); it != aliases.end())
generator.append(String::formatted("\"{}\"sv", it->name));
generator.append(DeprecatedString::formatted("\"{}\"sv", it->name));
else
generator.append(String::formatted("\"{}\"sv", value));
generator.append(DeprecatedString::formatted("\"{}\"sv", value));
}
generator.append(R"~~~( };

View File

@ -69,7 +69,7 @@ static StringView sequence_storage_type_to_cpp_storage_type_name(SequenceStorage
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface);
static String union_type_to_variant(UnionType const& union_type, Interface const& interface)
static DeprecatedString union_type_to_variant(UnionType const& union_type, Interface const& interface)
{
StringBuilder builder;
builder.append("Variant<"sv);
@ -95,10 +95,10 @@ static String union_type_to_variant(UnionType const& union_type, Interface const
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
{
if (is_platform_object(type))
return { .name = String::formatted("JS::Handle<{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
return { .name = DeprecatedString::formatted("JS::Handle<{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
if (type.is_string())
return { .name = "String", .sequence_storage_type = SequenceStorageType::Vector };
return { .name = "DeprecatedString", .sequence_storage_type = SequenceStorageType::Vector };
if (type.name() == "double" && !type.is_nullable())
return { .name = "double", .sequence_storage_type = SequenceStorageType::Vector };
@ -139,7 +139,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
if (sequence_cpp_type.sequence_storage_type == SequenceStorageType::MarkedVector)
return { .name = storage_type_name, .sequence_storage_type = SequenceStorageType::Vector };
return { .name = String::formatted("{}<{}>", storage_type_name, sequence_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
return { .name = DeprecatedString::formatted("{}<{}>", storage_type_name, sequence_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
}
if (type.name() == "record") {
@ -149,7 +149,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
auto record_key_cpp_type = idl_type_name_to_cpp_type(record_key_type, interface);
auto record_value_cpp_type = idl_type_name_to_cpp_type(record_value_type, interface);
return { .name = String::formatted("OrderedHashMap<{}, {}>", record_key_cpp_type.name, record_value_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
return { .name = DeprecatedString::formatted("OrderedHashMap<{}, {}>", record_key_cpp_type.name, record_value_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
}
if (is<UnionType>(type)) {
@ -168,7 +168,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
TODO();
}
static String make_input_acceptable_cpp(String const& input)
static DeprecatedString make_input_acceptable_cpp(DeprecatedString const& input)
{
if (input.is_one_of("class", "template", "for", "default", "char", "namespace", "delete", "inline")) {
StringBuilder builder;
@ -206,7 +206,7 @@ static void generate_include_for(auto& generator, auto& path)
}
LexicalPath include_path { path_string };
forked_generator.set("include.path", String::formatted("{}/{}.h", include_path.dirname(), include_path.title()));
forked_generator.set("include.path", DeprecatedString::formatted("{}/{}.h", include_path.dirname(), include_path.title()));
forked_generator.append(R"~~~(
#include <@include.path@>
)~~~");
@ -215,7 +215,7 @@ static void generate_include_for(auto& generator, auto& path)
static void emit_includes_for_all_imports(auto& interface, auto& generator, bool is_iterator = false)
{
Queue<RemoveCVReference<decltype(interface)> const*> interfaces;
HashTable<String> paths_imported;
HashTable<DeprecatedString> paths_imported;
interfaces.enqueue(&interface);
@ -236,15 +236,15 @@ static void emit_includes_for_all_imports(auto& interface, auto& generator, bool
generate_include_for(generator, interface->module_own_path);
if (is_iterator) {
auto iterator_name = String::formatted("{}Iterator", interface->name);
auto iterator_path = String::formatted("{}Iterator", interface->fully_qualified_name.replace("::"sv, "/"sv, ReplaceMode::All));
auto iterator_name = DeprecatedString::formatted("{}Iterator", interface->name);
auto iterator_path = DeprecatedString::formatted("{}Iterator", interface->fully_qualified_name.replace("::"sv, "/"sv, ReplaceMode::All));
generate_include_for_iterator(generator, iterator_path, iterator_name);
}
}
}
template<typename ParameterType>
static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter, String const& js_name, String const& js_suffix, String const& cpp_name, IDL::Interface const& interface, bool legacy_null_to_empty_string = false, bool optional = false, Optional<String> optional_default_value = {}, bool variadic = false, size_t recursion_depth = 0)
static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter, DeprecatedString const& js_name, DeprecatedString const& js_suffix, DeprecatedString const& cpp_name, IDL::Interface const& interface, bool legacy_null_to_empty_string = false, bool optional = false, Optional<DeprecatedString> optional_default_value = {}, bool variadic = false, size_t recursion_depth = 0)
{
auto scoped_generator = generator.fork();
auto acceptable_cpp_name = make_input_acceptable_cpp(cpp_name);
@ -261,7 +261,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (parameter.type->is_string()) {
if (variadic) {
scoped_generator.append(R"~~~(
Vector<String> @cpp_name@;
Vector<DeprecatedString> @cpp_name@;
@cpp_name@.ensure_capacity(vm.argument_count() - @js_suffix@);
for (size_t i = @js_suffix@; i < vm.argument_count(); ++i) {
@ -272,26 +272,26 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else if (!optional) {
if (!parameter.type->is_nullable()) {
scoped_generator.append(R"~~~(
String @cpp_name@;
DeprecatedString @cpp_name@;
if (@js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@) {
@cpp_name@ = String::empty();
@cpp_name@ = DeprecatedString::empty();
} else {
@cpp_name@ = TRY(@js_name@@js_suffix@.to_string(vm));
}
)~~~");
} else {
scoped_generator.append(R"~~~(
String @cpp_name@;
DeprecatedString @cpp_name@;
if (!@js_name@@js_suffix@.is_nullish())
@cpp_name@ = TRY(@js_name@@js_suffix@.to_string(vm));
)~~~");
}
} else {
scoped_generator.append(R"~~~(
String @cpp_name@;
DeprecatedString @cpp_name@;
if (!@js_name@@js_suffix@.is_undefined()) {
if (@js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@)
@cpp_name@ = String::empty();
@cpp_name@ = DeprecatedString::empty();
else
@cpp_name@ = TRY(@js_name@@js_suffix@.to_string(vm));
})~~~");
@ -573,7 +573,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto default_value_cpp_name = enumeration.translated_cpp_names.get(enum_member_name);
VERIFY(default_value_cpp_name.has_value());
enum_generator.set("enum.default.cpp_value", *default_value_cpp_name);
enum_generator.set("js_name.as_string", String::formatted("{}{}_string", enum_generator.get("js_name"sv), enum_generator.get("js_suffix"sv)));
enum_generator.set("js_name.as_string", DeprecatedString::formatted("{}{}_string", enum_generator.get("js_name"sv), enum_generator.get("js_suffix"sv)));
enum_generator.append(R"~~~(
@parameter.type.name@ @cpp_name@ { @parameter.type.name@::@enum.default.cpp_value@ };
)~~~");
@ -634,8 +634,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
for (auto& member : current_dictionary->members) {
dictionary_generator.set("member_key", member.name);
auto member_js_name = make_input_acceptable_cpp(member.name.to_snakecase());
auto member_value_name = String::formatted("{}_value", member_js_name);
auto member_property_value_name = String::formatted("{}_property_value", member_js_name);
auto member_value_name = DeprecatedString::formatted("{}_value", member_js_name);
auto member_property_value_name = DeprecatedString::formatted("{}_property_value", member_js_name);
dictionary_generator.set("member_name", member_js_name);
dictionary_generator.set("member_value_name", member_value_name);
dictionary_generator.set("member_property_value_name", member_property_value_name);
@ -705,7 +705,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto sequence_generator = scoped_generator.fork();
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
sequence_generator.set("recursion_depth", String::number(recursion_depth));
sequence_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
// An ECMAScript value V is converted to an IDL sequence<T> value as follows:
// 1. If Type(V) is not Object, throw a TypeError.
@ -757,7 +757,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, @js_name@@js_suffix@.to_string_without_side_effects());
)~~~");
parameterized_type.generate_sequence_from_iterable(sequence_generator, String::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), String::formatted("{}{}", js_name, js_suffix), String::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
parameterized_type.generate_sequence_from_iterable(sequence_generator, DeprecatedString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), DeprecatedString::formatted("{}{}", js_name, js_suffix), DeprecatedString::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
if (optional) {
sequence_generator.append(R"~~~(
@ -770,7 +770,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto record_generator = scoped_generator.fork();
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
record_generator.set("recursion_depth", String::number(recursion_depth));
record_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
// A record can only have two types: key type and value type.
VERIFY(parameterized_type.parameters().size() == 2);
@ -820,7 +820,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
IDL::Parameter key_parameter { .type = parameterized_type.parameters()[0], .name = acceptable_cpp_name, .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(record_generator, key_parameter, "key", String::number(recursion_depth), String::formatted("typed_key{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
generate_to_cpp(record_generator, key_parameter, "key", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("typed_key{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
record_generator.append(R"~~~(
auto value@recursion_depth@ = TRY(@js_name@@js_suffix@_object.get(property_key@recursion_depth@));
@ -828,7 +828,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// FIXME: Record value types should be TypeWithExtendedAttributes, which would allow us to get [LegacyNullToEmptyString] here.
IDL::Parameter value_parameter { .type = parameterized_type.parameters()[1], .name = acceptable_cpp_name, .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(record_generator, value_parameter, "value", String::number(recursion_depth), String::formatted("typed_value{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
generate_to_cpp(record_generator, value_parameter, "value", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("typed_value{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
record_generator.append(R"~~~(
@cpp_name@.set(typed_key@recursion_depth@, typed_value@recursion_depth@);
@ -841,7 +841,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto& union_type = verify_cast<IDL::UnionType>(*parameter.type);
union_generator.set("union_type", union_type_to_variant(union_type, interface));
union_generator.set("recursion_depth", String::number(recursion_depth));
union_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
// NOTE: This is handled out here as we need the dictionary conversion code for the {} optional default value.
// 3. Let types be the flattened member types of the union type.
@ -891,7 +891,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
to_variant_captures.append("&vm, &realm"sv);
if (dictionary_type)
to_variant_captures.append(String::formatted(", &{}{}_to_dictionary", js_name, js_suffix));
to_variant_captures.append(DeprecatedString::formatted(", &{}{}_to_dictionary", js_name, js_suffix));
union_generator.set("to_variant_captures", to_variant_captures.to_string());
@ -1028,7 +1028,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (method) {
)~~~");
sequence_type->generate_sequence_from_iterable(union_generator, acceptable_cpp_name, String::formatted("{}{}", js_name, js_suffix), "method", interface, recursion_depth + 1);
sequence_type->generate_sequence_from_iterable(union_generator, acceptable_cpp_name, DeprecatedString::formatted("{}{}", js_name, js_suffix), "method", interface, recursion_depth + 1);
union_generator.append(R"~~~(
@ -1113,8 +1113,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
// NOTE: generate_to_cpp doesn't use the parameter name.
// NOTE: generate_to_cpp will use to_{u32,etc.} which uses to_number internally and will thus use TRY, but it cannot throw as we know we are dealing with a number.
IDL::Parameter parameter { .type = *numeric_type, .name = String::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, String::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
IDL::Parameter parameter { .type = *numeric_type, .name = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, DeprecatedString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
union_generator.append(R"~~~(
return @js_name@@js_suffix@_number;
@ -1178,8 +1178,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// NOTE: generate_to_cpp doesn't use the parameter name.
// NOTE: generate_to_cpp will use to_{u32,etc.} which uses to_number internally and will thus use TRY, but it cannot throw as we know we are dealing with a number.
IDL::Parameter parameter { .type = *numeric_type, .name = String::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_numeric_type_generator, parameter, "x", String::empty(), "x_number", interface, false, false, {}, false, recursion_depth + 1);
IDL::Parameter parameter { .type = *numeric_type, .name = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_numeric_type_generator, parameter, "x", DeprecatedString::empty(), "x_number", interface, false, false, {}, false, recursion_depth + 1);
union_numeric_type_generator.append(R"~~~(
return x_number;
@ -1189,8 +1189,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// NOTE: generate_to_cpp doesn't use the parameter name.
// NOTE: generate_to_cpp will use to_{u32,etc.} which uses to_number internally and will thus use TRY, but it cannot throw as we know we are dealing with a number.
IDL::Parameter parameter { .type = *numeric_type, .name = String::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, String::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
IDL::Parameter parameter { .type = *numeric_type, .name = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(union_generator, parameter, js_name, js_suffix, DeprecatedString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
union_generator.append(R"~~~(
return @js_name@@js_suffix@_number;
@ -1233,7 +1233,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else {
if (optional_default_value == "\"\"") {
union_generator.append(R"~~~(
@union_type@ @cpp_name@ = @js_name@@js_suffix@.is_undefined() ? String::empty() : TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
@union_type@ @cpp_name@ = @js_name@@js_suffix@.is_undefined() ? DeprecatedString::empty() : TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
)~~~");
} else if (optional_default_value == "{}") {
VERIFY(dictionary_type);
@ -1266,21 +1266,21 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
}
}
static void generate_argument_count_check(SourceGenerator& generator, String const& function_name, size_t argument_count)
static void generate_argument_count_check(SourceGenerator& generator, DeprecatedString const& function_name, size_t argument_count)
{
if (argument_count == 0)
return;
auto argument_count_check_generator = generator.fork();
argument_count_check_generator.set("function.name", function_name);
argument_count_check_generator.set("function.nargs", String::number(argument_count));
argument_count_check_generator.set("function.nargs", DeprecatedString::number(argument_count));
if (argument_count == 1) {
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountOne");
argument_count_check_generator.set(".arg_count_suffix", "");
} else {
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountMany");
argument_count_check_generator.set(".arg_count_suffix", String::formatted(", \"{}\"", argument_count));
argument_count_check_generator.set(".arg_count_suffix", DeprecatedString::formatted(", \"{}\"", argument_count));
}
argument_count_check_generator.append(R"~~~(
@ -1293,20 +1293,20 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
{
auto arguments_generator = generator.fork();
Vector<String> parameter_names;
Vector<DeprecatedString> parameter_names;
size_t argument_index = 0;
for (auto& parameter : parameters) {
parameter_names.append(make_input_acceptable_cpp(parameter.name.to_snakecase()));
if (!parameter.variadic) {
arguments_generator.set("argument.index", String::number(argument_index));
arguments_generator.set("argument.index", DeprecatedString::number(argument_index));
arguments_generator.append(R"~~~(
auto arg@argument.index@ = vm.argument(@argument.index@);
)~~~");
}
bool legacy_null_to_empty_string = parameter.extended_attributes.contains("LegacyNullToEmptyString");
generate_to_cpp(generator, parameter, "arg", String::number(argument_index), parameter.name.to_snakecase(), interface, legacy_null_to_empty_string, parameter.optional, parameter.optional_default_value, parameter.variadic, 0);
generate_to_cpp(generator, parameter, "arg", DeprecatedString::number(argument_index), parameter.name.to_snakecase(), interface, legacy_null_to_empty_string, parameter.optional, parameter.optional_default_value, parameter.variadic, 0);
++argument_index;
}
@ -1314,13 +1314,13 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
}
// https://webidl.spec.whatwg.org/#create-sequence-from-iterable
void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& generator, String const& cpp_name, String const& iterable_cpp_name, String const& iterator_method_cpp_name, IDL::Interface const& interface, size_t recursion_depth) const
void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& generator, DeprecatedString const& cpp_name, DeprecatedString const& iterable_cpp_name, DeprecatedString const& iterator_method_cpp_name, IDL::Interface const& interface, size_t recursion_depth) const
{
auto sequence_generator = generator.fork();
sequence_generator.set("cpp_name", cpp_name);
sequence_generator.set("iterable_cpp_name", iterable_cpp_name);
sequence_generator.set("iterator_method_cpp_name", iterator_method_cpp_name);
sequence_generator.set("recursion_depth", String::number(recursion_depth));
sequence_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
auto sequence_cpp_type = idl_type_name_to_cpp_type(parameters().first(), interface);
sequence_generator.set("sequence.type", sequence_cpp_type.name);
sequence_generator.set("sequence.storage_type", sequence_storage_type_to_cpp_storage_type_name(sequence_cpp_type.sequence_storage_type));
@ -1360,7 +1360,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge
// FIXME: Sequences types should be TypeWithExtendedAttributes, which would allow us to get [LegacyNullToEmptyString] here.
IDL::Parameter parameter { .type = parameters().first(), .name = iterable_cpp_name, .optional_default_value = {}, .extended_attributes = {} };
generate_to_cpp(sequence_generator, parameter, "next_item", String::number(recursion_depth), String::formatted("sequence_item{}", recursion_depth), interface, false, false, {}, false, recursion_depth);
generate_to_cpp(sequence_generator, parameter, "next_item", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("sequence_item{}", recursion_depth), interface, false, false, {}, false, recursion_depth);
sequence_generator.append(R"~~~(
@cpp_name@.append(sequence_item@recursion_depth@);
@ -1373,13 +1373,13 @@ enum class WrappingReference {
Yes,
};
static void generate_wrap_statement(SourceGenerator& generator, String const& value, IDL::Type const& type, IDL::Interface const& interface, StringView result_expression, WrappingReference wrapping_reference = WrappingReference::No, size_t recursion_depth = 0)
static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString const& value, IDL::Type const& type, IDL::Interface const& interface, StringView result_expression, WrappingReference wrapping_reference = WrappingReference::No, size_t recursion_depth = 0)
{
auto scoped_generator = generator.fork();
scoped_generator.set("value", value);
scoped_generator.set("type", type.name());
scoped_generator.set("result_expression", result_expression);
scoped_generator.set("recursion_depth", String::number(recursion_depth));
scoped_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
if (type.name() == "undefined") {
scoped_generator.append(R"~~~(
@ -1443,7 +1443,7 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
auto* wrapped_element@recursion_depth@ = &(*element@recursion_depth@);
)~~~");
} else {
generate_wrap_statement(scoped_generator, String::formatted("element{}", recursion_depth), sequence_generic_type.parameters().first(), interface, String::formatted("auto wrapped_element{} =", recursion_depth), WrappingReference::Yes, recursion_depth + 1);
generate_wrap_statement(scoped_generator, DeprecatedString::formatted("element{}", recursion_depth), sequence_generic_type.parameters().first(), interface, DeprecatedString::formatted("auto wrapped_element{} =", recursion_depth), WrappingReference::Yes, recursion_depth + 1);
}
scoped_generator.append(R"~~~(
@ -1498,7 +1498,7 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
)~~~");
// NOTE: While we are using const&, the underlying type for wrappable types in unions is (Nonnull)RefPtr, which are not references.
generate_wrap_statement(union_generator, String::formatted("visited_union_value{}", recursion_depth), current_union_type, interface, "return"sv, WrappingReference::No, recursion_depth + 1);
generate_wrap_statement(union_generator, DeprecatedString::formatted("visited_union_value{}", recursion_depth), current_union_type, interface, "return"sv, WrappingReference::No, recursion_depth + 1);
// End of current visit lambda.
// The last lambda cannot have a trailing comma on the closing brace, unless the type is nullable, where an extra lambda will be generated for the Empty case.
@ -1561,14 +1561,14 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
while (true) {
for (auto& member : current_dictionary->members) {
dictionary_generator.set("member_key", member.name);
auto member_key_js_name = String::formatted("{}{}", make_input_acceptable_cpp(member.name.to_snakecase()), recursion_depth);
auto member_key_js_name = DeprecatedString::formatted("{}{}", make_input_acceptable_cpp(member.name.to_snakecase()), recursion_depth);
dictionary_generator.set("member_name", member_key_js_name);
auto member_value_js_name = String::formatted("{}_value", member_key_js_name);
auto member_value_js_name = DeprecatedString::formatted("{}_value", member_key_js_name);
dictionary_generator.set("member_value", member_value_js_name);
auto wrapped_value_name = String::formatted("auto wrapped_{}", member_value_js_name);
auto wrapped_value_name = DeprecatedString::formatted("auto wrapped_{}", member_value_js_name);
dictionary_generator.set("wrapped_value_name", wrapped_value_name);
generate_wrap_statement(dictionary_generator, String::formatted("{}.{}", value, member.name), member.type, interface, wrapped_value_name, WrappingReference::No, recursion_depth + 1);
generate_wrap_statement(dictionary_generator, DeprecatedString::formatted("{}.{}", value, member.name), member.type, interface, wrapped_value_name, WrappingReference::No, recursion_depth + 1);
dictionary_generator.append(R"~~~(
MUST(dictionary_object@recursion_depth@->create_data_property("@member_key@", @wrapped_value_name@));
@ -1617,24 +1617,24 @@ static void generate_return_statement(SourceGenerator& generator, IDL::Type cons
return generate_wrap_statement(generator, "retval", return_type, interface, "return"sv);
}
static void generate_variable_statement(SourceGenerator& generator, String const& variable_name, IDL::Type const& value_type, String const& value_name, IDL::Interface const& interface)
static void generate_variable_statement(SourceGenerator& generator, DeprecatedString const& variable_name, IDL::Type const& value_type, DeprecatedString const& value_name, IDL::Interface const& interface)
{
auto variable_generator = generator.fork();
variable_generator.set("variable_name", variable_name);
variable_generator.append(R"~~~(
JS::Value @variable_name@;
)~~~");
return generate_wrap_statement(generator, value_name, value_type, interface, String::formatted("{} = ", variable_name));
return generate_wrap_statement(generator, value_name, value_type, interface, DeprecatedString::formatted("{} = ", variable_name));
}
static void generate_function(SourceGenerator& generator, IDL::Function const& function, StaticFunction is_static_function, String const& class_name, String const& interface_fully_qualified_name, IDL::Interface const& interface)
static void generate_function(SourceGenerator& generator, IDL::Function const& function, StaticFunction is_static_function, DeprecatedString const& class_name, DeprecatedString const& interface_fully_qualified_name, IDL::Interface const& interface)
{
auto function_generator = generator.fork();
function_generator.set("class_name", class_name);
function_generator.set("interface_fully_qualified_name", interface_fully_qualified_name);
function_generator.set("function.name", function.name);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(function.name.to_snakecase()));
function_generator.set("overload_suffix", function.is_overloaded ? String::number(function.overload_index) : String::empty());
function_generator.set("overload_suffix", function.is_overloaded ? DeprecatedString::number(function.overload_index) : DeprecatedString::empty());
if (function.extended_attributes.contains("ImplementedAs")) {
auto implemented_as = function.extended_attributes.get("ImplementedAs").value();
@ -1672,7 +1672,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@@overload_suffi
if (arguments_builder.is_empty())
function_generator.set(".arguments", "vm");
else
function_generator.set(".arguments", String::formatted("vm, {}", arguments_builder.string_view()));
function_generator.set(".arguments", DeprecatedString::formatted("vm, {}", arguments_builder.string_view()));
function_generator.append(R"~~~(
[[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return @interface_fully_qualified_name@::@function.cpp_name@(@.arguments@); }));
@ -1813,7 +1813,7 @@ static EffectiveOverloadSet compute_the_effective_overload_set(auto const& overl
return EffectiveOverloadSet { move(overloads) };
}
static String generate_constructor_for_idl_type(Type const& type)
static DeprecatedString generate_constructor_for_idl_type(Type const& type)
{
auto append_type_list = [](auto& builder, auto const& type_list) {
bool first = true;
@ -1830,7 +1830,7 @@ static String generate_constructor_for_idl_type(Type const& type)
switch (type.kind()) {
case Type::Kind::Plain:
return String::formatted("make_ref_counted<IDL::Type>(\"{}\", {})", type.name(), type.is_nullable());
return DeprecatedString::formatted("make_ref_counted<IDL::Type>(\"{}\", {})", type.name(), type.is_nullable());
case Type::Kind::Parameterized: {
auto const& parameterized_type = type.as_parameterized();
StringBuilder builder;
@ -1852,7 +1852,7 @@ static String generate_constructor_for_idl_type(Type const& type)
VERIFY_NOT_REACHED();
}
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, String const& class_name)
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, DeprecatedString const& class_name)
{
auto function_generator = generator.fork();
function_generator.set("class_name", class_name);
@ -1869,7 +1869,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
auto maximum_argument_count = 0u;
for (auto const& overload : overloads_set)
maximum_argument_count = max(maximum_argument_count, overload.types.size());
function_generator.set("max_argument_count", String::number(maximum_argument_count));
function_generator.set("max_argument_count", DeprecatedString::number(maximum_argument_count));
function_generator.appendln(" switch (min(@max_argument_count@, vm.argument_count())) {");
// Generate the effective overload set for each argument count.
@ -1888,8 +1888,8 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
if (effective_overload_count == 0)
continue;
function_generator.set("current_argument_count", String::number(argument_count));
function_generator.set("overload_count", String::number(effective_overload_count));
function_generator.set("current_argument_count", DeprecatedString::number(argument_count));
function_generator.set("overload_count", DeprecatedString::number(effective_overload_count));
function_generator.appendln(R"~~~(
case @current_argument_count@: {
Vector<IDL::EffectiveOverloadSet::Item> overloads;
@ -1930,7 +1930,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
types_builder.append("}"sv);
optionality_builder.append("}"sv);
function_generator.set("overload.callable_id", String::number(overload.callable_id));
function_generator.set("overload.callable_id", DeprecatedString::number(overload.callable_id));
function_generator.set("overload.types", types_builder.to_string());
function_generator.set("overload.optionality_values", optionality_builder.to_string());
@ -1955,7 +1955,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
)~~~");
for (auto i = 0u; i < overload_set.value.size(); ++i) {
function_generator.set("overload_id", String::number(i));
function_generator.set("overload_id", DeprecatedString::number(i));
function_generator.append(R"~~~(
case @overload_id@:
return @function.name:snakecase@@overload_id@(vm);
@ -2009,7 +2009,7 @@ private:
)~~~");
if (overload_set.value.size() > 1) {
for (auto i = 0u; i < overload_set.value.size(); ++i) {
function_generator.set("overload_suffix", String::number(i));
function_generator.set("overload_suffix", DeprecatedString::number(i));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
)~~~");
@ -2143,7 +2143,7 @@ JS::ThrowCompletionOr<JS::Object*> @constructor_class@::construct(FunctionObject
// Single constructor
auto& constructor = interface.constructors[0];
generator.set("constructor.length", String::number(constructor.shortest_length()));
generator.set("constructor.length", DeprecatedString::number(constructor.shortest_length()));
generator.append(R"~~~(
auto& vm = this->vm();
@ -2191,7 +2191,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, String::formatted("auto constant_{}_value =", constant.name));
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
constant_generator.append(R"~~~(
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
@ -2203,7 +2203,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", String::number(get_shortest_function_length(overload_set.value)));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
function_generator.append(R"~~~(
define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
@ -2264,7 +2264,7 @@ private:
)~~~");
if (overload_set.value.size() > 1) {
for (auto i = 0u; i < overload_set.value.size(); ++i) {
function_generator.set("overload_suffix", String::number(i));
function_generator.set("overload_suffix", DeprecatedString::number(i));
function_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
)~~~");
@ -2326,7 +2326,7 @@ enum class @enum.type.name@ {
enum_generator.append(R"~~~(
};
inline String idl_enum_to_string(@enum.type.name@ value) {
inline DeprecatedString idl_enum_to_string(@enum.type.name@ value) {
switch(value) {
)~~~");
for (auto& entry : it.value.translated_cpp_names) {
@ -2364,7 +2364,7 @@ void generate_prototype_implementation(IDL::Interface const& interface)
generator.set("fully_qualified_name", interface.fully_qualified_name);
if (interface.pair_iterator_types.has_value()) {
generator.set("iterator_name", String::formatted("{}Iterator", interface.name));
generator.set("iterator_name", DeprecatedString::formatted("{}Iterator", interface.name));
}
generator.append(R"~~~(
@ -2500,7 +2500,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
auto constant_generator = generator.fork();
constant_generator.set("constant.name", constant.name);
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, String::formatted("auto constant_{}_value =", constant.name));
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
constant_generator.append(R"~~~(
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
@ -2512,7 +2512,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
auto function_generator = generator.fork();
function_generator.set("function.name", overload_set.key);
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
function_generator.set("function.length", String::number(get_shortest_function_length(overload_set.value)));
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
// FIXME: What if only some of the overloads are Unscopable?
if (any_of(overload_set.value, [](auto const& function) { return function.extended_attributes.contains("Unscopable"); })) {
@ -2686,7 +2686,7 @@ JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.setter_callback@)
if (!cpp_value)
impl->remove_attribute(HTML::AttributeNames::@attribute.reflect_name@);
else
MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::empty()));
MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, DeprecatedString::empty()));
)~~~");
}
} else {
@ -2801,7 +2801,7 @@ void generate_iterator_prototype_header(IDL::Interface const& interface)
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("prototype_class", String::formatted("{}IteratorPrototype", interface.name));
generator.set("prototype_class", DeprecatedString::formatted("{}IteratorPrototype", interface.name));
generator.append(R"~~~(
#pragma once
@ -2833,10 +2833,10 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface)
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("name", String::formatted("{}Iterator", interface.name));
generator.set("prototype_class", String::formatted("{}IteratorPrototype", interface.name));
generator.set("fully_qualified_name", String::formatted("{}Iterator", interface.fully_qualified_name));
generator.set("possible_include_path", String::formatted("{}Iterator", interface.name.replace("::"sv, "/"sv, ReplaceMode::All)));
generator.set("name", DeprecatedString::formatted("{}Iterator", interface.name));
generator.set("prototype_class", DeprecatedString::formatted("{}IteratorPrototype", interface.name));
generator.set("fully_qualified_name", DeprecatedString::formatted("{}Iterator", interface.fully_qualified_name));
generator.set("possible_include_path", DeprecatedString::formatted("{}Iterator", interface.name.replace("::"sv, "/"sv, ReplaceMode::All)));
generator.append(R"~~~(
#include <AK/Function.h>

View File

@ -58,8 +58,8 @@ enum class PropertyID {
Custom,
)~~~");
Vector<String> shorthand_property_ids;
Vector<String> longhand_property_ids;
Vector<DeprecatedString> shorthand_property_ids;
Vector<DeprecatedString> longhand_property_ids;
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());

View File

@ -39,7 +39,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
static String title_casify_transform_function(StringView input)
static DeprecatedString title_casify_transform_function(StringView input)
{
// Transform function names look like `fooBar`, so we just have to make the first character uppercase.
StringBuilder builder;
@ -189,7 +189,7 @@ TransformFunctionMetadata transform_function_metadata(TransformFunction transfor
member_generator.append(first ? " "sv : ", "sv);
first = false;
member_generator.append(String::formatted("{{ TransformFunctionParameterType::{}, {}}}", parameter_type, value.as_object().get("required"sv).to_string()));
member_generator.append(DeprecatedString::formatted("{{ TransformFunctionParameterType::{}, {}}}", parameter_type, value.as_object().get("required"sv).to_string()));
});
member_generator.append(R"~~~( }

View File

@ -5,9 +5,9 @@
*/
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Stream.h>
@ -16,14 +16,14 @@
#include <LibMain/Main.h>
static ErrorOr<void> add_to_interface_sets(IDL::Interface&, Vector<IDL::Interface&>& window_exposed, Vector<IDL::Interface&>& dedicated_worker_exposed, Vector<IDL::Interface&>& shared_worker_exposed);
static String s_error_string;
static DeprecatedString s_error_string;
static ErrorOr<void> generate_exposed_interface_header(StringView class_name, StringView output_path)
{
StringBuilder builder;
SourceGenerator generator(builder);
generator.set("global_object_snake_name", String(class_name).to_snakecase());
generator.set("global_object_snake_name", DeprecatedString(class_name).to_snakecase());
generator.append(R"~~~(
#pragma once
@ -37,7 +37,7 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object&, JS::Realm&);
)~~~");
auto generated_header_path = LexicalPath(output_path).append(String::formatted("{}ExposedInterfaces.h", class_name)).string();
auto generated_header_path = LexicalPath(output_path).append(DeprecatedString::formatted("{}ExposedInterfaces.h", class_name)).string();
auto generated_header_file = TRY(Core::Stream::File::open(generated_header_path, Core::Stream::OpenMode::Write));
TRY(generated_header_file->write(generator.as_string_view().bytes()));
@ -50,7 +50,7 @@ static ErrorOr<void> generate_exposed_interface_implementation(StringView class_
SourceGenerator generator(builder);
generator.set("global_object_name", class_name);
generator.set("global_object_snake_name", String(class_name).to_snakecase());
generator.set("global_object_snake_name", DeprecatedString(class_name).to_snakecase());
generator.append(R"~~~(
#include <LibJS/Heap/DeferGC.h>
@ -123,7 +123,7 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object& global, JS::R
}
}
)~~~");
auto generated_implementation_path = LexicalPath(output_path).append(String::formatted("{}ExposedInterfaces.cpp", class_name)).string();
auto generated_implementation_path = LexicalPath(output_path).append(DeprecatedString::formatted("{}ExposedInterfaces.cpp", class_name)).string();
auto generated_implementation_file = TRY(Core::Stream::File::open(generated_implementation_path, Core::Stream::OpenMode::Write));
TRY(generated_implementation_file->write(generator.as_string_view().bytes()));
@ -136,7 +136,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringView output_path;
StringView base_path;
Vector<String> paths;
Vector<DeprecatedString> paths;
args_parser.add_option(output_path, "Path to output generated files into", "output-path", 'o', "output-path");
args_parser.add_option(base_path, "Path to root of IDL file tree", "base-path", 'b', "base-path");
@ -149,16 +149,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
const LexicalPath lexical_base(base_path);
// Read in all IDL files, we must own the storage for all of these for the lifetime of the program
Vector<String> file_contents;
for (String const& path : paths) {
Vector<DeprecatedString> file_contents;
for (DeprecatedString const& path : paths) {
auto file_or_error = Core::Stream::File::open(path, Core::Stream::OpenMode::Read);
if (file_or_error.is_error()) {
s_error_string = String::formatted("Unable to open file {}", path);
s_error_string = DeprecatedString::formatted("Unable to open file {}", path);
return Error::from_string_view(s_error_string);
}
auto file = file_or_error.release_value();
auto string = MUST(file->read_all());
file_contents.append(String(ReadonlyBytes(string)));
file_contents.append(DeprecatedString(ReadonlyBytes(string)));
}
VERIFY(paths.size() == file_contents.size());
@ -220,7 +220,7 @@ static ErrorOr<ExposedTo> parse_exposure_set(IDL::Interface& interface)
auto maybe_exposed = interface.extended_attributes.get("Exposed");
if (!maybe_exposed.has_value()) {
s_error_string = String::formatted("Interface {} is missing extended attribute Exposed", interface.name);
s_error_string = DeprecatedString::formatted("Interface {} is missing extended attribute Exposed", interface.name);
return Error::from_string_view(s_error_string);
}
auto exposed = maybe_exposed.value().trim_whitespace();
@ -250,18 +250,18 @@ static ErrorOr<ExposedTo> parse_exposure_set(IDL::Interface& interface)
} else if (candidate == "AudioWorklet"sv) {
whom |= ExposedTo::AudioWorklet;
} else {
s_error_string = String::formatted("Unknown Exposed attribute candidate {} in {} in {}", candidate, exposed, interface.name);
s_error_string = DeprecatedString::formatted("Unknown Exposed attribute candidate {} in {} in {}", candidate, exposed, interface.name);
return Error::from_string_view(s_error_string);
}
}
if (whom == ExposedTo::Nobody) {
s_error_string = String::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
s_error_string = DeprecatedString::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
return Error::from_string_view(s_error_string);
}
return whom;
}
s_error_string = String::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
s_error_string = DeprecatedString::formatted("Unknown Exposed attribute {} in {}", exposed, interface.name);
return Error::from_string_view(s_error_string);
}
@ -275,7 +275,7 @@ static IDL::Interface& add_synthetic_interface(IDL::Interface& reference_interfa
auto new_interface = make<IDL::Interface>();
new_interface->name = name;
new_interface->constructor_class = String::formatted("{}Constructor", new_interface->name);
new_interface->constructor_class = DeprecatedString::formatted("{}Constructor", new_interface->name);
new_interface->prototype_class = reference_interface.prototype_class;
new_interface->parent_name = "[Synthetic Interface]";

View File

@ -7,13 +7,13 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/JsonObject.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibCore/Stream.h>
#include <ctype.h>
String title_casify(String const& dashy_name)
DeprecatedString title_casify(DeprecatedString const& dashy_name)
{
auto parts = dashy_name.split('-');
StringBuilder builder;
@ -28,7 +28,7 @@ String title_casify(String const& dashy_name)
return builder.to_string();
}
String camel_casify(StringView dashy_name)
DeprecatedString camel_casify(StringView dashy_name)
{
auto parts = dashy_name.split_view('-');
StringBuilder builder;
@ -49,7 +49,7 @@ String camel_casify(StringView dashy_name)
return builder.to_string();
}
String snake_casify(String const& dashy_name)
DeprecatedString snake_casify(DeprecatedString const& dashy_name)
{
return dashy_name.replace("-"sv, "_"sv, ReplaceMode::All);
}

View File

@ -4,11 +4,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/GenericLexer.h>
#include <AK/HashTable.h>
#include <AK/OwnPtr.h>
#include <AK/SourceGenerator.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Types.h>
#include <LibCore/ArgsParser.h>
@ -22,8 +22,8 @@ struct Range {
};
struct StateTransition {
Optional<String> new_state;
Optional<String> action;
Optional<DeprecatedString> new_state;
Optional<DeprecatedString> action;
};
struct MatchedAction {
@ -32,18 +32,18 @@ struct MatchedAction {
};
struct State {
String name;
DeprecatedString name;
Vector<MatchedAction> actions;
Optional<String> entry_action;
Optional<String> exit_action;
Optional<DeprecatedString> entry_action;
Optional<DeprecatedString> exit_action;
};
struct StateMachine {
String name;
String initial_state;
DeprecatedString name;
DeprecatedString initial_state;
Vector<State> states;
Optional<State> anywhere;
Optional<String> namespaces;
Optional<DeprecatedString> namespaces;
};
static OwnPtr<StateMachine>
@ -232,9 +232,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
HashTable<String> actions(StateMachine const& machine)
HashTable<DeprecatedString> actions(StateMachine const& machine)
{
HashTable<String> table;
HashTable<DeprecatedString> table;
auto do_state = [&](State const& state) {
if (state.entry_action.has_value())
@ -296,7 +296,7 @@ void output_header(StateMachine const& machine, SourceGenerator& generator)
{
generator.set("class_name", machine.name);
generator.set("initial_state", machine.initial_state);
generator.set("state_count", String::number(machine.states.size() + 1));
generator.set("state_count", DeprecatedString::number(machine.states.size() + 1));
generator.append(R"~~~(
#pragma once

View File

@ -4,11 +4,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/Result.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibCore/ConfigFile.h>
@ -25,18 +25,18 @@ enum class ComponentCategory {
};
struct ComponentData {
String name;
String description;
DeprecatedString name;
DeprecatedString description;
ComponentCategory category { ComponentCategory::Optional };
bool was_selected { false };
Vector<String> dependencies;
Vector<DeprecatedString> dependencies;
bool is_selected { false };
};
struct WhiptailOption {
String tag;
String name;
String description;
DeprecatedString tag;
DeprecatedString name;
DeprecatedString description;
bool checked { false };
};
@ -77,7 +77,7 @@ static Vector<ComponentData> read_component_data(Core::ConfigFile const& config_
return components;
}
static Result<Vector<String>, int> run_whiptail(WhiptailMode mode, Vector<WhiptailOption> const& options, StringView title, StringView description)
static Result<Vector<DeprecatedString>, int> run_whiptail(WhiptailMode mode, Vector<WhiptailOption> const& options, StringView title, StringView description)
{
struct winsize w;
if (ioctl(0, TIOCGWINSZ, &w) < 0) {
@ -97,7 +97,7 @@ static Result<Vector<String>, int> run_whiptail(WhiptailMode mode, Vector<Whipta
int read_fd = pipefd[0];
int write_fd = pipefd[1];
Vector<String> arguments = { "whiptail", "--notags", "--separate-output", "--output-fd", String::number(write_fd) };
Vector<DeprecatedString> arguments = { "whiptail", "--notags", "--separate-output", "--output-fd", DeprecatedString::number(write_fd) };
if (!title.is_empty()) {
arguments.append("--title");
@ -116,13 +116,13 @@ static Result<Vector<String>, int> run_whiptail(WhiptailMode mode, Vector<Whipta
}
if (description.is_empty())
arguments.append(String::empty());
arguments.append(DeprecatedString::empty());
else
arguments.append(String::formatted("\n {}", description));
arguments.append(DeprecatedString::formatted("\n {}", description));
arguments.append(String::number(height));
arguments.append(String::number(width));
arguments.append(String::number(height - 9));
arguments.append(DeprecatedString::number(height));
arguments.append(DeprecatedString::number(width));
arguments.append(DeprecatedString::number(height - 9));
// Check how wide the name field needs to be.
size_t max_name_width = 0;
@ -133,7 +133,7 @@ static Result<Vector<String>, int> run_whiptail(WhiptailMode mode, Vector<Whipta
for (auto& option : options) {
arguments.append(option.tag);
arguments.append(String::formatted("{:{2}} {}", option.name, option.description, max_name_width));
arguments.append(DeprecatedString::formatted("{:{2}} {}", option.name, option.description, max_name_width));
if (mode == WhiptailMode::Checklist)
arguments.append(option.checked ? "1" : "0");
}
@ -151,7 +151,7 @@ static Result<Vector<String>, int> run_whiptail(WhiptailMode mode, Vector<Whipta
return -1;
}
auto full_term_variable = String::formatted("TERM={}", term_variable);
auto full_term_variable = DeprecatedString::formatted("TERM={}", term_variable);
auto colors = "NEWT_COLORS=root=,black\ncheckbox=black,lightgray";
char* env[3];
@ -194,11 +194,11 @@ static Result<Vector<String>, int> run_whiptail(WhiptailMode mode, Vector<Whipta
auto file = Core::File::construct();
file->open(read_fd, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
auto data = String::copy(file->read_all());
auto data = DeprecatedString::copy(file->read_all());
return data.split('\n');
}
static bool run_system_command(String const& command, StringView command_name)
static bool run_system_command(DeprecatedString const& command, StringView command_name)
{
if (command.starts_with("cmake"sv))
warnln("\e[34mRunning CMake...\e[0m");
@ -274,7 +274,7 @@ int main()
StringView build_type = customize ? type.substring_view(7) : type.view();
// Step 4: Customize the configuration if the user requested to. In any case, set the components component.is_selected value correctly.
Vector<String> activated_components;
Vector<DeprecatedString> activated_components;
if (customize) {
Vector<WhiptailOption> options;
@ -336,12 +336,12 @@ int main()
}
// Step 5: Generate the cmake command.
Vector<String> cmake_arguments = { "cmake", "../..", "-G", "Ninja", "-DBUILD_EVERYTHING=OFF" };
Vector<DeprecatedString> cmake_arguments = { "cmake", "../..", "-G", "Ninja", "-DBUILD_EVERYTHING=OFF" };
for (auto& component : components)
cmake_arguments.append(String::formatted("-DBUILD_{}={}", component.name.to_uppercase(), component.is_selected ? "ON" : "OFF"));
cmake_arguments.append(DeprecatedString::formatted("-DBUILD_{}={}", component.name.to_uppercase(), component.is_selected ? "ON" : "OFF"));
warnln("\e[34mThe following command will be run:\e[0m");
outln("{} \\", String::join(' ', cmake_arguments));
outln("{} \\", DeprecatedString::join(' ', cmake_arguments));
outln(" && ninja clean\n && rm -rf Root");
warn("\e[34mDo you want to run the command?\e[0m [Y/n] ");
auto character = getchar();
@ -351,7 +351,7 @@ int main()
}
// Step 6: Run CMake, 'ninja clean' and 'rm -rf Root'
auto command = String::join(' ', cmake_arguments);
auto command = DeprecatedString::join(' ', cmake_arguments);
if (!run_system_command(command, "CMake"sv))
return 1;
if (!run_system_command("ninja clean"sv, "Ninja"sv))

View File

@ -21,10 +21,10 @@ int main(int argc, char** argv)
}
// Read files, compute their hashes, ignore collisions for now.
HashMap<u32, Vector<String>> inverse_hashes;
HashMap<u32, Vector<DeprecatedString>> inverse_hashes;
bool had_errors = false;
for (int file_index = 1; file_index < argc; ++file_index) {
String filename(argv[file_index]);
DeprecatedString filename(argv[file_index]);
auto file_or_error = Core::File::open(filename, Core::OpenMode::ReadOnly);
if (file_or_error.is_error()) {
warnln("Error: Cannot open '{}': {}", filename, file_or_error.error());
@ -32,9 +32,9 @@ int main(int argc, char** argv)
continue; // next file
}
auto file = file_or_error.value();
String endpoint_name;
DeprecatedString endpoint_name;
while (true) {
String line = file->read_line();
DeprecatedString line = file->read_line();
if (file->error() != 0 || line.is_null())
break;
if (!line.starts_with("endpoint "sv))

View File

@ -50,7 +50,7 @@ EM_JS(void, user_display, (char const* string, u32 length), { globalDisplayToUse
template<typename... Args>
void display(CheckedFormatString<Args...> format_string, Args const&... args)
{
auto string = String::formatted(format_string.view(), args...);
auto string = DeprecatedString::formatted(format_string.view(), args...);
user_display(string.characters(), string.length());
}
@ -269,7 +269,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::print)
{
auto result = ::print(vm.argument(0));
if (result.is_error())
return g_vm->throw_completion<JS::InternalError>(String::formatted("Failed to print value: {}", result.error()));
return g_vm->throw_completion<JS::InternalError>(DeprecatedString::formatted("Failed to print value: {}", result.error()));
displayln();
@ -298,7 +298,7 @@ public:
// 2.3. Printer(logLevel, args[, options]), https://console.spec.whatwg.org/#printer
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments arguments) override
{
String indent = String::repeated(" "sv, m_group_stack_depth);
DeprecatedString indent = DeprecatedString::repeated(" "sv, m_group_stack_depth);
if (log_level == JS::Console::LogLevel::Trace) {
auto trace = arguments.get<JS::Console::Trace>();
@ -320,7 +320,7 @@ public:
return JS::js_undefined();
}
auto output = String::join(' ', arguments.get<JS::MarkedVector<JS::Value>>());
auto output = DeprecatedString::join(' ', arguments.get<JS::MarkedVector<JS::Value>>());
switch (log_level) {
case JS::Console::LogLevel::Debug:
displayln("{}{}", indent, output);

View File

@ -188,7 +188,7 @@ index 0000000000000000000000000000000000000000..cc0c08cb85a682d66a00f6b48ad2871f
+ unix_getUserInfo(env, jinfo, proc.pid);
+ JNU_CHECK_EXCEPTION(env);
+
+ auto cmdline_file = JAVA_TRY(Core::Stream::File::open(String::formatted("/proc/{}/cmdline", pid), Core::Stream::OpenMode::Read), "Unable to open /proc/pid/cmdline"sv);
+ auto cmdline_file = JAVA_TRY(Core::Stream::File::open(DeprecatedString::formatted("/proc/{}/cmdline", pid), Core::Stream::OpenMode::Read), "Unable to open /proc/pid/cmdline"sv);
+ auto contents = JAVA_TRY(cmdline_file->read_all(), "Unable to read /proc/pid/cmdline"sv);
+ auto cmdline = JAVA_TRY(JsonValue::from_string(contents), "Invalid JSON in /proc/pid/cmdline"sv);
+

View File

@ -19,6 +19,7 @@ set(AK_TEST_SOURCES
TestCircularDuplexStream.cpp
TestCircularQueue.cpp
TestComplex.cpp
TestDeprecatedString.cpp
TestDisjointChunks.cpp
TestDistinctNumeric.cpp
TestDoublyLinkedList.cpp
@ -61,7 +62,6 @@ set(AK_TEST_SOURCES
TestSpan.cpp
TestStack.cpp
TestStdLibExtras.cpp
TestString.cpp
TestStringFloatingPointConversions.cpp
TestStringUtils.cpp
TestStringView.cpp

View File

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/Base64.h>
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <string.h>
TEST_CASE(test_decode)
@ -16,7 +16,7 @@ TEST_CASE(test_decode)
auto decoded_option = decode_base64(input);
EXPECT(!decoded_option.is_error());
auto decoded = decoded_option.release_value();
EXPECT(String::copy(decoded) == expected);
EXPECT(DeprecatedString::copy(decoded) == expected);
EXPECT(expected.length() <= calculate_base64_decoded_length(input.bytes()));
};
@ -43,7 +43,7 @@ TEST_CASE(test_encode)
{
auto encode_equal = [&](StringView input, StringView expected) {
auto encoded = encode_base64(input.bytes());
EXPECT(encoded == String(expected));
EXPECT(encoded == DeprecatedString(expected));
EXPECT_EQ(expected.length(), calculate_base64_encoded_length(input.bytes()));
};

View File

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/BinaryHeap.h>
#include <AK/String.h>
#include <AK/DeprecatedString.h>
TEST_CASE(construct)
{
@ -44,7 +44,7 @@ TEST_CASE(populate_int)
TEST_CASE(populate_string)
{
BinaryHeap<int, String, 5> strings;
BinaryHeap<int, DeprecatedString, 5> strings;
strings.insert(1, "ABC");
strings.insert(2, "DEF");
EXPECT_EQ(strings.size(), 2u);

View File

@ -49,20 +49,20 @@ TEST_CASE(array_doubles)
TEST_CASE(vector_strings)
{
Vector<String> strings;
Vector<DeprecatedString> strings;
strings.append("bat");
strings.append("cat");
strings.append("dog");
auto string_compare = [](String const& a, String const& b) -> int {
auto string_compare = [](DeprecatedString const& a, DeprecatedString const& b) -> int {
return strcmp(a.characters(), b.characters());
};
auto test1 = *binary_search(strings, String("bat"), nullptr, string_compare);
auto test2 = *binary_search(strings, String("cat"), nullptr, string_compare);
auto test3 = *binary_search(strings, String("dog"), nullptr, string_compare);
EXPECT_EQ(test1, String("bat"));
EXPECT_EQ(test2, String("cat"));
EXPECT_EQ(test3, String("dog"));
auto test1 = *binary_search(strings, DeprecatedString("bat"), nullptr, string_compare);
auto test2 = *binary_search(strings, DeprecatedString("cat"), nullptr, string_compare);
auto test3 = *binary_search(strings, DeprecatedString("dog"), nullptr, string_compare);
EXPECT_EQ(test1, DeprecatedString("bat"));
EXPECT_EQ(test2, DeprecatedString("cat"));
EXPECT_EQ(test3, DeprecatedString("dog"));
}
TEST_CASE(single_element)

View File

@ -7,8 +7,8 @@
#include <LibTest/TestCase.h>
#include <AK/CircularDeque.h>
#include <AK/DeprecatedString.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
TEST_CASE(enqueue_begin)
{
@ -37,9 +37,9 @@ TEST_CASE(enqueue_begin)
TEST_CASE(enqueue_begin_being_moved_from)
{
CircularDeque<String, 2> strings;
CircularDeque<DeprecatedString, 2> strings;
String str { "test" };
DeprecatedString str { "test" };
strings.enqueue_begin(move(str));
EXPECT(str.is_null());
}

View File

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/CircularQueue.h>
#include <AK/String.h>
#include <AK/DeprecatedString.h>
TEST_CASE(basic)
{
@ -28,7 +28,7 @@ TEST_CASE(basic)
TEST_CASE(complex_type)
{
CircularQueue<String, 2> strings;
CircularQueue<DeprecatedString, 2> strings;
strings.enqueue("ABC");
strings.enqueue("DEF");
@ -44,7 +44,7 @@ TEST_CASE(complex_type)
TEST_CASE(complex_type_clear)
{
CircularQueue<String, 5> strings;
CircularQueue<DeprecatedString, 5> strings;
strings.enqueue("xxx");
strings.enqueue("xxx");
strings.enqueue("xxx");

View File

@ -6,28 +6,28 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/FlyString.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <cstring>
TEST_CASE(construct_empty)
{
EXPECT(String().is_null());
EXPECT(String().is_empty());
EXPECT(!String().characters());
EXPECT(DeprecatedString().is_null());
EXPECT(DeprecatedString().is_empty());
EXPECT(!DeprecatedString().characters());
EXPECT(!String("").is_null());
EXPECT(String("").is_empty());
EXPECT(String("").characters() != nullptr);
EXPECT(!DeprecatedString("").is_null());
EXPECT(DeprecatedString("").is_empty());
EXPECT(DeprecatedString("").characters() != nullptr);
EXPECT(String("").impl() == String::empty().impl());
EXPECT(DeprecatedString("").impl() == DeprecatedString::empty().impl());
}
TEST_CASE(construct_contents)
{
String test_string = "ABCDEF";
DeprecatedString test_string = "ABCDEF";
EXPECT(!test_string.is_empty());
EXPECT(!test_string.is_null());
EXPECT_EQ(test_string.length(), 6u);
@ -42,45 +42,45 @@ TEST_CASE(construct_contents)
TEST_CASE(equal)
{
EXPECT_NE(String::empty(), String {});
EXPECT_NE(DeprecatedString::empty(), DeprecatedString {});
}
TEST_CASE(compare)
{
EXPECT("a"sv < String("b"));
EXPECT(!("a"sv > String("b")));
EXPECT("b"sv > String("a"));
EXPECT(!("b"sv < String("b")));
EXPECT("a"sv >= String("a"));
EXPECT(!("a"sv >= String("b")));
EXPECT("a"sv <= String("a"));
EXPECT(!("b"sv <= String("a")));
EXPECT("a"sv < DeprecatedString("b"));
EXPECT(!("a"sv > DeprecatedString("b")));
EXPECT("b"sv > DeprecatedString("a"));
EXPECT(!("b"sv < DeprecatedString("b")));
EXPECT("a"sv >= DeprecatedString("a"));
EXPECT(!("a"sv >= DeprecatedString("b")));
EXPECT("a"sv <= DeprecatedString("a"));
EXPECT(!("b"sv <= DeprecatedString("a")));
EXPECT(String("a") > String());
EXPECT(!(String() > String("a")));
EXPECT(String() < String("a"));
EXPECT(!(String("a") < String()));
EXPECT(String("a") >= String());
EXPECT(!(String() >= String("a")));
EXPECT(String() <= String("a"));
EXPECT(!(String("a") <= String()));
EXPECT(DeprecatedString("a") > DeprecatedString());
EXPECT(!(DeprecatedString() > DeprecatedString("a")));
EXPECT(DeprecatedString() < DeprecatedString("a"));
EXPECT(!(DeprecatedString("a") < DeprecatedString()));
EXPECT(DeprecatedString("a") >= DeprecatedString());
EXPECT(!(DeprecatedString() >= DeprecatedString("a")));
EXPECT(DeprecatedString() <= DeprecatedString("a"));
EXPECT(!(DeprecatedString("a") <= DeprecatedString()));
EXPECT(!(String() > String()));
EXPECT(!(String() < String()));
EXPECT(String() >= String());
EXPECT(String() <= String());
EXPECT(!(DeprecatedString() > DeprecatedString()));
EXPECT(!(DeprecatedString() < DeprecatedString()));
EXPECT(DeprecatedString() >= DeprecatedString());
EXPECT(DeprecatedString() <= DeprecatedString());
}
TEST_CASE(index_access)
{
String test_string = "ABCDEF";
DeprecatedString test_string = "ABCDEF";
EXPECT_EQ(test_string[0], 'A');
EXPECT_EQ(test_string[1], 'B');
}
TEST_CASE(starts_with)
{
String test_string = "ABCDEF";
DeprecatedString test_string = "ABCDEF";
EXPECT(test_string.starts_with("AB"sv));
EXPECT(test_string.starts_with('A'));
EXPECT(!test_string.starts_with('B'));
@ -92,7 +92,7 @@ TEST_CASE(starts_with)
TEST_CASE(ends_with)
{
String test_string = "ABCDEF";
DeprecatedString test_string = "ABCDEF";
EXPECT(test_string.ends_with("EF"sv));
EXPECT(test_string.ends_with('F'));
EXPECT(!test_string.ends_with('E'));
@ -104,7 +104,7 @@ TEST_CASE(ends_with)
TEST_CASE(copy_string)
{
String test_string = "ABCDEF";
DeprecatedString test_string = "ABCDEF";
auto test_string_copy = test_string;
EXPECT_EQ(test_string, test_string_copy);
EXPECT_EQ(test_string.characters(), test_string_copy.characters());
@ -112,7 +112,7 @@ TEST_CASE(copy_string)
TEST_CASE(move_string)
{
String test_string = "ABCDEF";
DeprecatedString test_string = "ABCDEF";
auto test_string_copy = test_string;
auto test_string_move = move(test_string_copy);
EXPECT_EQ(test_string, test_string_move);
@ -121,25 +121,25 @@ TEST_CASE(move_string)
TEST_CASE(repeated)
{
EXPECT_EQ(String::repeated('x', 0), "");
EXPECT_EQ(String::repeated('x', 1), "x");
EXPECT_EQ(String::repeated('x', 2), "xx");
EXPECT_EQ(DeprecatedString::repeated('x', 0), "");
EXPECT_EQ(DeprecatedString::repeated('x', 1), "x");
EXPECT_EQ(DeprecatedString::repeated('x', 2), "xx");
}
TEST_CASE(to_int)
{
EXPECT_EQ(String("123").to_int().value(), 123);
EXPECT_EQ(String("-123").to_int().value(), -123);
EXPECT_EQ(DeprecatedString("123").to_int().value(), 123);
EXPECT_EQ(DeprecatedString("-123").to_int().value(), -123);
}
TEST_CASE(to_lowercase)
{
EXPECT(String("ABC").to_lowercase() == "abc");
EXPECT(DeprecatedString("ABC").to_lowercase() == "abc");
}
TEST_CASE(to_uppercase)
{
EXPECT(String("AbC").to_uppercase() == "ABC");
EXPECT(DeprecatedString("AbC").to_uppercase() == "ABC");
}
TEST_CASE(flystring)
@ -151,7 +151,7 @@ TEST_CASE(flystring)
}
{
String a = "foo";
DeprecatedString a = "foo";
FlyString b = a;
StringBuilder builder;
builder.append('f');
@ -164,7 +164,7 @@ TEST_CASE(flystring)
TEST_CASE(replace)
{
String test_string = "Well, hello Friends!";
DeprecatedString test_string = "Well, hello Friends!";
test_string = test_string.replace("Friends"sv, "Testers"sv, ReplaceMode::FirstOnly);
EXPECT(test_string == "Well, hello Testers!");
@ -175,7 +175,7 @@ TEST_CASE(replace)
test_string = test_string.replace("!"sv, " :^)"sv, ReplaceMode::FirstOnly);
EXPECT(test_string == "We're, he'reo Testers :^)");
test_string = String("111._.111._.111");
test_string = DeprecatedString("111._.111._.111");
test_string = test_string.replace("111"sv, "|||"sv, ReplaceMode::All);
EXPECT(test_string == "|||._.|||._.|||");
@ -185,7 +185,7 @@ TEST_CASE(replace)
TEST_CASE(count)
{
String test_string = "Well, hello Friends!";
DeprecatedString test_string = "Well, hello Friends!";
u32 count = test_string.count("Friends"sv);
EXPECT(count == 1);
@ -195,7 +195,7 @@ TEST_CASE(count)
count = test_string.count("!"sv);
EXPECT(count == 1);
test_string = String("111._.111._.111");
test_string = DeprecatedString("111._.111._.111");
count = test_string.count("111"sv);
EXPECT(count == 3);
@ -205,7 +205,7 @@ TEST_CASE(count)
TEST_CASE(substring)
{
String test = "abcdef";
DeprecatedString test = "abcdef";
EXPECT_EQ(test.substring(0, 6), test);
EXPECT_EQ(test.substring(0, 3), "abc");
EXPECT_EQ(test.substring(3, 3), "def");
@ -215,7 +215,7 @@ TEST_CASE(substring)
TEST_CASE(split)
{
String test = "foo bar baz";
DeprecatedString test = "foo bar baz";
auto parts = test.split(' ');
EXPECT_EQ(parts.size(), 3u);
EXPECT_EQ(parts[0], "foo");
@ -259,7 +259,7 @@ TEST_CASE(builder_zero_initial_capacity)
TEST_CASE(find)
{
String a = "foobarbar";
DeprecatedString a = "foobarbar";
EXPECT_EQ(a.find("bar"sv), Optional<size_t> { 3 });
EXPECT_EQ(a.find("baz"sv), Optional<size_t> {});
EXPECT_EQ(a.find("bar"sv, 4), Optional<size_t> { 6 });
@ -275,7 +275,7 @@ TEST_CASE(find)
TEST_CASE(find_with_empty_needle)
{
String string = "";
DeprecatedString string = "";
EXPECT_EQ(string.find(""sv), 0u);
EXPECT_EQ(string.find_all(""sv), (Vector<size_t> { 0u }));
@ -286,30 +286,30 @@ TEST_CASE(find_with_empty_needle)
TEST_CASE(bijective_base)
{
EXPECT_EQ(String::bijective_base_from(0), "A");
EXPECT_EQ(String::bijective_base_from(25), "Z");
EXPECT_EQ(String::bijective_base_from(26), "AA");
EXPECT_EQ(String::bijective_base_from(52), "BA");
EXPECT_EQ(String::bijective_base_from(704), "ABC");
EXPECT_EQ(DeprecatedString::bijective_base_from(0), "A");
EXPECT_EQ(DeprecatedString::bijective_base_from(25), "Z");
EXPECT_EQ(DeprecatedString::bijective_base_from(26), "AA");
EXPECT_EQ(DeprecatedString::bijective_base_from(52), "BA");
EXPECT_EQ(DeprecatedString::bijective_base_from(704), "ABC");
}
TEST_CASE(roman_numerals)
{
auto zero = String::roman_number_from(0);
auto zero = DeprecatedString::roman_number_from(0);
EXPECT_EQ(zero, "");
auto one = String::roman_number_from(1);
auto one = DeprecatedString::roman_number_from(1);
EXPECT_EQ(one, "I");
auto nine = String::roman_number_from(9);
auto nine = DeprecatedString::roman_number_from(9);
EXPECT_EQ(nine, "IX");
auto fourty_eight = String::roman_number_from(48);
auto fourty_eight = DeprecatedString::roman_number_from(48);
EXPECT_EQ(fourty_eight, "XLVIII");
auto one_thousand_nine_hundred_ninety_eight = String::roman_number_from(1998);
auto one_thousand_nine_hundred_ninety_eight = DeprecatedString::roman_number_from(1998);
EXPECT_EQ(one_thousand_nine_hundred_ninety_eight, "MCMXCVIII");
auto four_thousand = String::roman_number_from(4000);
auto four_thousand = DeprecatedString::roman_number_from(4000);
EXPECT_EQ(four_thousand, "4000");
}

View File

@ -6,9 +6,9 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/DisjointChunks.h>
#include <AK/FixedArray.h>
#include <AK/String.h>
#include <AK/Vector.h>
TEST_CASE(basic)

View File

@ -145,9 +145,9 @@ TEST_CASE(cast)
TEST_CASE(formatter)
{
EXPECT_EQ(String::formatted("{}", FixedPoint<16>(123.456)), "123.455993"sv);
EXPECT_EQ(String::formatted("{}", FixedPoint<16>(-123.456)), "-123.455994"sv);
EXPECT_EQ(String::formatted("{}", FixedPoint<4>(123.456)), "123.4375"sv);
EXPECT_EQ(String::formatted("{}", FixedPoint<4>(-123.456)), "-123.4375"sv);
EXPECT_EQ(String::formatted("{}", FixedPoint<16> {}), "0"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(123.456)), "123.455993"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-123.456)), "-123.455994"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<4>(123.456)), "123.4375"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<4>(-123.456)), "-123.4375"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16> {}), "0"sv);
}

View File

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/String.h>
#include <AK/DeprecatedString.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <math.h>
@ -20,42 +20,42 @@ TEST_CASE(is_integral_works_properly)
TEST_CASE(format_string_literals)
{
EXPECT_EQ(String::formatted("prefix-{}-suffix", "abc"), "prefix-abc-suffix");
EXPECT_EQ(String::formatted("{}{}{}", "a", "b", "c"), "abc");
EXPECT_EQ(DeprecatedString::formatted("prefix-{}-suffix", "abc"), "prefix-abc-suffix");
EXPECT_EQ(DeprecatedString::formatted("{}{}{}", "a", "b", "c"), "abc");
}
TEST_CASE(format_integers)
{
EXPECT_EQ(String::formatted("{}", 42u), "42");
EXPECT_EQ(String::formatted("{:4}", 42u), " 42");
EXPECT_EQ(String::formatted("{:08}", 42u), "00000042");
EXPECT_EQ(String::formatted("{:7}", -17), " -17");
EXPECT_EQ(String::formatted("{}", -17), "-17");
EXPECT_EQ(String::formatted("{:04}", 13), "0013");
EXPECT_EQ(String::formatted("{:08x}", 4096), "00001000");
EXPECT_EQ(String::formatted("{:x}", 0x1111222233334444ull), "1111222233334444");
EXPECT_EQ(String::formatted("{:4}", 12345678), "12345678");
EXPECT_EQ(DeprecatedString::formatted("{}", 42u), "42");
EXPECT_EQ(DeprecatedString::formatted("{:4}", 42u), " 42");
EXPECT_EQ(DeprecatedString::formatted("{:08}", 42u), "00000042");
EXPECT_EQ(DeprecatedString::formatted("{:7}", -17), " -17");
EXPECT_EQ(DeprecatedString::formatted("{}", -17), "-17");
EXPECT_EQ(DeprecatedString::formatted("{:04}", 13), "0013");
EXPECT_EQ(DeprecatedString::formatted("{:08x}", 4096), "00001000");
EXPECT_EQ(DeprecatedString::formatted("{:x}", 0x1111222233334444ull), "1111222233334444");
EXPECT_EQ(DeprecatedString::formatted("{:4}", 12345678), "12345678");
}
TEST_CASE(reorder_format_arguments)
{
EXPECT_EQ(String::formatted("{1}{0}", "a", "b"), "ba");
EXPECT_EQ(String::formatted("{0}{1}", "a", "b"), "ab");
EXPECT_EQ(DeprecatedString::formatted("{1}{0}", "a", "b"), "ba");
EXPECT_EQ(DeprecatedString::formatted("{0}{1}", "a", "b"), "ab");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(String::formatted("{0}{0}{0}"sv, "a", "b"), "aaa");
EXPECT_EQ(DeprecatedString::formatted("{0}{0}{0}"sv, "a", "b"), "aaa");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(String::formatted("{1}{}{0}"sv, "a", "b", "c"), "baa");
EXPECT_EQ(DeprecatedString::formatted("{1}{}{0}"sv, "a", "b", "c"), "baa");
}
TEST_CASE(escape_braces)
{
EXPECT_EQ(String::formatted("{{{}", "foo"), "{foo");
EXPECT_EQ(String::formatted("{}}}", "bar"), "bar}");
EXPECT_EQ(DeprecatedString::formatted("{{{}", "foo"), "{foo");
EXPECT_EQ(DeprecatedString::formatted("{}}}", "bar"), "bar}");
}
TEST_CASE(everything)
{
EXPECT_EQ(String::formatted("{{{:04}/{}/{0:8}/{1}", 42u, "foo"), "{0042/foo/ 42/foo");
EXPECT_EQ(DeprecatedString::formatted("{{{:04}/{}/{0:8}/{1}", 42u, "foo"), "{0042/foo/ 42/foo");
}
TEST_CASE(string_builder)
@ -69,85 +69,85 @@ TEST_CASE(string_builder)
TEST_CASE(format_without_arguments)
{
EXPECT_EQ(String::formatted("foo"), "foo");
EXPECT_EQ(DeprecatedString::formatted("foo"), "foo");
}
TEST_CASE(format_upper_case_integer)
{
EXPECT_EQ(String::formatted("{:4X}", 0xff), " FF");
EXPECT_EQ(String::formatted("{:#4X}", 0xff), "0XFF");
EXPECT_EQ(DeprecatedString::formatted("{:4X}", 0xff), " FF");
EXPECT_EQ(DeprecatedString::formatted("{:#4X}", 0xff), "0XFF");
EXPECT_EQ(String::formatted("{:b}", 0xff), "11111111");
EXPECT_EQ(String::formatted("{:B}", 0xff), "11111111");
EXPECT_EQ(String::formatted("{:#b}", 0xff), "0b11111111");
EXPECT_EQ(DeprecatedString::formatted("{:b}", 0xff), "11111111");
EXPECT_EQ(DeprecatedString::formatted("{:B}", 0xff), "11111111");
EXPECT_EQ(DeprecatedString::formatted("{:#b}", 0xff), "0b11111111");
}
TEST_CASE(format_aligned)
{
EXPECT_EQ(String::formatted("{:*<8}", 13), "13******");
EXPECT_EQ(String::formatted("{:*^8}", 13), "***13***");
EXPECT_EQ(String::formatted("{:*>8}", 13), "******13");
EXPECT_EQ(String::formatted("{:*>+8}", 13), "*****+13");
EXPECT_EQ(String::formatted("{:*^ 8}", 13), "** 13***");
EXPECT_EQ(DeprecatedString::formatted("{:*<8}", 13), "13******");
EXPECT_EQ(DeprecatedString::formatted("{:*^8}", 13), "***13***");
EXPECT_EQ(DeprecatedString::formatted("{:*>8}", 13), "******13");
EXPECT_EQ(DeprecatedString::formatted("{:*>+8}", 13), "*****+13");
EXPECT_EQ(DeprecatedString::formatted("{:*^ 8}", 13), "** 13***");
}
TEST_CASE(format_octal)
{
EXPECT_EQ(String::formatted("{:o}", 0744), "744");
EXPECT_EQ(String::formatted("{:#o}", 0744), "0744");
EXPECT_EQ(DeprecatedString::formatted("{:o}", 0744), "744");
EXPECT_EQ(DeprecatedString::formatted("{:#o}", 0744), "0744");
}
TEST_CASE(zero_pad)
{
EXPECT_EQ(String::formatted("{: <010}", 42), "42 ");
EXPECT_EQ(String::formatted("{:010}", 42), "0000000042");
EXPECT_EQ(String::formatted("{:/^010}", 42), "////42////");
EXPECT_EQ(String::formatted("{:04x}", -32), "-0020");
EXPECT_EQ(String::formatted("{:#06x}", -64), "-0x000040");
EXPECT_EQ(DeprecatedString::formatted("{: <010}", 42), "42 ");
EXPECT_EQ(DeprecatedString::formatted("{:010}", 42), "0000000042");
EXPECT_EQ(DeprecatedString::formatted("{:/^010}", 42), "////42////");
EXPECT_EQ(DeprecatedString::formatted("{:04x}", -32), "-0020");
EXPECT_EQ(DeprecatedString::formatted("{:#06x}", -64), "-0x000040");
}
TEST_CASE(replacement_field)
{
EXPECT_EQ(String::formatted("{:*>{1}}", 13, static_cast<size_t>(10)), "********13");
EXPECT_EQ(String::formatted("{:*<{1}}", 7, 4), "7***");
EXPECT_EQ(DeprecatedString::formatted("{:*>{1}}", 13, static_cast<size_t>(10)), "********13");
EXPECT_EQ(DeprecatedString::formatted("{:*<{1}}", 7, 4), "7***");
// Compiletime check bypass: intentionally ignoring extra arguments
EXPECT_EQ(String::formatted("{:{2}}"sv, -5, 8, 16), " -5");
EXPECT_EQ(String::formatted("{{{:*^{1}}}}", 1, 3), "{*1*}");
EXPECT_EQ(String::formatted("{:0{}}", 1, 3), "001");
EXPECT_EQ(DeprecatedString::formatted("{:{2}}"sv, -5, 8, 16), " -5");
EXPECT_EQ(DeprecatedString::formatted("{{{:*^{1}}}}", 1, 3), "{*1*}");
EXPECT_EQ(DeprecatedString::formatted("{:0{}}", 1, 3), "001");
}
TEST_CASE(replacement_field_regression)
{
// FIXME: Compiletime check bypass: cannot parse '}}' correctly.
EXPECT_EQ(String::formatted("{:{}}"sv, "", static_cast<unsigned long>(6)), " ");
EXPECT_EQ(DeprecatedString::formatted("{:{}}"sv, "", static_cast<unsigned long>(6)), " ");
}
TEST_CASE(complex_string_specifiers)
{
EXPECT_EQ(String::formatted("{:.8}", "123456789"), "12345678");
EXPECT_EQ(String::formatted("{:9}", "abcd"), "abcd ");
EXPECT_EQ(String::formatted("{:>9}", "abcd"), " abcd");
EXPECT_EQ(String::formatted("{:^9}", "abcd"), " abcd ");
EXPECT_EQ(String::formatted("{:4.6}", "a"), "a ");
EXPECT_EQ(String::formatted("{:4.6}", "abcdef"), "abcdef");
EXPECT_EQ(String::formatted("{:4.6}", "abcdefghi"), "abcdef");
EXPECT_EQ(DeprecatedString::formatted("{:.8}", "123456789"), "12345678");
EXPECT_EQ(DeprecatedString::formatted("{:9}", "abcd"), "abcd ");
EXPECT_EQ(DeprecatedString::formatted("{:>9}", "abcd"), " abcd");
EXPECT_EQ(DeprecatedString::formatted("{:^9}", "abcd"), " abcd ");
EXPECT_EQ(DeprecatedString::formatted("{:4.6}", "a"), "a ");
EXPECT_EQ(DeprecatedString::formatted("{:4.6}", "abcdef"), "abcdef");
EXPECT_EQ(DeprecatedString::formatted("{:4.6}", "abcdefghi"), "abcdef");
}
TEST_CASE(cast_integer_to_character)
{
EXPECT_EQ(String::formatted("{:c}", static_cast<int>('a')), "a");
EXPECT_EQ(String::formatted("{:c}", static_cast<unsigned int>('f')), "f");
EXPECT_EQ(DeprecatedString::formatted("{:c}", static_cast<int>('a')), "a");
EXPECT_EQ(DeprecatedString::formatted("{:c}", static_cast<unsigned int>('f')), "f");
}
TEST_CASE(boolean_values)
{
EXPECT_EQ(String::formatted("{}", true), "true");
EXPECT_EQ(String::formatted("{}", false), "false");
EXPECT_EQ(String::formatted("{:6}", true), "true ");
EXPECT_EQ(String::formatted("{:>4}", false), "false");
EXPECT_EQ(String::formatted("{:d}", false), "0");
EXPECT_EQ(String::formatted("{:d}", true), "1");
EXPECT_EQ(String::formatted("{:#08x}", true), "0x00000001");
EXPECT_EQ(DeprecatedString::formatted("{}", true), "true");
EXPECT_EQ(DeprecatedString::formatted("{}", false), "false");
EXPECT_EQ(DeprecatedString::formatted("{:6}", true), "true ");
EXPECT_EQ(DeprecatedString::formatted("{:>4}", false), "false");
EXPECT_EQ(DeprecatedString::formatted("{:d}", false), "0");
EXPECT_EQ(DeprecatedString::formatted("{:d}", true), "1");
EXPECT_EQ(DeprecatedString::formatted("{:#08x}", true), "0x00000001");
}
TEST_CASE(pointers)
@ -155,13 +155,13 @@ TEST_CASE(pointers)
void* ptr = reinterpret_cast<void*>(0x4000);
if (sizeof(void*) == 4) {
EXPECT_EQ(String::formatted("{:p}", 32), "0x00000020");
EXPECT_EQ(String::formatted("{:p}", ptr), "0x00004000");
EXPECT_EQ(String::formatted("{}", ptr), "0x00004000");
EXPECT_EQ(DeprecatedString::formatted("{:p}", 32), "0x00000020");
EXPECT_EQ(DeprecatedString::formatted("{:p}", ptr), "0x00004000");
EXPECT_EQ(DeprecatedString::formatted("{}", ptr), "0x00004000");
} else if (sizeof(void*) == 8) {
EXPECT_EQ(String::formatted("{:p}", 32), "0x0000000000000020");
EXPECT_EQ(String::formatted("{:p}", ptr), "0x0000000000004000");
EXPECT_EQ(String::formatted("{}", ptr), "0x0000000000004000");
EXPECT_EQ(DeprecatedString::formatted("{:p}", 32), "0x0000000000000020");
EXPECT_EQ(DeprecatedString::formatted("{:p}", ptr), "0x0000000000004000");
EXPECT_EQ(DeprecatedString::formatted("{}", ptr), "0x0000000000004000");
} else {
VERIFY_NOT_REACHED();
}
@ -173,12 +173,12 @@ TEST_CASE(pointers)
// This is a bit scary, thus this test. At least this test should fail in this case.
TEST_CASE(ensure_that_format_works)
{
if (String::formatted("FAIL") != "FAIL") {
if (DeprecatedString::formatted("FAIL") != "FAIL") {
fprintf(stderr, "FAIL\n");
exit(1);
}
if (String::formatted("{} FAIL {}", 1, 2) != "1 FAIL 2") {
if (DeprecatedString::formatted("{} FAIL {}", 1, 2) != "1 FAIL 2") {
fprintf(stderr, "FAIL\n");
exit(1);
}
@ -187,13 +187,13 @@ TEST_CASE(ensure_that_format_works)
TEST_CASE(format_string_literal_as_pointer)
{
char const* literal = "abc";
EXPECT_EQ(String::formatted("{:p}", literal), String::formatted("{:p}", reinterpret_cast<FlatPtr>(literal)));
EXPECT_EQ(DeprecatedString::formatted("{:p}", literal), DeprecatedString::formatted("{:p}", reinterpret_cast<FlatPtr>(literal)));
}
TEST_CASE(format_character)
{
char a = 'a';
EXPECT_EQ(String::formatted("{}", true ? a : 'b'), "a");
EXPECT_EQ(DeprecatedString::formatted("{}", true ? a : 'b'), "a");
}
struct A {
@ -210,8 +210,8 @@ struct AK::Formatter<B> : Formatter<StringView> {
TEST_CASE(format_if_supported)
{
EXPECT_EQ(String::formatted("{}", FormatIfSupported { A {} }), "?");
EXPECT_EQ(String::formatted("{}", FormatIfSupported { B {} }), "B");
EXPECT_EQ(DeprecatedString::formatted("{}", FormatIfSupported { A {} }), "?");
EXPECT_EQ(DeprecatedString::formatted("{}", FormatIfSupported { B {} }), "B");
}
TEST_CASE(file_descriptor)
@ -239,46 +239,46 @@ TEST_CASE(file_descriptor)
TEST_CASE(floating_point_numbers)
{
EXPECT_EQ(String::formatted("{}", 1.12), "1.12");
EXPECT_EQ(String::formatted("{}", 1.), "1");
EXPECT_EQ(String::formatted("{:.3}", 1.12), "1.12");
EXPECT_EQ(String::formatted("{:.1}", 1.12), "1.1");
EXPECT_EQ(String::formatted("{}", -1.12), "-1.12");
EXPECT_EQ(DeprecatedString::formatted("{}", 1.12), "1.12");
EXPECT_EQ(DeprecatedString::formatted("{}", 1.), "1");
EXPECT_EQ(DeprecatedString::formatted("{:.3}", 1.12), "1.12");
EXPECT_EQ(DeprecatedString::formatted("{:.1}", 1.12), "1.1");
EXPECT_EQ(DeprecatedString::formatted("{}", -1.12), "-1.12");
EXPECT_EQ(String::formatted("{}", NAN), "nan");
EXPECT_EQ(String::formatted("{}", INFINITY), "inf");
EXPECT_EQ(String::formatted("{}", -INFINITY), "-inf");
EXPECT_EQ(DeprecatedString::formatted("{}", NAN), "nan");
EXPECT_EQ(DeprecatedString::formatted("{}", INFINITY), "inf");
EXPECT_EQ(DeprecatedString::formatted("{}", -INFINITY), "-inf");
// FIXME: There is always the question what we mean with the width field. Do we mean significant digits?
// Do we mean the whole width? This is what was the simplest to implement:
EXPECT_EQ(String::formatted("{:x>5.1}", 1.12), "xx1.1");
EXPECT_EQ(DeprecatedString::formatted("{:x>5.1}", 1.12), "xx1.1");
}
TEST_CASE(no_precision_no_trailing_number)
{
EXPECT_EQ(String::formatted("{:.0}", 0.1), "0");
EXPECT_EQ(DeprecatedString::formatted("{:.0}", 0.1), "0");
}
TEST_CASE(yay_this_implementation_sucks)
{
EXPECT_EQ(String::formatted("{:.0}", .99999999999), "0");
EXPECT_EQ(DeprecatedString::formatted("{:.0}", .99999999999), "0");
}
TEST_CASE(precision_with_trailing_zeros)
{
EXPECT_EQ(String::formatted("{:0.3}", 1.12), "1.120");
EXPECT_EQ(String::formatted("{:0.1}", 1.12), "1.1");
EXPECT_EQ(DeprecatedString::formatted("{:0.3}", 1.12), "1.120");
EXPECT_EQ(DeprecatedString::formatted("{:0.1}", 1.12), "1.1");
}
TEST_CASE(magnitude_less_than_zero)
{
EXPECT_EQ(String::formatted("{}", -0.654), "-0.654");
EXPECT_EQ(String::formatted("{}", 0.654), "0.654");
EXPECT_EQ(DeprecatedString::formatted("{}", -0.654), "-0.654");
EXPECT_EQ(DeprecatedString::formatted("{}", 0.654), "0.654");
}
TEST_CASE(format_nullptr)
{
EXPECT_EQ(String::formatted("{}", nullptr), String::formatted("{:p}", static_cast<FlatPtr>(0)));
EXPECT_EQ(DeprecatedString::formatted("{}", nullptr), DeprecatedString::formatted("{:p}", static_cast<FlatPtr>(0)));
}
struct C {
@ -294,12 +294,12 @@ struct AK::Formatter<C> : AK::Formatter<FormatString> {
TEST_CASE(use_format_string_formatter)
{
EXPECT_EQ(String::formatted("{:*<10}", C { 42 }), "C(i=42)***");
EXPECT_EQ(DeprecatedString::formatted("{:*<10}", C { 42 }), "C(i=42)***");
}
TEST_CASE(long_long_regression)
{
EXPECT_EQ(String::formatted("{}", 0x0123456789abcdefLL), "81985529216486895");
EXPECT_EQ(DeprecatedString::formatted("{}", 0x0123456789abcdefLL), "81985529216486895");
StringBuilder builder;
AK::FormatBuilder fmtbuilder { builder };
@ -310,38 +310,38 @@ TEST_CASE(long_long_regression)
TEST_CASE(hex_dump)
{
EXPECT_EQ(String::formatted("{:hex-dump}", "0000"), "30303030");
EXPECT_EQ(String::formatted("{:>4hex-dump}", "0000"), "30303030 0000");
EXPECT_EQ(String::formatted("{:>2hex-dump}", "0000"), "3030 00\n3030 00");
EXPECT_EQ(String::formatted("{:*>4hex-dump}", "0000"), "30303030****0000");
EXPECT_EQ(DeprecatedString::formatted("{:hex-dump}", "0000"), "30303030");
EXPECT_EQ(DeprecatedString::formatted("{:>4hex-dump}", "0000"), "30303030 0000");
EXPECT_EQ(DeprecatedString::formatted("{:>2hex-dump}", "0000"), "3030 00\n3030 00");
EXPECT_EQ(DeprecatedString::formatted("{:*>4hex-dump}", "0000"), "30303030****0000");
}
TEST_CASE(vector_format)
{
{
Vector<int> v { 1, 2, 3, 4 };
EXPECT_EQ(String::formatted("{}", v), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(DeprecatedString::formatted("{}", v), "[ 1, 2, 3, 4 ]");
}
{
Vector<StringView> v { "1"sv, "2"sv, "3"sv, "4"sv };
EXPECT_EQ(String::formatted("{}", v), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(DeprecatedString::formatted("{}", v), "[ 1, 2, 3, 4 ]");
}
{
Vector<Vector<String>> v { { "1"sv, "2"sv }, { "3"sv, "4"sv } };
EXPECT_EQ(String::formatted("{}", v), "[ [ 1, 2 ], [ 3, 4 ] ]");
Vector<Vector<DeprecatedString>> v { { "1"sv, "2"sv }, { "3"sv, "4"sv } };
EXPECT_EQ(DeprecatedString::formatted("{}", v), "[ [ 1, 2 ], [ 3, 4 ] ]");
}
}
TEST_CASE(format_wchar)
{
EXPECT_EQ(String::formatted("{}", L'a'), "a");
EXPECT_EQ(String::formatted("{}", L'\U0001F41E'), "\xF0\x9F\x90\x9E");
EXPECT_EQ(String::formatted("{:x}", L'a'), "61");
EXPECT_EQ(String::formatted("{:x}", L'\U0001F41E'), "1f41e");
EXPECT_EQ(String::formatted("{:d}", L'a'), "97");
EXPECT_EQ(String::formatted("{:d}", L'\U0001F41E'), "128030");
EXPECT_EQ(DeprecatedString::formatted("{}", L'a'), "a");
EXPECT_EQ(DeprecatedString::formatted("{}", L'\U0001F41E'), "\xF0\x9F\x90\x9E");
EXPECT_EQ(DeprecatedString::formatted("{:x}", L'a'), "61");
EXPECT_EQ(DeprecatedString::formatted("{:x}", L'\U0001F41E'), "1f41e");
EXPECT_EQ(DeprecatedString::formatted("{:d}", L'a'), "97");
EXPECT_EQ(DeprecatedString::formatted("{:d}", L'\U0001F41E'), "128030");
EXPECT_EQ(String::formatted("{:6}", L'a'), "a ");
EXPECT_EQ(String::formatted("{:6d}", L'a'), " 97");
EXPECT_EQ(String::formatted("{:#x}", L'\U0001F41E'), "0x1f41e");
EXPECT_EQ(DeprecatedString::formatted("{:6}", L'a'), "a ");
EXPECT_EQ(DeprecatedString::formatted("{:6d}", L'a'), " 97");
EXPECT_EQ(DeprecatedString::formatted("{:#x}", L'\U0001F41E'), "0x1f41e");
}

View File

@ -6,9 +6,9 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>
TEST_CASE(construct)
{
@ -19,7 +19,7 @@ TEST_CASE(construct)
TEST_CASE(construct_from_initializer_list)
{
HashMap<int, String> number_to_string {
HashMap<int, DeprecatedString> number_to_string {
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
@ -30,7 +30,7 @@ TEST_CASE(construct_from_initializer_list)
TEST_CASE(populate)
{
HashMap<int, String> number_to_string;
HashMap<int, DeprecatedString> number_to_string;
number_to_string.set(1, "One");
number_to_string.set(2, "Two");
number_to_string.set(3, "Three");
@ -41,7 +41,7 @@ TEST_CASE(populate)
TEST_CASE(range_loop)
{
HashMap<int, String> number_to_string;
HashMap<int, DeprecatedString> number_to_string;
EXPECT_EQ(number_to_string.set(1, "One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(2, "Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(3, "Three"), AK::HashSetResult::InsertedNewEntry);
@ -56,7 +56,7 @@ TEST_CASE(range_loop)
TEST_CASE(map_remove)
{
HashMap<int, String> number_to_string;
HashMap<int, DeprecatedString> number_to_string;
EXPECT_EQ(number_to_string.set(1, "One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(2, "Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(3, "Three"), AK::HashSetResult::InsertedNewEntry);
@ -73,7 +73,7 @@ TEST_CASE(map_remove)
TEST_CASE(remove_all_matching)
{
HashMap<int, String> map;
HashMap<int, DeprecatedString> map;
map.set(1, "One");
map.set(2, "Two");
@ -82,27 +82,27 @@ TEST_CASE(remove_all_matching)
EXPECT_EQ(map.size(), 4u);
EXPECT_EQ(map.remove_all_matching([&](int key, String const& value) { return key == 1 || value == "Two"; }), true);
EXPECT_EQ(map.remove_all_matching([&](int key, DeprecatedString const& value) { return key == 1 || value == "Two"; }), true);
EXPECT_EQ(map.size(), 2u);
EXPECT_EQ(map.remove_all_matching([&](int, String const&) { return false; }), false);
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return false; }), false);
EXPECT_EQ(map.size(), 2u);
EXPECT(map.contains(3));
EXPECT(map.contains(4));
EXPECT_EQ(map.remove_all_matching([&](int, String const&) { return true; }), true);
EXPECT_EQ(map.remove_all_matching([&](int, String const&) { return false; }), false);
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return true; }), true);
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return false; }), false);
EXPECT(map.is_empty());
EXPECT_EQ(map.remove_all_matching([&](int, String const&) { return true; }), false);
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return true; }), false);
}
TEST_CASE(case_insensitive)
{
HashMap<String, int, CaseInsensitiveStringTraits> casemap;
EXPECT_EQ(String("nickserv").to_lowercase(), String("NickServ").to_lowercase());
HashMap<DeprecatedString, int, CaseInsensitiveStringTraits> casemap;
EXPECT_EQ(DeprecatedString("nickserv").to_lowercase(), DeprecatedString("NickServ").to_lowercase());
EXPECT_EQ(casemap.set("nickserv", 3), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(casemap.set("NickServ", 3), AK::HashSetResult::ReplacedExistingEntry);
EXPECT_EQ(casemap.size(), 1u);
@ -111,11 +111,11 @@ TEST_CASE(case_insensitive)
TEST_CASE(hashmap_of_nonnullownptr_get)
{
struct Object {
Object(String const& s)
Object(DeprecatedString const& s)
: string(s)
{
}
String string;
DeprecatedString string;
};
HashMap<int, NonnullOwnPtr<Object>> objects;
@ -142,16 +142,16 @@ TEST_CASE(hashmap_of_nonnullownptr_get)
TEST_CASE(many_strings)
{
HashMap<String, int> strings;
HashMap<DeprecatedString, int> strings;
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.set(String::number(i), i), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set(DeprecatedString::number(i), i), AK::HashSetResult::InsertedNewEntry);
}
EXPECT_EQ(strings.size(), 999u);
for (auto& it : strings) {
EXPECT_EQ(it.key.to_int().value(), it.value);
}
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.remove(String::number(i)), true);
EXPECT_EQ(strings.remove(DeprecatedString::number(i)), true);
}
EXPECT_EQ(strings.is_empty(), true);
}
@ -204,7 +204,7 @@ TEST_CASE(basic_contains)
TEST_CASE(in_place_rehashing_ordered_loop_bug)
{
OrderedHashMap<String, String> map;
OrderedHashMap<DeprecatedString, DeprecatedString> map;
map.set("yt.innertube::nextId", "");
map.set("yt.innertube::requests", "");
map.remove("yt.innertube::nextId");

View File

@ -6,9 +6,9 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/HashTable.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/String.h>
TEST_CASE(construct)
{
@ -44,7 +44,7 @@ TEST_CASE(move_is_not_swap)
TEST_CASE(populate)
{
HashTable<String> strings;
HashTable<DeprecatedString> strings;
strings.set("One");
strings.set("Two");
strings.set("Three");
@ -55,7 +55,7 @@ TEST_CASE(populate)
TEST_CASE(range_loop)
{
HashTable<String> strings;
HashTable<DeprecatedString> strings;
EXPECT_EQ(strings.set("One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Three"), AK::HashSetResult::InsertedNewEntry);
@ -70,7 +70,7 @@ TEST_CASE(range_loop)
TEST_CASE(table_remove)
{
HashTable<String> strings;
HashTable<DeprecatedString> strings;
EXPECT_EQ(strings.set("One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Three"), AK::HashSetResult::InsertedNewEntry);
@ -113,8 +113,8 @@ TEST_CASE(remove_all_matching)
TEST_CASE(case_insensitive)
{
HashTable<String, CaseInsensitiveStringTraits> casetable;
EXPECT_EQ(String("nickserv").to_lowercase(), String("NickServ").to_lowercase());
HashTable<DeprecatedString, CaseInsensitiveStringTraits> casetable;
EXPECT_EQ(DeprecatedString("nickserv").to_lowercase(), DeprecatedString("NickServ").to_lowercase());
EXPECT_EQ(casetable.set("nickserv"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(casetable.set("NickServ"), AK::HashSetResult::ReplacedExistingEntry);
EXPECT_EQ(casetable.size(), 1u);
@ -122,33 +122,33 @@ TEST_CASE(case_insensitive)
TEST_CASE(many_strings)
{
HashTable<String> strings;
HashTable<DeprecatedString> strings;
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.set(String::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
}
EXPECT_EQ(strings.size(), 999u);
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.remove(String::number(i)), true);
EXPECT_EQ(strings.remove(DeprecatedString::number(i)), true);
}
EXPECT_EQ(strings.is_empty(), true);
}
TEST_CASE(many_collisions)
{
struct StringCollisionTraits : public GenericTraits<String> {
static unsigned hash(String const&) { return 0; }
struct StringCollisionTraits : public GenericTraits<DeprecatedString> {
static unsigned hash(DeprecatedString const&) { return 0; }
};
HashTable<String, StringCollisionTraits> strings;
HashTable<DeprecatedString, StringCollisionTraits> strings;
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.set(String::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
}
EXPECT_EQ(strings.set("foo"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.size(), 1000u);
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.remove(String::number(i)), true);
EXPECT_EQ(strings.remove(DeprecatedString::number(i)), true);
}
// FIXME: Doing this with an "EXPECT_NOT_EQ" would be cleaner.
@ -157,24 +157,24 @@ TEST_CASE(many_collisions)
TEST_CASE(space_reuse)
{
struct StringCollisionTraits : public GenericTraits<String> {
static unsigned hash(String const&) { return 0; }
struct StringCollisionTraits : public GenericTraits<DeprecatedString> {
static unsigned hash(DeprecatedString const&) { return 0; }
};
HashTable<String, StringCollisionTraits> strings;
HashTable<DeprecatedString, StringCollisionTraits> strings;
// Add a few items to allow it to do initial resizing.
EXPECT_EQ(strings.set("0"), AK::HashSetResult::InsertedNewEntry);
for (int i = 1; i < 5; ++i) {
EXPECT_EQ(strings.set(String::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(String::number(i - 1)), true);
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(DeprecatedString::number(i - 1)), true);
}
auto capacity = strings.capacity();
for (int i = 5; i < 999; ++i) {
EXPECT_EQ(strings.set(String::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(String::number(i - 1)), true);
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(DeprecatedString::number(i - 1)), true);
}
EXPECT_EQ(strings.capacity(), capacity);
@ -300,7 +300,7 @@ BENCHMARK_CASE(benchmark_thrashing)
TEST_CASE(reinsertion)
{
OrderedHashTable<String> map;
OrderedHashTable<DeprecatedString> map;
map.set("ytidb::LAST_RESULT_ENTRY_KEY");
map.set("__sak");
map.remove("__sak");

View File

@ -6,15 +6,15 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
TEST_CASE(load_form)
{
String raw_form_json = R"(
DeprecatedString raw_form_json = R"(
{
"name": "Form1",
"widgets": [
@ -294,7 +294,7 @@ private:
TEST_CASE(fallible_json_object_for_each)
{
String raw_json = R"(
DeprecatedString raw_json = R"(
{
"name": "anon",
"home": "/home/anon",
@ -334,7 +334,7 @@ TEST_CASE(fallible_json_object_for_each)
TEST_CASE(fallible_json_array_for_each)
{
String raw_json = R"(
DeprecatedString raw_json = R"(
[
"anon",
"/home/anon",

View File

@ -7,8 +7,8 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/String.h>
TEST_CASE(relative_path)
{

View File

@ -6,9 +6,9 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/MemMem.h>
#include <AK/Memory.h>
#include <AK/String.h>
TEST_CASE(bitap)
{
@ -78,9 +78,9 @@ TEST_CASE(kmp_two_chunks)
TEST_CASE(timing_safe_compare)
{
String data_set = "abcdefghijklmnopqrstuvwxyz123456789";
DeprecatedString data_set = "abcdefghijklmnopqrstuvwxyz123456789";
EXPECT_EQ(true, AK::timing_safe_compare(data_set.characters(), data_set.characters(), data_set.length()));
String reversed = data_set.reverse();
DeprecatedString reversed = data_set.reverse();
EXPECT_EQ(false, AK::timing_safe_compare(data_set.characters(), reversed.characters(), reversed.length()));
}

View File

@ -6,8 +6,8 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/NonnullRefPtr.h>
#include <AK/String.h>
struct Object : public RefCounted<Object> {
int x;

View File

@ -7,8 +7,8 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Vector.h>
TEST_CASE(basic_optional)
@ -59,7 +59,7 @@ TEST_CASE(optional_rvalue_ref_qualified_getters)
TEST_CASE(optional_leak_1)
{
struct Structure {
Optional<String> str;
Optional<DeprecatedString> str;
};
// This used to leak, it does not anymore.
@ -81,7 +81,7 @@ TEST_CASE(comparison_without_values)
{
Optional<StringView> opt0;
Optional<StringView> opt1;
Optional<String> opt2;
Optional<DeprecatedString> opt2;
EXPECT_EQ(opt0, opt1);
EXPECT_EQ(opt0, opt2);
}
@ -90,7 +90,7 @@ TEST_CASE(comparison_with_values)
{
Optional<StringView> opt0;
Optional<StringView> opt1 = "foo"sv;
Optional<String> opt2 = "foo"sv;
Optional<DeprecatedString> opt2 = "foo"sv;
Optional<StringView> opt3 = "bar"sv;
EXPECT_NE(opt0, opt1);
EXPECT_EQ(opt1, opt2);
@ -99,14 +99,14 @@ TEST_CASE(comparison_with_values)
TEST_CASE(comparison_to_underlying_types)
{
Optional<String> opt0;
EXPECT_NE(opt0, String());
Optional<DeprecatedString> opt0;
EXPECT_NE(opt0, DeprecatedString());
EXPECT_NE(opt0, "foo");
Optional<StringView> opt1 = "foo"sv;
EXPECT_EQ(opt1, "foo");
EXPECT_NE(opt1, "bar");
EXPECT_EQ(opt1, String("foo"));
EXPECT_EQ(opt1, DeprecatedString("foo"));
}
TEST_CASE(comparison_with_numeric_types)
@ -262,7 +262,7 @@ TEST_CASE(comparison_reference)
StringView test = "foo"sv;
Optional<StringView&> opt0;
Optional<StringView const&> opt1 = test;
Optional<String> opt2 = "foo"sv;
Optional<DeprecatedString> opt2 = "foo"sv;
Optional<StringView> opt3 = "bar"sv;
EXPECT_NE(opt0, opt1);

View File

@ -6,8 +6,8 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/Queue.h>
#include <AK/String.h>
TEST_CASE(construct)
{
@ -32,7 +32,7 @@ TEST_CASE(populate_int)
TEST_CASE(populate_string)
{
Queue<String> strings;
Queue<DeprecatedString> strings;
strings.enqueue("ABC");
strings.enqueue("DEF");
EXPECT_EQ(strings.size(), 2u);
@ -43,11 +43,11 @@ TEST_CASE(populate_string)
TEST_CASE(order)
{
Queue<String> strings;
Queue<DeprecatedString> strings;
EXPECT(strings.is_empty());
for (size_t i = 0; i < 10000; ++i) {
strings.enqueue(String::number(i));
strings.enqueue(DeprecatedString::number(i));
EXPECT_EQ(strings.size(), i + 1);
}

Some files were not shown because too many files have changed in this diff Show More