mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte string. As the null state has already been removed, there are no other particularly hairy blockers in repurposing this type as a byte string (what it _really_ is). This commit is auto-generated: $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \ Meta Ports Ladybird Tests Kernel) $ perl -pie 's/\bDeprecatedString\b/ByteString/g; s/deprecated_string/byte_string/g' $xs $ clang-format --style=file -i \ $(git diff --name-only | grep \.cpp\|\.h) $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
parent
38d62563b3
commit
5e1499d104
Notes:
sideshowbarker
2024-07-16 23:38:54 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/5e1499d104 Pull-request: https://github.com/SerenityOS/serenity/pull/22325
1615 changed files with 10257 additions and 10257 deletions
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/DeprecatedFlyString.h>
|
#include <AK/DeprecatedFlyString.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
|
@ -16,17 +16,17 @@
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
bool DeprecatedString::operator==(DeprecatedFlyString const& fly_string) const
|
bool ByteString::operator==(DeprecatedFlyString const& fly_string) const
|
||||||
{
|
{
|
||||||
return m_impl == fly_string.impl() || view() == fly_string.view();
|
return m_impl == fly_string.impl() || view() == fly_string.view();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::operator==(DeprecatedString const& other) const
|
bool ByteString::operator==(ByteString const& other) const
|
||||||
{
|
{
|
||||||
return m_impl == other.impl() || view() == other.view();
|
return m_impl == other.impl() || view() == other.view();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::operator==(StringView other) const
|
bool ByteString::operator==(StringView other) const
|
||||||
{
|
{
|
||||||
if (other.is_null())
|
if (other.is_null())
|
||||||
return is_empty();
|
return is_empty();
|
||||||
|
@ -34,17 +34,17 @@ bool DeprecatedString::operator==(StringView other) const
|
||||||
return view() == other;
|
return view() == other;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::operator<(DeprecatedString const& other) const
|
bool ByteString::operator<(ByteString const& other) const
|
||||||
{
|
{
|
||||||
return view() < other.view();
|
return view() < other.view();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::operator>(DeprecatedString const& other) const
|
bool ByteString::operator>(ByteString const& other) const
|
||||||
{
|
{
|
||||||
return view() > other.view();
|
return view() > other.view();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
|
bool ByteString::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
|
||||||
{
|
{
|
||||||
// We must fit at least the NUL-terminator.
|
// We must fit at least the NUL-terminator.
|
||||||
VERIFY(buffer_size > 0);
|
VERIFY(buffer_size > 0);
|
||||||
|
@ -56,55 +56,55 @@ bool DeprecatedString::copy_characters_to_buffer(char* buffer, size_t buffer_siz
|
||||||
return characters_to_copy == length();
|
return characters_to_copy == length();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::isolated_copy() const
|
ByteString ByteString::isolated_copy() const
|
||||||
{
|
{
|
||||||
if (m_impl->length() == 0)
|
if (m_impl->length() == 0)
|
||||||
return empty();
|
return empty();
|
||||||
char* buffer;
|
char* buffer;
|
||||||
auto impl = StringImpl::create_uninitialized(length(), buffer);
|
auto impl = StringImpl::create_uninitialized(length(), buffer);
|
||||||
memcpy(buffer, m_impl->characters(), m_impl->length());
|
memcpy(buffer, m_impl->characters(), m_impl->length());
|
||||||
return DeprecatedString(move(*impl));
|
return ByteString(move(*impl));
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::substring(size_t start, size_t length) const
|
ByteString ByteString::substring(size_t start, size_t length) const
|
||||||
{
|
{
|
||||||
if (!length)
|
if (!length)
|
||||||
return DeprecatedString::empty();
|
return ByteString::empty();
|
||||||
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
|
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
|
||||||
VERIFY(start + length <= m_impl->length());
|
VERIFY(start + length <= m_impl->length());
|
||||||
return { characters() + start, length };
|
return { characters() + start, length };
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::substring(size_t start) const
|
ByteString ByteString::substring(size_t start) const
|
||||||
{
|
{
|
||||||
VERIFY(start <= length());
|
VERIFY(start <= length());
|
||||||
return { characters() + start, length() - start };
|
return { characters() + start, length() - start };
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView DeprecatedString::substring_view(size_t start, size_t length) const
|
StringView ByteString::substring_view(size_t start, size_t length) const
|
||||||
{
|
{
|
||||||
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
|
VERIFY(!Checked<size_t>::addition_would_overflow(start, length));
|
||||||
VERIFY(start + length <= m_impl->length());
|
VERIFY(start + length <= m_impl->length());
|
||||||
return { characters() + start, length };
|
return { characters() + start, length };
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView DeprecatedString::substring_view(size_t start) const
|
StringView ByteString::substring_view(size_t start) const
|
||||||
{
|
{
|
||||||
VERIFY(start <= length());
|
VERIFY(start <= length());
|
||||||
return { characters() + start, length() - start };
|
return { characters() + start, length() - start };
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<DeprecatedString> DeprecatedString::split(char separator, SplitBehavior split_behavior) const
|
Vector<ByteString> ByteString::split(char separator, SplitBehavior split_behavior) const
|
||||||
{
|
{
|
||||||
return split_limit(separator, 0, split_behavior);
|
return split_limit(separator, 0, split_behavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<DeprecatedString> DeprecatedString::split_limit(char separator, size_t limit, SplitBehavior split_behavior) const
|
Vector<ByteString> ByteString::split_limit(char separator, size_t limit, SplitBehavior split_behavior) const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
Vector<DeprecatedString> v;
|
Vector<ByteString> v;
|
||||||
size_t substart = 0;
|
size_t substart = 0;
|
||||||
bool keep_empty = has_flag(split_behavior, SplitBehavior::KeepEmpty);
|
bool keep_empty = has_flag(split_behavior, SplitBehavior::KeepEmpty);
|
||||||
bool keep_separator = has_flag(split_behavior, SplitBehavior::KeepTrailingSeparator);
|
bool keep_separator = has_flag(split_behavior, SplitBehavior::KeepTrailingSeparator);
|
||||||
|
@ -123,7 +123,7 @@ Vector<DeprecatedString> DeprecatedString::split_limit(char separator, size_t li
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<StringView> DeprecatedString::split_view(Function<bool(char)> separator, SplitBehavior split_behavior) const
|
Vector<StringView> ByteString::split_view(Function<bool(char)> separator, SplitBehavior split_behavior) const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return {};
|
return {};
|
||||||
|
@ -147,78 +147,78 @@ Vector<StringView> DeprecatedString::split_view(Function<bool(char)> separator,
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<StringView> DeprecatedString::split_view(char const separator, SplitBehavior split_behavior) const
|
Vector<StringView> ByteString::split_view(char const separator, SplitBehavior split_behavior) const
|
||||||
{
|
{
|
||||||
return split_view([separator](char ch) { return ch == separator; }, split_behavior);
|
return split_view([separator](char ch) { return ch == separator; }, split_behavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer DeprecatedString::to_byte_buffer() const
|
ByteBuffer ByteString::to_byte_buffer() const
|
||||||
{
|
{
|
||||||
// FIXME: Handle OOM failure.
|
// FIXME: Handle OOM failure.
|
||||||
return ByteBuffer::copy(bytes()).release_value_but_fixme_should_propagate_errors();
|
return ByteBuffer::copy(bytes()).release_value_but_fixme_should_propagate_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Optional<T> DeprecatedString::to_int(TrimWhitespace trim_whitespace) const
|
Optional<T> ByteString::to_int(TrimWhitespace trim_whitespace) const
|
||||||
{
|
{
|
||||||
return StringUtils::convert_to_int<T>(view(), trim_whitespace);
|
return StringUtils::convert_to_int<T>(view(), trim_whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
template Optional<i8> DeprecatedString::to_int(TrimWhitespace) const;
|
template Optional<i8> ByteString::to_int(TrimWhitespace) const;
|
||||||
template Optional<i16> DeprecatedString::to_int(TrimWhitespace) const;
|
template Optional<i16> ByteString::to_int(TrimWhitespace) const;
|
||||||
template Optional<i32> DeprecatedString::to_int(TrimWhitespace) const;
|
template Optional<i32> ByteString::to_int(TrimWhitespace) const;
|
||||||
template Optional<long> DeprecatedString::to_int(TrimWhitespace) const;
|
template Optional<long> ByteString::to_int(TrimWhitespace) const;
|
||||||
template Optional<long long> DeprecatedString::to_int(TrimWhitespace) const;
|
template Optional<long long> ByteString::to_int(TrimWhitespace) const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Optional<T> DeprecatedString::to_uint(TrimWhitespace trim_whitespace) const
|
Optional<T> ByteString::to_uint(TrimWhitespace trim_whitespace) const
|
||||||
{
|
{
|
||||||
return StringUtils::convert_to_uint<T>(view(), trim_whitespace);
|
return StringUtils::convert_to_uint<T>(view(), trim_whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
template Optional<u8> DeprecatedString::to_uint(TrimWhitespace) const;
|
template Optional<u8> ByteString::to_uint(TrimWhitespace) const;
|
||||||
template Optional<u16> DeprecatedString::to_uint(TrimWhitespace) const;
|
template Optional<u16> ByteString::to_uint(TrimWhitespace) const;
|
||||||
template Optional<u32> DeprecatedString::to_uint(TrimWhitespace) const;
|
template Optional<u32> ByteString::to_uint(TrimWhitespace) const;
|
||||||
template Optional<unsigned long> DeprecatedString::to_uint(TrimWhitespace) const;
|
template Optional<unsigned long> ByteString::to_uint(TrimWhitespace) const;
|
||||||
template Optional<unsigned long long> DeprecatedString::to_uint(TrimWhitespace) const;
|
template Optional<unsigned long long> ByteString::to_uint(TrimWhitespace) const;
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
Optional<double> DeprecatedString::to_double(TrimWhitespace trim_whitespace) const
|
Optional<double> ByteString::to_double(TrimWhitespace trim_whitespace) const
|
||||||
{
|
{
|
||||||
return StringUtils::convert_to_floating_point<double>(*this, trim_whitespace);
|
return StringUtils::convert_to_floating_point<double>(*this, trim_whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<float> DeprecatedString::to_float(TrimWhitespace trim_whitespace) const
|
Optional<float> ByteString::to_float(TrimWhitespace trim_whitespace) const
|
||||||
{
|
{
|
||||||
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
|
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool DeprecatedString::starts_with(StringView str, CaseSensitivity case_sensitivity) const
|
bool ByteString::starts_with(StringView str, CaseSensitivity case_sensitivity) const
|
||||||
{
|
{
|
||||||
return StringUtils::starts_with(*this, str, case_sensitivity);
|
return StringUtils::starts_with(*this, str, case_sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::starts_with(char ch) const
|
bool ByteString::starts_with(char ch) const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return false;
|
return false;
|
||||||
return characters()[0] == ch;
|
return characters()[0] == ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::ends_with(StringView str, CaseSensitivity case_sensitivity) const
|
bool ByteString::ends_with(StringView str, CaseSensitivity case_sensitivity) const
|
||||||
{
|
{
|
||||||
return StringUtils::ends_with(*this, str, case_sensitivity);
|
return StringUtils::ends_with(*this, str, case_sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::ends_with(char ch) const
|
bool ByteString::ends_with(char ch) const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return false;
|
return false;
|
||||||
return characters()[length() - 1] == ch;
|
return characters()[length() - 1] == ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::repeated(char ch, size_t count)
|
ByteString ByteString::repeated(char ch, size_t count)
|
||||||
{
|
{
|
||||||
if (!count)
|
if (!count)
|
||||||
return empty();
|
return empty();
|
||||||
|
@ -228,7 +228,7 @@ DeprecatedString DeprecatedString::repeated(char ch, size_t count)
|
||||||
return *impl;
|
return *impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::repeated(StringView string, size_t count)
|
ByteString ByteString::repeated(StringView string, size_t count)
|
||||||
{
|
{
|
||||||
if (!count || string.is_empty())
|
if (!count || string.is_empty())
|
||||||
return empty();
|
return empty();
|
||||||
|
@ -239,7 +239,7 @@ DeprecatedString DeprecatedString::repeated(StringView string, size_t count)
|
||||||
return *impl;
|
return *impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::bijective_base_from(size_t value, unsigned base, StringView map)
|
ByteString ByteString::bijective_base_from(size_t value, unsigned base, StringView map)
|
||||||
{
|
{
|
||||||
value++;
|
value++;
|
||||||
if (map.is_null())
|
if (map.is_null())
|
||||||
|
@ -265,13 +265,13 @@ DeprecatedString DeprecatedString::bijective_base_from(size_t value, unsigned ba
|
||||||
for (size_t j = 0; j < i / 2; ++j)
|
for (size_t j = 0; j < i / 2; ++j)
|
||||||
swap(buffer[j], buffer[i - j - 1]);
|
swap(buffer[j], buffer[i - j - 1]);
|
||||||
|
|
||||||
return DeprecatedString { ReadonlyBytes(buffer.data(), i) };
|
return ByteString { ReadonlyBytes(buffer.data(), i) };
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::roman_number_from(size_t value)
|
ByteString ByteString::roman_number_from(size_t value)
|
||||||
{
|
{
|
||||||
if (value > 3999)
|
if (value > 3999)
|
||||||
return DeprecatedString::number(value);
|
return ByteString::number(value);
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
|
@ -318,44 +318,44 @@ DeprecatedString DeprecatedString::roman_number_from(size_t value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
|
bool ByteString::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
|
||||||
{
|
{
|
||||||
return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans);
|
return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::matches(StringView mask, CaseSensitivity case_sensitivity) const
|
bool ByteString::matches(StringView mask, CaseSensitivity case_sensitivity) const
|
||||||
{
|
{
|
||||||
return StringUtils::matches(*this, mask, case_sensitivity);
|
return StringUtils::matches(*this, mask, case_sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::contains(StringView needle, CaseSensitivity case_sensitivity) const
|
bool ByteString::contains(StringView needle, CaseSensitivity case_sensitivity) const
|
||||||
{
|
{
|
||||||
return StringUtils::contains(*this, needle, case_sensitivity);
|
return StringUtils::contains(*this, needle, case_sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::contains(char needle, CaseSensitivity case_sensitivity) const
|
bool ByteString::contains(char needle, CaseSensitivity case_sensitivity) const
|
||||||
{
|
{
|
||||||
return StringUtils::contains(*this, StringView(&needle, 1), case_sensitivity);
|
return StringUtils::contains(*this, StringView(&needle, 1), case_sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::equals_ignoring_ascii_case(StringView other) const
|
bool ByteString::equals_ignoring_ascii_case(StringView other) const
|
||||||
{
|
{
|
||||||
return StringUtils::equals_ignoring_ascii_case(view(), other);
|
return StringUtils::equals_ignoring_ascii_case(view(), other);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::reverse() const
|
ByteString ByteString::reverse() const
|
||||||
{
|
{
|
||||||
StringBuilder reversed_string(length());
|
StringBuilder reversed_string(length());
|
||||||
for (size_t i = length(); i-- > 0;) {
|
for (size_t i = length(); i-- > 0;) {
|
||||||
reversed_string.append(characters()[i]);
|
reversed_string.append(characters()[i]);
|
||||||
}
|
}
|
||||||
return reversed_string.to_deprecated_string();
|
return reversed_string.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString escape_html_entities(StringView html)
|
ByteString escape_html_entities(StringView html)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (size_t i = 0; i < html.length(); ++i) {
|
for (size_t i = 0; i < html.length(); ++i) {
|
||||||
|
@ -370,40 +370,40 @@ DeprecatedString escape_html_entities(StringView html)
|
||||||
else
|
else
|
||||||
builder.append(html[i]);
|
builder.append(html[i]);
|
||||||
}
|
}
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString::DeprecatedString(DeprecatedFlyString const& string)
|
ByteString::ByteString(DeprecatedFlyString const& string)
|
||||||
: m_impl(*(string.impl() ?: &StringImpl::the_empty_stringimpl()))
|
: m_impl(*(string.impl() ?: &StringImpl::the_empty_stringimpl()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::to_lowercase() const
|
ByteString ByteString::to_lowercase() const
|
||||||
{
|
{
|
||||||
return m_impl->to_lowercase();
|
return m_impl->to_lowercase();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::to_uppercase() const
|
ByteString ByteString::to_uppercase() const
|
||||||
{
|
{
|
||||||
return m_impl->to_uppercase();
|
return m_impl->to_uppercase();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::to_snakecase() const
|
ByteString ByteString::to_snakecase() const
|
||||||
{
|
{
|
||||||
return StringUtils::to_snakecase(*this);
|
return StringUtils::to_snakecase(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::to_titlecase() const
|
ByteString ByteString::to_titlecase() const
|
||||||
{
|
{
|
||||||
return StringUtils::to_titlecase(*this);
|
return StringUtils::to_titlecase(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::invert_case() const
|
ByteString ByteString::invert_case() const
|
||||||
{
|
{
|
||||||
return StringUtils::invert_case(*this);
|
return StringUtils::invert_case(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedString::operator==(char const* cstring) const
|
bool ByteString::operator==(char const* cstring) const
|
||||||
{
|
{
|
||||||
if (!cstring)
|
if (!cstring)
|
||||||
return is_empty();
|
return is_empty();
|
||||||
|
@ -411,28 +411,28 @@ bool DeprecatedString::operator==(char const* cstring) const
|
||||||
return view() == cstring;
|
return view() == cstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString DeprecatedString::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
|
ByteString ByteString::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
MUST(vformat(builder, fmtstr, params));
|
MUST(vformat(builder, fmtstr, params));
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<size_t> DeprecatedString::find_all(StringView needle) const
|
Vector<size_t> ByteString::find_all(StringView needle) const
|
||||||
{
|
{
|
||||||
return StringUtils::find_all(*this, needle);
|
return StringUtils::find_all(*this, needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedStringCodePointIterator DeprecatedString::code_points() const
|
DeprecatedStringCodePointIterator ByteString::code_points() const
|
||||||
{
|
{
|
||||||
return DeprecatedStringCodePointIterator(*this);
|
return DeprecatedStringCodePointIterator(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<DeprecatedString> DeprecatedString::from_utf8(ReadonlyBytes bytes)
|
ErrorOr<ByteString> ByteString::from_utf8(ReadonlyBytes bytes)
|
||||||
{
|
{
|
||||||
if (!Utf8View(bytes).validate())
|
if (!Utf8View(bytes).validate())
|
||||||
return Error::from_string_literal("DeprecatedString::from_utf8: Input was not valid UTF-8");
|
return Error::from_string_literal("ByteString::from_utf8: Input was not valid UTF-8");
|
||||||
return DeprecatedString { *StringImpl::create(bytes) };
|
return ByteString { *StringImpl::create(bytes) };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -16,93 +16,93 @@
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
// DeprecatedString is a convenience wrapper around StringImpl, suitable for passing
|
// ByteString is a convenience wrapper around StringImpl, suitable for passing
|
||||||
// around as a value type. It's basically the same as passing around a
|
// around as a value type. It's basically the same as passing around a
|
||||||
// RefPtr<StringImpl const>, with a bit of syntactic sugar.
|
// RefPtr<StringImpl const>, with a bit of syntactic sugar.
|
||||||
//
|
//
|
||||||
// Note that StringImpl is an immutable object that cannot shrink or grow.
|
// Note that StringImpl is an immutable object that cannot shrink or grow.
|
||||||
// Its allocation size is snugly tailored to the specific string it contains.
|
// Its allocation size is snugly tailored to the specific string it contains.
|
||||||
// Copying a DeprecatedString is very efficient, since the internal StringImpl is
|
// Copying a ByteString is very efficient, since the internal StringImpl is
|
||||||
// retainable and so copying only requires modifying the ref count.
|
// retainable and so copying only requires modifying the ref count.
|
||||||
//
|
//
|
||||||
// There are three main ways to construct a new DeprecatedString:
|
// There are three main ways to construct a new ByteString:
|
||||||
//
|
//
|
||||||
// s = DeprecatedString("some literal");
|
// s = ByteString("some literal");
|
||||||
//
|
//
|
||||||
// s = DeprecatedString::formatted("{} little piggies", m_piggies);
|
// s = ByteString::formatted("{} little piggies", m_piggies);
|
||||||
//
|
//
|
||||||
// StringBuilder builder;
|
// StringBuilder builder;
|
||||||
// builder.append("abc");
|
// builder.append("abc");
|
||||||
// builder.append("123");
|
// builder.append("123");
|
||||||
// s = builder.to_deprecated_string();
|
// s = builder.to_byte_string();
|
||||||
|
|
||||||
class DeprecatedString {
|
class ByteString {
|
||||||
public:
|
public:
|
||||||
~DeprecatedString() = default;
|
~ByteString() = default;
|
||||||
|
|
||||||
DeprecatedString()
|
ByteString()
|
||||||
: m_impl(StringImpl::the_empty_stringimpl())
|
: m_impl(StringImpl::the_empty_stringimpl())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(StringView view)
|
ByteString(StringView view)
|
||||||
: m_impl(*StringImpl::create(view.characters_without_null_termination(), view.length()))
|
: m_impl(*StringImpl::create(view.characters_without_null_termination(), view.length()))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(DeprecatedString const& other)
|
ByteString(ByteString const& other)
|
||||||
: m_impl(other.m_impl)
|
: m_impl(other.m_impl)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(DeprecatedString&& other)
|
ByteString(ByteString&& other)
|
||||||
: m_impl(move(other.m_impl))
|
: m_impl(move(other.m_impl))
|
||||||
{
|
{
|
||||||
other.m_impl = StringImpl::the_empty_stringimpl();
|
other.m_impl = StringImpl::the_empty_stringimpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
|
ByteString(char const* cstring, ShouldChomp shouldChomp = NoChomp)
|
||||||
: m_impl(*StringImpl::create(cstring, shouldChomp))
|
: m_impl(*StringImpl::create(cstring, shouldChomp))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
|
ByteString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp)
|
||||||
: m_impl(*StringImpl::create(cstring, length, shouldChomp))
|
: m_impl(*StringImpl::create(cstring, length, shouldChomp))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit DeprecatedString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
|
explicit ByteString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp)
|
||||||
: m_impl(*StringImpl::create(bytes, shouldChomp))
|
: m_impl(*StringImpl::create(bytes, shouldChomp))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(StringImpl const& impl)
|
ByteString(StringImpl const& impl)
|
||||||
: m_impl(impl)
|
: m_impl(impl)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(NonnullRefPtr<StringImpl const>&& impl)
|
ByteString(NonnullRefPtr<StringImpl const>&& impl)
|
||||||
: m_impl(*move(impl))
|
: m_impl(*move(impl))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString(DeprecatedFlyString const&);
|
ByteString(DeprecatedFlyString const&);
|
||||||
|
|
||||||
static ErrorOr<DeprecatedString> from_utf8(ReadonlyBytes);
|
static ErrorOr<ByteString> from_utf8(ReadonlyBytes);
|
||||||
static ErrorOr<DeprecatedString> from_utf8(StringView string) { return from_utf8(string.bytes()); }
|
static ErrorOr<ByteString> from_utf8(StringView string) { return from_utf8(string.bytes()); }
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString repeated(char, size_t count);
|
[[nodiscard]] static ByteString repeated(char, size_t count);
|
||||||
[[nodiscard]] static DeprecatedString repeated(StringView, size_t count);
|
[[nodiscard]] static ByteString repeated(StringView, size_t count);
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
|
[[nodiscard]] static ByteString bijective_base_from(size_t value, unsigned base = 26, StringView map = {});
|
||||||
[[nodiscard]] static DeprecatedString roman_number_from(size_t value);
|
[[nodiscard]] static ByteString roman_number_from(size_t value);
|
||||||
|
|
||||||
template<class SeparatorType, class CollectionType>
|
template<class SeparatorType, class CollectionType>
|
||||||
[[nodiscard]] static DeprecatedString join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
|
[[nodiscard]] static ByteString join(SeparatorType const& separator, CollectionType const& collection, StringView fmtstr = "{}"sv)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.join(separator, collection, fmtstr);
|
builder.join(separator, collection, fmtstr);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
|
[[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
|
||||||
|
@ -117,17 +117,17 @@ public:
|
||||||
[[nodiscard]] Optional<float> to_float(TrimWhitespace = TrimWhitespace::Yes) const;
|
[[nodiscard]] Optional<float> to_float(TrimWhitespace = TrimWhitespace::Yes) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString to_lowercase() const;
|
[[nodiscard]] ByteString to_lowercase() const;
|
||||||
[[nodiscard]] DeprecatedString to_uppercase() const;
|
[[nodiscard]] ByteString to_uppercase() const;
|
||||||
[[nodiscard]] DeprecatedString to_snakecase() const;
|
[[nodiscard]] ByteString to_snakecase() const;
|
||||||
[[nodiscard]] DeprecatedString to_titlecase() const;
|
[[nodiscard]] ByteString to_titlecase() const;
|
||||||
[[nodiscard]] DeprecatedString invert_case() const;
|
[[nodiscard]] ByteString invert_case() const;
|
||||||
|
|
||||||
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
|
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedStringCodePointIterator code_points() const;
|
[[nodiscard]] DeprecatedStringCodePointIterator code_points() const;
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString trim(StringView characters, TrimMode mode = TrimMode::Both) const
|
[[nodiscard]] ByteString trim(StringView characters, TrimMode mode = TrimMode::Both) const
|
||||||
{
|
{
|
||||||
auto trimmed_view = StringUtils::trim(view(), characters, mode);
|
auto trimmed_view = StringUtils::trim(view(), characters, mode);
|
||||||
if (view() == trimmed_view)
|
if (view() == trimmed_view)
|
||||||
|
@ -135,7 +135,7 @@ public:
|
||||||
return trimmed_view;
|
return trimmed_view;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString trim_whitespace(TrimMode mode = TrimMode::Both) const
|
[[nodiscard]] ByteString trim_whitespace(TrimMode mode = TrimMode::Both) const
|
||||||
{
|
{
|
||||||
auto trimmed_view = StringUtils::trim_whitespace(view(), mode);
|
auto trimmed_view = StringUtils::trim_whitespace(view(), mode);
|
||||||
if (view() == trimmed_view)
|
if (view() == trimmed_view)
|
||||||
|
@ -148,8 +148,8 @@ public:
|
||||||
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
||||||
[[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
[[nodiscard]] bool contains(char, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
|
||||||
|
|
||||||
[[nodiscard]] Vector<DeprecatedString> split_limit(char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const;
|
[[nodiscard]] Vector<ByteString> split_limit(char separator, size_t limit, SplitBehavior = SplitBehavior::Nothing) const;
|
||||||
[[nodiscard]] Vector<DeprecatedString> split(char separator, SplitBehavior = SplitBehavior::Nothing) const;
|
[[nodiscard]] Vector<ByteString> split(char separator, SplitBehavior = SplitBehavior::Nothing) const;
|
||||||
[[nodiscard]] Vector<StringView> split_view(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;
|
[[nodiscard]] Vector<StringView> split_view(Function<bool(char)> separator, SplitBehavior = SplitBehavior::Nothing) const;
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] StringView find_last_split_view(char separator) const { return view().find_last_split_view(separator); }
|
[[nodiscard]] StringView find_last_split_view(char separator) const { return view().find_last_split_view(separator); }
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString substring(size_t start, size_t length) const;
|
[[nodiscard]] ByteString substring(size_t start, size_t length) const;
|
||||||
[[nodiscard]] DeprecatedString substring(size_t start) const;
|
[[nodiscard]] ByteString substring(size_t start) const;
|
||||||
[[nodiscard]] StringView substring_view(size_t start, size_t length) const;
|
[[nodiscard]] StringView substring_view(size_t start, size_t length) const;
|
||||||
[[nodiscard]] StringView substring_view(size_t start) const;
|
[[nodiscard]] StringView substring_view(size_t start) const;
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ public:
|
||||||
return bit_cast<u8>((*m_impl)[i]);
|
return bit_cast<u8>((*m_impl)[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
using ConstIterator = SimpleIterator<const DeprecatedString, char const>;
|
using ConstIterator = SimpleIterator<const ByteString, char const>;
|
||||||
|
|
||||||
[[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); }
|
[[nodiscard]] constexpr ConstIterator begin() const { return ConstIterator::begin(*this); }
|
||||||
[[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); }
|
[[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); }
|
||||||
|
@ -200,47 +200,47 @@ public:
|
||||||
[[nodiscard]] bool starts_with(char) const;
|
[[nodiscard]] bool starts_with(char) const;
|
||||||
[[nodiscard]] bool ends_with(char) const;
|
[[nodiscard]] bool ends_with(char) const;
|
||||||
|
|
||||||
bool operator==(DeprecatedString const&) const;
|
bool operator==(ByteString const&) const;
|
||||||
|
|
||||||
bool operator==(StringView) const;
|
bool operator==(StringView) const;
|
||||||
|
|
||||||
bool operator==(DeprecatedFlyString const&) const;
|
bool operator==(DeprecatedFlyString const&) const;
|
||||||
|
|
||||||
bool operator<(DeprecatedString const&) const;
|
bool operator<(ByteString const&) const;
|
||||||
bool operator>=(DeprecatedString const& other) const { return !(*this < other); }
|
bool operator>=(ByteString const& other) const { return !(*this < other); }
|
||||||
bool operator>=(char const* other) const { return !(*this < other); }
|
bool operator>=(char const* other) const { return !(*this < other); }
|
||||||
|
|
||||||
bool operator>(DeprecatedString const&) const;
|
bool operator>(ByteString const&) const;
|
||||||
bool operator<=(DeprecatedString const& other) const { return !(*this > other); }
|
bool operator<=(ByteString const& other) const { return !(*this > other); }
|
||||||
bool operator<=(char const* other) const { return !(*this > other); }
|
bool operator<=(char const* other) const { return !(*this > other); }
|
||||||
|
|
||||||
bool operator==(char const* cstring) const;
|
bool operator==(char const* cstring) const;
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString isolated_copy() const;
|
[[nodiscard]] ByteString isolated_copy() const;
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString empty()
|
[[nodiscard]] static ByteString empty()
|
||||||
{
|
{
|
||||||
return StringImpl::the_empty_stringimpl();
|
return StringImpl::the_empty_stringimpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); }
|
[[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); }
|
||||||
|
|
||||||
DeprecatedString& operator=(DeprecatedString&& other)
|
ByteString& operator=(ByteString&& other)
|
||||||
{
|
{
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
m_impl = move(other.m_impl);
|
m_impl = move(other.m_impl);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString& operator=(DeprecatedString const& other)
|
ByteString& operator=(ByteString const& other)
|
||||||
{
|
{
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
m_impl = const_cast<DeprecatedString&>(other).m_impl;
|
m_impl = const_cast<ByteString&>(other).m_impl;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<OneOf<ReadonlyBytes, Bytes> T>
|
template<OneOf<ReadonlyBytes, Bytes> T>
|
||||||
DeprecatedString& operator=(T bytes)
|
ByteString& operator=(T bytes)
|
||||||
{
|
{
|
||||||
m_impl = *StringImpl::create(bytes);
|
m_impl = *StringImpl::create(bytes);
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -254,24 +254,24 @@ public:
|
||||||
[[nodiscard]] ByteBuffer to_byte_buffer() const;
|
[[nodiscard]] ByteBuffer to_byte_buffer() const;
|
||||||
|
|
||||||
template<typename BufferType>
|
template<typename BufferType>
|
||||||
[[nodiscard]] static DeprecatedString copy(BufferType const& buffer, ShouldChomp should_chomp = NoChomp)
|
[[nodiscard]] static ByteString copy(BufferType const& buffer, ShouldChomp should_chomp = NoChomp)
|
||||||
{
|
{
|
||||||
if (buffer.is_empty())
|
if (buffer.is_empty())
|
||||||
return empty();
|
return empty();
|
||||||
return DeprecatedString(reinterpret_cast<char const*>(buffer.data()), buffer.size(), should_chomp);
|
return ByteString(reinterpret_cast<char const*>(buffer.data()), buffer.size(), should_chomp);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString vformatted(StringView fmtstr, TypeErasedFormatParams&);
|
[[nodiscard]] static ByteString vformatted(StringView fmtstr, TypeErasedFormatParams&);
|
||||||
|
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
[[nodiscard]] static DeprecatedString formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
[[nodiscard]] static ByteString formatted(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
||||||
{
|
{
|
||||||
VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
|
VariadicFormatParams<AllowDebugOnlyFormatters::No, Parameters...> variadic_format_parameters { parameters... };
|
||||||
return vformatted(fmtstr.view(), variadic_format_parameters);
|
return vformatted(fmtstr.view(), variadic_format_parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Arithmetic T>
|
template<Arithmetic T>
|
||||||
[[nodiscard]] static DeprecatedString number(T value)
|
[[nodiscard]] static ByteString number(T value)
|
||||||
{
|
{
|
||||||
return formatted("{}", value);
|
return formatted("{}", value);
|
||||||
}
|
}
|
||||||
|
@ -281,9 +281,9 @@ public:
|
||||||
return { characters(), length() };
|
return { characters(), length() };
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString replace(StringView needle, StringView replacement, ReplaceMode replace_mode = ReplaceMode::All) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }
|
[[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode replace_mode = ReplaceMode::All) const { return StringUtils::replace(*this, needle, replacement, replace_mode); }
|
||||||
[[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); }
|
[[nodiscard]] size_t count(StringView needle) const { return StringUtils::count(*this, needle); }
|
||||||
[[nodiscard]] DeprecatedString reverse() const;
|
[[nodiscard]] ByteString reverse() const;
|
||||||
|
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
|
[[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const
|
||||||
|
@ -308,17 +308,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Traits<DeprecatedString> : public DefaultTraits<DeprecatedString> {
|
struct Traits<ByteString> : public DefaultTraits<ByteString> {
|
||||||
static unsigned hash(DeprecatedString const& s) { return s.impl() ? s.impl()->hash() : 0; }
|
static unsigned hash(ByteString const& s) { return s.impl() ? s.impl()->hash() : 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: Rename this to indicate that it's about ASCII-only case insensitivity.
|
// FIXME: Rename this to indicate that it's about ASCII-only case insensitivity.
|
||||||
struct CaseInsensitiveStringTraits : public Traits<DeprecatedString> {
|
struct CaseInsensitiveStringTraits : public Traits<ByteString> {
|
||||||
static unsigned hash(DeprecatedString const& s) { return s.impl() ? s.impl()->case_insensitive_hash() : 0; }
|
static unsigned hash(ByteString const& s) { return s.impl() ? s.impl()->case_insensitive_hash() : 0; }
|
||||||
static bool equals(DeprecatedString const& a, DeprecatedString const& b) { return a.equals_ignoring_ascii_case(b); }
|
static bool equals(ByteString const& a, ByteString const& b) { return a.equals_ignoring_ascii_case(b); }
|
||||||
};
|
};
|
||||||
|
|
||||||
DeprecatedString escape_html_entities(StringView html);
|
ByteString escape_html_entities(StringView html);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ set(AK_SOURCES
|
||||||
CountingStream.cpp
|
CountingStream.cpp
|
||||||
DOSPackedTime.cpp
|
DOSPackedTime.cpp
|
||||||
DeprecatedFlyString.cpp
|
DeprecatedFlyString.cpp
|
||||||
DeprecatedString.cpp
|
ByteString.cpp
|
||||||
Error.cpp
|
Error.cpp
|
||||||
FloatingPointStringConversions.cpp
|
FloatingPointStringConversions.cpp
|
||||||
FlyString.cpp
|
FlyString.cpp
|
||||||
|
|
|
@ -8,17 +8,17 @@
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
|
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
# include <AK/StringView.h>
|
# include <AK/StringView.h>
|
||||||
# include <cxxabi.h>
|
# include <cxxabi.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
inline DeprecatedString demangle(StringView name)
|
inline ByteString demangle(StringView name)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
auto* demangled_name = abi::__cxa_demangle(name.to_deprecated_string().characters(), nullptr, nullptr, &status);
|
auto* demangled_name = abi::__cxa_demangle(name.to_byte_string().characters(), nullptr, nullptr, &status);
|
||||||
auto string = DeprecatedString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name);
|
auto string = ByteString(status == 0 ? StringView { demangled_name, strlen(demangled_name) } : name);
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
free(demangled_name);
|
free(demangled_name);
|
||||||
return string;
|
return string;
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/DeprecatedFlyString.h>
|
#include <AK/DeprecatedFlyString.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/HashTable.h>
|
#include <AK/HashTable.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/Singleton.h>
|
#include <AK/Singleton.h>
|
||||||
|
@ -36,7 +36,7 @@ void DeprecatedFlyString::did_destroy_impl(Badge<StringImpl>, StringImpl& impl)
|
||||||
fly_impls().remove(&impl);
|
fly_impls().remove(&impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedFlyString::DeprecatedFlyString(DeprecatedString const& string)
|
DeprecatedFlyString::DeprecatedFlyString(ByteString const& string)
|
||||||
{
|
{
|
||||||
if (string.impl()->is_fly()) {
|
if (string.impl()->is_fly()) {
|
||||||
m_impl = string.impl();
|
m_impl = string.impl();
|
||||||
|
@ -61,7 +61,7 @@ DeprecatedFlyString::DeprecatedFlyString(StringView string)
|
||||||
return string == *candidate;
|
return string == *candidate;
|
||||||
});
|
});
|
||||||
if (it == fly_impls().end()) {
|
if (it == fly_impls().end()) {
|
||||||
auto new_string = string.to_deprecated_string();
|
auto new_string = string.to_byte_string();
|
||||||
fly_impls().set(new_string.impl());
|
fly_impls().set(new_string.impl());
|
||||||
new_string.impl()->set_fly({}, true);
|
new_string.impl()->set_fly({}, true);
|
||||||
m_impl = new_string.impl();
|
m_impl = new_string.impl();
|
||||||
|
@ -122,10 +122,10 @@ bool DeprecatedFlyString::ends_with(StringView str, CaseSensitivity case_sensiti
|
||||||
|
|
||||||
DeprecatedFlyString DeprecatedFlyString::to_lowercase() const
|
DeprecatedFlyString DeprecatedFlyString::to_lowercase() const
|
||||||
{
|
{
|
||||||
return DeprecatedString(*m_impl).to_lowercase();
|
return ByteString(*m_impl).to_lowercase();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeprecatedFlyString::operator==(DeprecatedString const& other) const
|
bool DeprecatedFlyString::operator==(ByteString const& other) const
|
||||||
{
|
{
|
||||||
return m_impl == other.impl() || view() == other.view();
|
return m_impl == other.impl() || view() == other.view();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/StringUtils.h>
|
#include <AK/StringUtils.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -22,10 +22,10 @@ public:
|
||||||
: m_impl(move(other.m_impl))
|
: m_impl(move(other.m_impl))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
DeprecatedFlyString(DeprecatedString const&);
|
DeprecatedFlyString(ByteString const&);
|
||||||
DeprecatedFlyString(StringView);
|
DeprecatedFlyString(StringView);
|
||||||
DeprecatedFlyString(char const* string)
|
DeprecatedFlyString(char const* string)
|
||||||
: DeprecatedFlyString(static_cast<DeprecatedString>(string))
|
: DeprecatedFlyString(static_cast<ByteString>(string))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ public:
|
||||||
|
|
||||||
bool operator==(DeprecatedFlyString const& other) const { return m_impl == other.m_impl; }
|
bool operator==(DeprecatedFlyString const& other) const { return m_impl == other.m_impl; }
|
||||||
|
|
||||||
bool operator==(DeprecatedString const&) const;
|
bool operator==(ByteString const&) const;
|
||||||
|
|
||||||
bool operator==(StringView) const;
|
bool operator==(StringView) const;
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,10 @@ public:
|
||||||
}
|
}
|
||||||
static Error from_string_view(StringView string_literal) { return Error(string_literal); }
|
static Error from_string_view(StringView string_literal) { return Error(string_literal); }
|
||||||
|
|
||||||
template<OneOf<DeprecatedString, DeprecatedFlyString, String, FlyString> T>
|
template<OneOf<ByteString, DeprecatedFlyString, String, FlyString> T>
|
||||||
static Error from_string_view(T)
|
static Error from_string_view(T)
|
||||||
{
|
{
|
||||||
// `Error::from_string_view(DeprecatedString::formatted(...))` is a somewhat common mistake, which leads to a UAF situation.
|
// `Error::from_string_view(ByteString::formatted(...))` is a somewhat common mistake, which leads to a UAF situation.
|
||||||
// If your string outlives this error and _isn't_ a temporary being passed to this function, explicitly call .view() on it to resolve to the StringView overload.
|
// If your string outlives this error and _isn't_ a temporary being passed to this function, explicitly call .view() on it to resolve to the StringView overload.
|
||||||
static_assert(DependentFalse<T>, "Error::from_string_view(String) is almost always a use-after-free");
|
static_assert(DependentFalse<T>, "Error::from_string_view(String) is almost always a use-after-free");
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
static ErrorOr<FlyString> from_utf8(StringView);
|
static ErrorOr<FlyString> from_utf8(StringView);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(IsOneOf<RemoveCVReference<T>, DeprecatedString, DeprecatedFlyString, FlyString, String>)
|
requires(IsOneOf<RemoveCVReference<T>, ByteString, DeprecatedFlyString, FlyString, String>)
|
||||||
static ErrorOr<String> from_utf8(T&&) = delete;
|
static ErrorOr<String> from_utf8(T&&) = delete;
|
||||||
|
|
||||||
FlyString(String const&);
|
FlyString(String const&);
|
||||||
|
|
|
@ -274,7 +274,7 @@ ErrorOr<void> FormatBuilder::put_u64(
|
||||||
|
|
||||||
size_t used_by_prefix = 0;
|
size_t used_by_prefix = 0;
|
||||||
if (align == Align::Right && zero_pad) {
|
if (align == Align::Right && zero_pad) {
|
||||||
// We want DeprecatedString::formatted("{:#08x}", 32) to produce '0x00000020' instead of '0x000020'. This
|
// We want ByteString::formatted("{:#08x}", 32) to produce '0x00000020' instead of '0x000020'. This
|
||||||
// behavior differs from both fmtlib and printf, but is more intuitive.
|
// behavior differs from both fmtlib and printf, but is more intuitive.
|
||||||
used_by_prefix = 0;
|
used_by_prefix = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1131,13 +1131,13 @@ void vout(LogLevel log_level, StringView fmtstr, TypeErasedFormatParams& params,
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
// FIXME: Deduplicate with Core::Process:get_name()
|
// FIXME: Deduplicate with Core::Process:get_name()
|
||||||
[[gnu::used]] static DeprecatedString process_name_helper()
|
[[gnu::used]] static ByteString process_name_helper()
|
||||||
{
|
{
|
||||||
# if defined(AK_OS_SERENITY)
|
# if defined(AK_OS_SERENITY)
|
||||||
char buffer[BUFSIZ] = {};
|
char buffer[BUFSIZ] = {};
|
||||||
int rc = get_process_name(buffer, BUFSIZ);
|
int rc = get_process_name(buffer, BUFSIZ);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
return DeprecatedString {};
|
return ByteString {};
|
||||||
return StringView { buffer, strlen(buffer) };
|
return StringView { buffer, strlen(buffer) };
|
||||||
# elif defined(AK_LIBC_GLIBC) || (defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID))
|
# elif defined(AK_LIBC_GLIBC) || (defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID))
|
||||||
return StringView { program_invocation_name, strlen(program_invocation_name) };
|
return StringView { program_invocation_name, strlen(program_invocation_name) };
|
||||||
|
|
|
@ -501,7 +501,7 @@ struct Formatter<unsigned char[Size]> : Formatter<StringView> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<DeprecatedString> : Formatter<StringView> {
|
struct Formatter<ByteString> : Formatter<StringView> {
|
||||||
};
|
};
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<DeprecatedFlyString> : Formatter<StringView> {
|
struct Formatter<DeprecatedFlyString> : Formatter<StringView> {
|
||||||
|
|
|
@ -27,7 +27,7 @@ class CircularBuffer;
|
||||||
class ConstrainedStream;
|
class ConstrainedStream;
|
||||||
class CountingStream;
|
class CountingStream;
|
||||||
class DeprecatedFlyString;
|
class DeprecatedFlyString;
|
||||||
class DeprecatedString;
|
class ByteString;
|
||||||
class DeprecatedStringCodePointIterator;
|
class DeprecatedStringCodePointIterator;
|
||||||
class Duration;
|
class Duration;
|
||||||
class Error;
|
class Error;
|
||||||
|
@ -159,12 +159,12 @@ using AK::BigEndianOutputBitStream;
|
||||||
using AK::Bitmap;
|
using AK::Bitmap;
|
||||||
using AK::ByteBuffer;
|
using AK::ByteBuffer;
|
||||||
using AK::Bytes;
|
using AK::Bytes;
|
||||||
|
using AK::ByteString;
|
||||||
using AK::CircularBuffer;
|
using AK::CircularBuffer;
|
||||||
using AK::CircularQueue;
|
using AK::CircularQueue;
|
||||||
using AK::ConstrainedStream;
|
using AK::ConstrainedStream;
|
||||||
using AK::CountingStream;
|
using AK::CountingStream;
|
||||||
using AK::DeprecatedFlyString;
|
using AK::DeprecatedFlyString;
|
||||||
using AK::DeprecatedString;
|
|
||||||
using AK::DeprecatedStringCodePointIterator;
|
using AK::DeprecatedStringCodePointIterator;
|
||||||
using AK::DoublyLinkedList;
|
using AK::DoublyLinkedList;
|
||||||
using AK::Duration;
|
using AK::Duration;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
# include <AK/Utf16View.h>
|
# include <AK/Utf16View.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ template ErrorOr<u64> GenericLexer::consume_decimal_integer<u64>();
|
||||||
template ErrorOr<i64> GenericLexer::consume_decimal_integer<i64>();
|
template ErrorOr<i64> GenericLexer::consume_decimal_integer<i64>();
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
Optional<DeprecatedString> GenericLexer::consume_and_unescape_string(char escape_char)
|
Optional<ByteString> GenericLexer::consume_and_unescape_string(char escape_char)
|
||||||
{
|
{
|
||||||
auto view = consume_quoted_string(escape_char);
|
auto view = consume_quoted_string(escape_char);
|
||||||
if (view.is_null())
|
if (view.is_null())
|
||||||
|
@ -195,7 +195,7 @@ Optional<DeprecatedString> GenericLexer::consume_and_unescape_string(char escape
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (size_t i = 0; i < view.length(); ++i)
|
for (size_t i = 0; i < view.length(); ++i)
|
||||||
builder.append(consume_escaped_character(escape_char));
|
builder.append(consume_escaped_character(escape_char));
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto GenericLexer::consume_escaped_code_point(bool combine_surrogate_pairs) -> Result<u32, UnicodeEscapeError>
|
auto GenericLexer::consume_escaped_code_point(bool combine_surrogate_pairs) -> Result<u32, UnicodeEscapeError>
|
||||||
|
|
|
@ -92,7 +92,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
bool consume_specific(DeprecatedString const& next)
|
bool consume_specific(ByteString const& next)
|
||||||
{
|
{
|
||||||
return consume_specific(StringView { next });
|
return consume_specific(StringView { next });
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ public:
|
||||||
StringView consume_until(StringView);
|
StringView consume_until(StringView);
|
||||||
StringView consume_quoted_string(char escape_char = 0);
|
StringView consume_quoted_string(char escape_char = 0);
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
Optional<DeprecatedString> consume_and_unescape_string(char escape_char = '\\');
|
Optional<ByteString> consume_and_unescape_string(char escape_char = '\\');
|
||||||
#endif
|
#endif
|
||||||
template<Integral T>
|
template<Integral T>
|
||||||
ErrorOr<T> consume_decimal_integer();
|
ErrorOr<T> consume_decimal_integer();
|
||||||
|
|
|
@ -45,14 +45,14 @@ ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(const ReadonlyBytes input)
|
||||||
return Kernel::KString::try_create(output.string_view());
|
return Kernel::KString::try_create(output.string_view());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
DeprecatedString encode_hex(const ReadonlyBytes input)
|
ByteString encode_hex(const ReadonlyBytes input)
|
||||||
{
|
{
|
||||||
StringBuilder output(input.size() * 2);
|
StringBuilder output(input.size() * 2);
|
||||||
|
|
||||||
for (auto ch : input)
|
for (auto ch : input)
|
||||||
output.appendff("{:02x}", ch);
|
output.appendff("{:02x}", ch);
|
||||||
|
|
||||||
return output.to_deprecated_string();
|
return output.to_byte_string();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
4
AK/Hex.h
4
AK/Hex.h
|
@ -13,7 +13,7 @@
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
# include <Kernel/Library/KString.h>
|
# include <Kernel/Library/KString.h>
|
||||||
#else
|
#else
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -34,7 +34,7 @@ ErrorOr<ByteBuffer> decode_hex(StringView);
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(ReadonlyBytes);
|
ErrorOr<NonnullOwnPtr<Kernel::KString>> encode_hex(ReadonlyBytes);
|
||||||
#else
|
#else
|
||||||
DeprecatedString encode_hex(ReadonlyBytes);
|
ByteString encode_hex(ReadonlyBytes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
# include <AK/Error.h>
|
# include <AK/Error.h>
|
||||||
# include <Kernel/Library/KString.h>
|
# include <Kernel/Library/KString.h>
|
||||||
#else
|
#else
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
# include <AK/String.h>
|
# include <AK/String.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -67,18 +67,18 @@ public:
|
||||||
octet(SubnetClass::D));
|
octet(SubnetClass::D));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
DeprecatedString to_deprecated_string() const
|
ByteString to_byte_string() const
|
||||||
{
|
{
|
||||||
return DeprecatedString::formatted("{}.{}.{}.{}",
|
return ByteString::formatted("{}.{}.{}.{}",
|
||||||
octet(SubnetClass::A),
|
octet(SubnetClass::A),
|
||||||
octet(SubnetClass::B),
|
octet(SubnetClass::B),
|
||||||
octet(SubnetClass::C),
|
octet(SubnetClass::C),
|
||||||
octet(SubnetClass::D));
|
octet(SubnetClass::D));
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString to_deprecated_string_reversed() const
|
ByteString to_byte_string_reversed() const
|
||||||
{
|
{
|
||||||
return DeprecatedString::formatted("{}.{}.{}.{}",
|
return ByteString::formatted("{}.{}.{}.{}",
|
||||||
octet(SubnetClass::D),
|
octet(SubnetClass::D),
|
||||||
octet(SubnetClass::C),
|
octet(SubnetClass::C),
|
||||||
octet(SubnetClass::B),
|
octet(SubnetClass::B),
|
||||||
|
@ -179,7 +179,7 @@ template<>
|
||||||
struct Formatter<IPv4Address> : Formatter<StringView> {
|
struct Formatter<IPv4Address> : Formatter<StringView> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
|
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
|
||||||
{
|
{
|
||||||
return Formatter<StringView>::format(builder, value.to_deprecated_string());
|
return Formatter<StringView>::format(builder, value.to_byte_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -71,7 +71,7 @@ private:
|
||||||
{
|
{
|
||||||
using RawContainerType = RemoveCV<Container>;
|
using RawContainerType = RemoveCV<Container>;
|
||||||
|
|
||||||
if constexpr (IsSame<StringView, RawContainerType> || IsSame<DeprecatedString, RawContainerType>)
|
if constexpr (IsSame<StringView, RawContainerType> || IsSame<ByteString, RawContainerType>)
|
||||||
return { container, container.length() };
|
return { container, container.length() };
|
||||||
else
|
else
|
||||||
return { container, container.size() };
|
return { container, container.size() };
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
void serialize(Builder&) const;
|
void serialize(Builder&) const;
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString to_deprecated_string() const { return serialized<StringBuilder>(); }
|
[[nodiscard]] ByteString to_byte_string() const { return serialized<StringBuilder>(); }
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void for_each(Callback callback) const
|
void for_each(Callback callback) const
|
||||||
|
@ -111,7 +111,7 @@ inline typename Builder::OutputType JsonArray::serialized() const
|
||||||
{
|
{
|
||||||
Builder builder;
|
Builder builder;
|
||||||
serialize(builder);
|
serialize(builder);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
ErrorOr<void> add(DeprecatedString const& value)
|
ErrorOr<void> add(ByteString const& value)
|
||||||
{
|
{
|
||||||
TRY(begin_item());
|
TRY(begin_item());
|
||||||
if constexpr (IsLegacyBuilder<Builder>) {
|
if constexpr (IsLegacyBuilder<Builder>) {
|
||||||
|
|
|
@ -109,7 +109,7 @@ Optional<bool> JsonObject::get_bool(StringView key) const
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
#if !defined(KERNEL)
|
||||||
Optional<DeprecatedString> JsonObject::get_deprecated_string(StringView key) const
|
Optional<ByteString> JsonObject::get_byte_string(StringView key) const
|
||||||
{
|
{
|
||||||
auto maybe_value = get(key);
|
auto maybe_value = get(key);
|
||||||
if (maybe_value.has_value() && maybe_value->is_string())
|
if (maybe_value.has_value() && maybe_value->is_string())
|
||||||
|
@ -249,7 +249,7 @@ bool JsonObject::has_double(StringView key) const
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void JsonObject::set(DeprecatedString const& key, JsonValue value)
|
void JsonObject::set(ByteString const& key, JsonValue value)
|
||||||
{
|
{
|
||||||
m_members.set(key, move(value));
|
m_members.set(key, move(value));
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ bool JsonObject::remove(StringView key)
|
||||||
return m_members.remove(key);
|
return m_members.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString JsonObject::to_deprecated_string() const
|
ByteString JsonObject::to_byte_string() const
|
||||||
{
|
{
|
||||||
return serialized<StringBuilder>();
|
return serialized<StringBuilder>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Concepts.h>
|
#include <AK/Concepts.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/JsonArray.h>
|
#include <AK/JsonArray.h>
|
||||||
|
@ -20,7 +20,7 @@ namespace AK {
|
||||||
|
|
||||||
class JsonObject {
|
class JsonObject {
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
using CallbackErrorType = decltype(declval<Callback>()(declval<DeprecatedString const&>(), declval<JsonValue const&>()).release_error());
|
using CallbackErrorType = decltype(declval<Callback>()(declval<ByteString const&>(), declval<JsonValue const&>()).release_error());
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JsonObject();
|
JsonObject();
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
Optional<bool> get_bool(StringView key) const;
|
Optional<bool> get_bool(StringView key) const;
|
||||||
|
|
||||||
#if !defined(KERNEL)
|
#if !defined(KERNEL)
|
||||||
Optional<DeprecatedString> get_deprecated_string(StringView key) const;
|
Optional<ByteString> get_byte_string(StringView key) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Optional<JsonObject const&> get_object(StringView key) const;
|
Optional<JsonObject const&> get_object(StringView key) const;
|
||||||
|
@ -89,7 +89,7 @@ public:
|
||||||
Optional<float> get_float_with_precision_loss(StringView key) const;
|
Optional<float> get_float_with_precision_loss(StringView key) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void set(DeprecatedString const& key, JsonValue value);
|
void set(ByteString const& key, JsonValue value);
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void for_each_member(Callback callback) const
|
void for_each_member(Callback callback) const
|
||||||
|
@ -98,7 +98,7 @@ public:
|
||||||
callback(member.key, member.value);
|
callback(member.key, member.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<FallibleFunction<DeprecatedString const&, JsonValue const&> Callback>
|
template<FallibleFunction<ByteString const&, JsonValue const&> Callback>
|
||||||
ErrorOr<void, CallbackErrorType<Callback>> try_for_each_member(Callback&& callback) const
|
ErrorOr<void, CallbackErrorType<Callback>> try_for_each_member(Callback&& callback) const
|
||||||
{
|
{
|
||||||
for (auto const& member : m_members)
|
for (auto const& member : m_members)
|
||||||
|
@ -114,10 +114,10 @@ public:
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
void serialize(Builder&) const;
|
void serialize(Builder&) const;
|
||||||
|
|
||||||
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
[[nodiscard]] ByteString to_byte_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OrderedHashMap<DeprecatedString, JsonValue> m_members;
|
OrderedHashMap<ByteString, JsonValue> m_members;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
|
@ -135,7 +135,7 @@ inline typename Builder::OutputType JsonObject::serialized() const
|
||||||
{
|
{
|
||||||
Builder builder;
|
Builder builder;
|
||||||
serialize(builder);
|
serialize(builder);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
|
@ -186,7 +186,7 @@ inline typename Builder::OutputType JsonValue::serialized() const
|
||||||
{
|
{
|
||||||
Builder builder;
|
Builder builder;
|
||||||
serialize(builder);
|
serialize(builder);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
ErrorOr<void> add(StringView key, DeprecatedString const& value)
|
ErrorOr<void> add(StringView key, ByteString const& value)
|
||||||
{
|
{
|
||||||
TRY(begin_item(key));
|
TRY(begin_item(key));
|
||||||
if constexpr (IsLegacyBuilder<Builder>) {
|
if constexpr (IsLegacyBuilder<Builder>) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ constexpr bool is_space(int ch)
|
||||||
// │ │
|
// │ │
|
||||||
// ╰─── u[0-9A-Za-z]{4} ──╯
|
// ╰─── u[0-9A-Za-z]{4} ──╯
|
||||||
//
|
//
|
||||||
ErrorOr<DeprecatedString> JsonParser::consume_and_unescape_string()
|
ErrorOr<ByteString> JsonParser::consume_and_unescape_string()
|
||||||
{
|
{
|
||||||
if (!consume_specific('"'))
|
if (!consume_specific('"'))
|
||||||
return Error::from_string_literal("JsonParser: Expected '\"'");
|
return Error::from_string_literal("JsonParser: Expected '\"'");
|
||||||
|
@ -128,7 +128,7 @@ ErrorOr<DeprecatedString> JsonParser::consume_and_unescape_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return final_sb.to_deprecated_string();
|
return final_sb.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<JsonValue> JsonParser::parse_object()
|
ErrorOr<JsonValue> JsonParser::parse_object()
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
private:
|
private:
|
||||||
ErrorOr<JsonValue> parse_helper();
|
ErrorOr<JsonValue> parse_helper();
|
||||||
|
|
||||||
ErrorOr<DeprecatedString> consume_and_unescape_string();
|
ErrorOr<ByteString> consume_and_unescape_string();
|
||||||
ErrorOr<JsonValue> parse_array();
|
ErrorOr<JsonValue> parse_array();
|
||||||
ErrorOr<JsonValue> parse_object();
|
ErrorOr<JsonValue> parse_object();
|
||||||
ErrorOr<JsonValue> parse_number();
|
ErrorOr<JsonValue> parse_number();
|
||||||
|
|
|
@ -31,16 +31,16 @@ JsonValue JsonPath::resolve(JsonValue const& top_root) const
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString JsonPath::to_deprecated_string() const
|
ByteString JsonPath::to_byte_string() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append("{ ."sv);
|
builder.append("{ ."sv);
|
||||||
for (auto const& el : *this) {
|
for (auto const& el : *this) {
|
||||||
builder.append("sv > "sv);
|
builder.append("sv > "sv);
|
||||||
builder.append(el.to_deprecated_string());
|
builder.append(el.to_byte_string());
|
||||||
}
|
}
|
||||||
builder.append("sv }"sv);
|
builder.append("sv }"sv);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Kind kind() const { return m_kind; }
|
Kind kind() const { return m_kind; }
|
||||||
DeprecatedString const& key() const
|
ByteString const& key() const
|
||||||
{
|
{
|
||||||
VERIFY(m_kind == Kind::Key);
|
VERIFY(m_kind == Kind::Key);
|
||||||
return m_key;
|
return m_key;
|
||||||
|
@ -46,13 +46,13 @@ public:
|
||||||
return m_index;
|
return m_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString to_deprecated_string() const
|
ByteString to_byte_string() const
|
||||||
{
|
{
|
||||||
switch (m_kind) {
|
switch (m_kind) {
|
||||||
case Kind::Key:
|
case Kind::Key:
|
||||||
return key();
|
return key();
|
||||||
case Kind::Index:
|
case Kind::Index:
|
||||||
return DeprecatedString::number(index());
|
return ByteString::number(index());
|
||||||
default:
|
default:
|
||||||
return "*";
|
return "*";
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Kind m_kind;
|
Kind m_kind;
|
||||||
DeprecatedString m_key;
|
ByteString m_key;
|
||||||
size_t m_index { 0 };
|
size_t m_index { 0 };
|
||||||
|
|
||||||
JsonPathElement(Kind kind)
|
JsonPathElement(Kind kind)
|
||||||
|
@ -90,7 +90,7 @@ private:
|
||||||
class JsonPath : public Vector<JsonPathElement> {
|
class JsonPath : public Vector<JsonPathElement> {
|
||||||
public:
|
public:
|
||||||
JsonValue resolve(JsonValue const&) const;
|
JsonValue resolve(JsonValue const&) const;
|
||||||
DeprecatedString to_deprecated_string() const;
|
ByteString to_byte_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ JsonValue::JsonValue(long long unsigned value)
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue::JsonValue(char const* cstring)
|
JsonValue::JsonValue(char const* cstring)
|
||||||
: JsonValue(DeprecatedString(cstring))
|
: JsonValue(ByteString(cstring))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ JsonValue::JsonValue(double value)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JsonValue::JsonValue(DeprecatedString const& value)
|
JsonValue::JsonValue(ByteString const& value)
|
||||||
{
|
{
|
||||||
m_type = Type::String;
|
m_type = Type::String;
|
||||||
m_value.as_string = const_cast<StringImpl*>(value.impl());
|
m_value.as_string = const_cast<StringImpl*>(value.impl());
|
||||||
|
@ -175,7 +175,7 @@ JsonValue::JsonValue(DeprecatedString const& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue::JsonValue(StringView value)
|
JsonValue::JsonValue(StringView value)
|
||||||
: JsonValue(value.to_deprecated_string())
|
: JsonValue(value.to_byte_string())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
# error "JsonValue does not propagate allocation failures, so it is not safe to use in the kernel."
|
# error "JsonValue does not propagate allocation failures, so it is not safe to use in the kernel."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
@ -52,7 +52,7 @@ public:
|
||||||
|
|
||||||
JsonValue(double);
|
JsonValue(double);
|
||||||
JsonValue(char const*);
|
JsonValue(char const*);
|
||||||
JsonValue(DeprecatedString const&);
|
JsonValue(ByteString const&);
|
||||||
JsonValue(StringView);
|
JsonValue(StringView);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -78,14 +78,14 @@ public:
|
||||||
template<typename Builder>
|
template<typename Builder>
|
||||||
void serialize(Builder&) const;
|
void serialize(Builder&) const;
|
||||||
|
|
||||||
DeprecatedString as_string_or(DeprecatedString const& alternative) const
|
ByteString as_string_or(ByteString const& alternative) const
|
||||||
{
|
{
|
||||||
if (is_string())
|
if (is_string())
|
||||||
return as_string();
|
return as_string();
|
||||||
return alternative;
|
return alternative;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString to_deprecated_string() const
|
ByteString to_byte_string() const
|
||||||
{
|
{
|
||||||
if (is_string())
|
if (is_string())
|
||||||
return as_string();
|
return as_string();
|
||||||
|
@ -148,7 +148,7 @@ public:
|
||||||
return m_value.as_bool;
|
return m_value.as_bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString as_string() const
|
ByteString as_string() const
|
||||||
{
|
{
|
||||||
VERIFY(is_string());
|
VERIFY(is_string());
|
||||||
return *m_value.as_string;
|
return *m_value.as_string;
|
||||||
|
@ -290,7 +290,7 @@ template<>
|
||||||
struct Formatter<JsonValue> : Formatter<StringView> {
|
struct Formatter<JsonValue> : Formatter<StringView> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, JsonValue const& value)
|
ErrorOr<void> format(FormatBuilder& builder, JsonValue const& value)
|
||||||
{
|
{
|
||||||
return Formatter<StringView>::format(builder, value.to_deprecated_string());
|
return Formatter<StringView>::format(builder, value.to_byte_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace AK {
|
||||||
|
|
||||||
char s_single_dot = '.';
|
char s_single_dot = '.';
|
||||||
|
|
||||||
LexicalPath::LexicalPath(DeprecatedString path)
|
LexicalPath::LexicalPath(ByteString path)
|
||||||
: m_string(canonicalized_path(move(path)))
|
: m_string(canonicalized_path(move(path)))
|
||||||
{
|
{
|
||||||
if (m_string.is_empty()) {
|
if (m_string.is_empty()) {
|
||||||
|
@ -58,9 +58,9 @@ LexicalPath::LexicalPath(DeprecatedString path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<DeprecatedString> LexicalPath::parts() const
|
Vector<ByteString> LexicalPath::parts() const
|
||||||
{
|
{
|
||||||
Vector<DeprecatedString> vector;
|
Vector<ByteString> vector;
|
||||||
vector.ensure_capacity(m_parts.size());
|
vector.ensure_capacity(m_parts.size());
|
||||||
for (auto& part : m_parts)
|
for (auto& part : m_parts)
|
||||||
vector.unchecked_append(part);
|
vector.unchecked_append(part);
|
||||||
|
@ -88,7 +88,7 @@ bool LexicalPath::is_child_of(LexicalPath const& possible_parent) const
|
||||||
return common_parts_with_parent == possible_parent.parts_view().span();
|
return common_parts_with_parent == possible_parent.parts_view().span();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path)
|
ByteString LexicalPath::canonicalized_path(ByteString path)
|
||||||
{
|
{
|
||||||
// NOTE: We never allow an empty m_string, if it's empty, we just set it to '.'.
|
// NOTE: We never allow an empty m_string, if it's empty, we just set it to '.'.
|
||||||
if (path.is_empty())
|
if (path.is_empty())
|
||||||
|
@ -101,7 +101,7 @@ DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path)
|
||||||
auto is_absolute = path[0] == '/';
|
auto is_absolute = path[0] == '/';
|
||||||
auto parts = path.split_view('/');
|
auto parts = path.split_view('/');
|
||||||
size_t approximate_canonical_length = 0;
|
size_t approximate_canonical_length = 0;
|
||||||
Vector<DeprecatedString> canonical_parts;
|
Vector<ByteString> canonical_parts;
|
||||||
|
|
||||||
for (auto& part : parts) {
|
for (auto& part : parts) {
|
||||||
if (part == ".")
|
if (part == ".")
|
||||||
|
@ -131,10 +131,10 @@ DeprecatedString LexicalPath::canonicalized_path(DeprecatedString path)
|
||||||
if (is_absolute)
|
if (is_absolute)
|
||||||
builder.append('/');
|
builder.append('/');
|
||||||
builder.join('/', canonical_parts);
|
builder.join('/', canonical_parts);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString LexicalPath::absolute_path(DeprecatedString dir_path, DeprecatedString target)
|
ByteString LexicalPath::absolute_path(ByteString dir_path, ByteString target)
|
||||||
{
|
{
|
||||||
if (LexicalPath(target).is_absolute()) {
|
if (LexicalPath(target).is_absolute()) {
|
||||||
return LexicalPath::canonicalized_path(target);
|
return LexicalPath::canonicalized_path(target);
|
||||||
|
@ -142,10 +142,10 @@ DeprecatedString LexicalPath::absolute_path(DeprecatedString dir_path, Deprecate
|
||||||
return LexicalPath::canonicalized_path(join(dir_path, target).string());
|
return LexicalPath::canonicalized_path(join(dir_path, target).string());
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString LexicalPath::relative_path(StringView a_path, StringView a_prefix)
|
ByteString LexicalPath::relative_path(StringView a_path, StringView a_prefix)
|
||||||
{
|
{
|
||||||
if (!a_path.starts_with('/') || !a_prefix.starts_with('/')) {
|
if (!a_path.starts_with('/') || !a_prefix.starts_with('/')) {
|
||||||
// FIXME: This should probably VERIFY or return an Optional<DeprecatedString>.
|
// FIXME: This should probably VERIFY or return an Optional<ByteString>.
|
||||||
return ""sv;
|
return ""sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ DeprecatedString LexicalPath::relative_path(StringView a_path, StringView a_pref
|
||||||
builder.append('/');
|
builder.append('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
LexicalPath LexicalPath::append(StringView value) const
|
LexicalPath LexicalPath::append(StringView value) const
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Vector.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.
|
// On Linux distros that use mlibc `basename` is defined as a macro that expands to `__mlibc_gnu_basename` or `__mlibc_gnu_basename_c`, so we undefine it.
|
||||||
|
@ -24,10 +24,10 @@ public:
|
||||||
Yes
|
Yes
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit LexicalPath(DeprecatedString);
|
explicit LexicalPath(ByteString);
|
||||||
|
|
||||||
bool is_absolute() const { return !m_string.is_empty() && m_string[0] == '/'; }
|
bool is_absolute() const { return !m_string.is_empty() && m_string[0] == '/'; }
|
||||||
DeprecatedString const& string() const { return m_string; }
|
ByteString const& string() const { return m_string; }
|
||||||
|
|
||||||
StringView dirname() const { return m_dirname; }
|
StringView dirname() const { return m_dirname; }
|
||||||
StringView basename(StripExtension s = StripExtension::No) const { return s == StripExtension::No ? m_basename : m_basename.substring_view(0, m_basename.length() - m_extension.length() - 1); }
|
StringView basename(StripExtension s = StripExtension::No) const { return s == StripExtension::No ? m_basename : m_basename.substring_view(0, m_basename.length() - m_extension.length() - 1); }
|
||||||
|
@ -35,7 +35,7 @@ public:
|
||||||
StringView extension() const { return m_extension; }
|
StringView extension() const { return m_extension; }
|
||||||
|
|
||||||
Vector<StringView> const& parts_view() const { return m_parts; }
|
Vector<StringView> const& parts_view() const { return m_parts; }
|
||||||
[[nodiscard]] Vector<DeprecatedString> parts() const;
|
[[nodiscard]] Vector<ByteString> parts() const;
|
||||||
|
|
||||||
bool has_extension(StringView) const;
|
bool has_extension(StringView) const;
|
||||||
bool is_child_of(LexicalPath const& possible_parent) const;
|
bool is_child_of(LexicalPath const& possible_parent) const;
|
||||||
|
@ -44,9 +44,9 @@ public:
|
||||||
[[nodiscard]] LexicalPath prepend(StringView) const;
|
[[nodiscard]] LexicalPath prepend(StringView) const;
|
||||||
[[nodiscard]] LexicalPath parent() const;
|
[[nodiscard]] LexicalPath parent() const;
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString canonicalized_path(DeprecatedString);
|
[[nodiscard]] static ByteString canonicalized_path(ByteString);
|
||||||
[[nodiscard]] static DeprecatedString absolute_path(DeprecatedString dir_path, DeprecatedString target);
|
[[nodiscard]] static ByteString absolute_path(ByteString dir_path, ByteString target);
|
||||||
[[nodiscard]] static DeprecatedString relative_path(StringView absolute_path, StringView prefix);
|
[[nodiscard]] static ByteString relative_path(StringView absolute_path, StringView prefix);
|
||||||
|
|
||||||
template<typename... S>
|
template<typename... S>
|
||||||
[[nodiscard]] static LexicalPath join(StringView first, S&&... rest)
|
[[nodiscard]] static LexicalPath join(StringView first, S&&... rest)
|
||||||
|
@ -55,28 +55,28 @@ public:
|
||||||
builder.append(first);
|
builder.append(first);
|
||||||
((builder.append('/'), builder.append(forward<S>(rest))), ...);
|
((builder.append('/'), builder.append(forward<S>(rest))), ...);
|
||||||
|
|
||||||
return LexicalPath { builder.to_deprecated_string() };
|
return LexicalPath { builder.to_byte_string() };
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString dirname(DeprecatedString path)
|
[[nodiscard]] static ByteString dirname(ByteString path)
|
||||||
{
|
{
|
||||||
auto lexical_path = LexicalPath(move(path));
|
auto lexical_path = LexicalPath(move(path));
|
||||||
return lexical_path.dirname();
|
return lexical_path.dirname();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString basename(DeprecatedString path, StripExtension s = StripExtension::No)
|
[[nodiscard]] static ByteString basename(ByteString path, StripExtension s = StripExtension::No)
|
||||||
{
|
{
|
||||||
auto lexical_path = LexicalPath(move(path));
|
auto lexical_path = LexicalPath(move(path));
|
||||||
return lexical_path.basename(s);
|
return lexical_path.basename(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString title(DeprecatedString path)
|
[[nodiscard]] static ByteString title(ByteString path)
|
||||||
{
|
{
|
||||||
auto lexical_path = LexicalPath(move(path));
|
auto lexical_path = LexicalPath(move(path));
|
||||||
return lexical_path.title();
|
return lexical_path.title();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static DeprecatedString extension(DeprecatedString path)
|
[[nodiscard]] static ByteString extension(ByteString path)
|
||||||
{
|
{
|
||||||
auto lexical_path = LexicalPath(move(path));
|
auto lexical_path = LexicalPath(move(path));
|
||||||
return lexical_path.extension();
|
return lexical_path.extension();
|
||||||
|
@ -84,7 +84,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<StringView> m_parts;
|
Vector<StringView> m_parts;
|
||||||
DeprecatedString m_string;
|
ByteString m_string;
|
||||||
StringView m_dirname;
|
StringView m_dirname;
|
||||||
StringView m_basename;
|
StringView m_basename;
|
||||||
StringView m_title;
|
StringView m_title;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
# include <Kernel/Library/KString.h>
|
# include <Kernel/Library/KString.h>
|
||||||
#else
|
#else
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class [[gnu::packed]] MACAddress {
|
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]);
|
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
|
#else
|
||||||
DeprecatedString to_deprecated_string() const
|
ByteString to_byte_string() const
|
||||||
{
|
{
|
||||||
return DeprecatedString::formatted("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", m_data[0], m_data[1], m_data[2], m_data[3], m_data[4], m_data[5]);
|
return ByteString::formatted("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", m_data[0], m_data[1], m_data[2], m_data[3], m_data[4], m_data[5]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/NumberFormat.h>
|
#include <AK/NumberFormat.h>
|
||||||
#include <AK/NumericLimits.h>
|
#include <AK/NumericLimits.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
// FIXME: Remove this hackery once printf() supports floats.
|
// FIXME: Remove this hackery once printf() supports floats.
|
||||||
static DeprecatedString number_string_with_one_decimal(u64 number, u64 unit, StringView suffix, UseThousandsSeparator use_thousands_separator)
|
static ByteString number_string_with_one_decimal(u64 number, u64 unit, StringView suffix, UseThousandsSeparator use_thousands_separator)
|
||||||
{
|
{
|
||||||
constexpr auto max_unit_size = NumericLimits<u64>::max() / 10;
|
constexpr auto max_unit_size = NumericLimits<u64>::max() / 10;
|
||||||
VERIFY(unit < max_unit_size);
|
VERIFY(unit < max_unit_size);
|
||||||
|
@ -21,25 +21,25 @@ static DeprecatedString number_string_with_one_decimal(u64 number, u64 unit, Str
|
||||||
auto integer_part = number / unit;
|
auto integer_part = number / unit;
|
||||||
auto decimal_part = (number % unit) * 10 / unit;
|
auto decimal_part = (number % unit) * 10 / unit;
|
||||||
if (use_thousands_separator == UseThousandsSeparator::Yes)
|
if (use_thousands_separator == UseThousandsSeparator::Yes)
|
||||||
return DeprecatedString::formatted("{:'d}.{} {}", integer_part, decimal_part, suffix);
|
return ByteString::formatted("{:'d}.{} {}", integer_part, decimal_part, suffix);
|
||||||
|
|
||||||
return DeprecatedString::formatted("{}.{} {}", integer_part, decimal_part, suffix);
|
return ByteString::formatted("{}.{} {}", integer_part, decimal_part, suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on, StringView unit, UseThousandsSeparator use_thousands_separator)
|
ByteString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on, StringView unit, UseThousandsSeparator use_thousands_separator)
|
||||||
{
|
{
|
||||||
u64 size_of_unit = based_on == HumanReadableBasedOn::Base2 ? 1024 : 1000;
|
u64 size_of_unit = based_on == HumanReadableBasedOn::Base2 ? 1024 : 1000;
|
||||||
constexpr auto unit_prefixes = AK::Array { "", "K", "M", "G", "T", "P", "E" };
|
constexpr auto unit_prefixes = AK::Array { "", "K", "M", "G", "T", "P", "E" };
|
||||||
auto full_unit_suffix = [&](int index) {
|
auto full_unit_suffix = [&](int index) {
|
||||||
auto binary_infix = (based_on == HumanReadableBasedOn::Base2 && index != 0) ? "i"sv : ""sv;
|
auto binary_infix = (based_on == HumanReadableBasedOn::Base2 && index != 0) ? "i"sv : ""sv;
|
||||||
return DeprecatedString::formatted("{}{}{}",
|
return ByteString::formatted("{}{}{}",
|
||||||
unit_prefixes[index], binary_infix, unit);
|
unit_prefixes[index], binary_infix, unit);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto size_of_current_unit = size_of_unit;
|
auto size_of_current_unit = size_of_unit;
|
||||||
|
|
||||||
if (quantity < size_of_unit)
|
if (quantity < size_of_unit)
|
||||||
return DeprecatedString::formatted("{} {}", quantity, full_unit_suffix(0));
|
return ByteString::formatted("{} {}", quantity, full_unit_suffix(0));
|
||||||
|
|
||||||
for (size_t i = 1; i < unit_prefixes.size() - 1; i++) {
|
for (size_t i = 1; i < unit_prefixes.size() - 1; i++) {
|
||||||
auto suffix = full_unit_suffix(i);
|
auto suffix = full_unit_suffix(i);
|
||||||
|
@ -54,28 +54,28 @@ DeprecatedString human_readable_quantity(u64 quantity, HumanReadableBasedOn base
|
||||||
size_of_current_unit, full_unit_suffix(unit_prefixes.size() - 1), use_thousands_separator);
|
size_of_current_unit, full_unit_suffix(unit_prefixes.size() - 1), use_thousands_separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString human_readable_size(u64 size, HumanReadableBasedOn based_on, UseThousandsSeparator use_thousands_separator)
|
ByteString human_readable_size(u64 size, HumanReadableBasedOn based_on, UseThousandsSeparator use_thousands_separator)
|
||||||
{
|
{
|
||||||
return human_readable_quantity(size, based_on, "B"sv, use_thousands_separator);
|
return human_readable_quantity(size, based_on, "B"sv, use_thousands_separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator)
|
ByteString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator)
|
||||||
{
|
{
|
||||||
if (size < 1 * KiB) {
|
if (size < 1 * KiB) {
|
||||||
if (use_thousands_separator == UseThousandsSeparator::Yes)
|
if (use_thousands_separator == UseThousandsSeparator::Yes)
|
||||||
return DeprecatedString::formatted("{:'d} bytes", size);
|
return ByteString::formatted("{:'d} bytes", size);
|
||||||
|
|
||||||
return DeprecatedString::formatted("{} bytes", size);
|
return ByteString::formatted("{} bytes", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto human_readable_size_string = human_readable_size(size, HumanReadableBasedOn::Base2, use_thousands_separator);
|
auto human_readable_size_string = human_readable_size(size, HumanReadableBasedOn::Base2, use_thousands_separator);
|
||||||
if (use_thousands_separator == UseThousandsSeparator::Yes)
|
if (use_thousands_separator == UseThousandsSeparator::Yes)
|
||||||
return DeprecatedString::formatted("{} ({:'d} bytes)", human_readable_size_string, size);
|
return ByteString::formatted("{} ({:'d} bytes)", human_readable_size_string, size);
|
||||||
|
|
||||||
return DeprecatedString::formatted("{} ({} bytes)", human_readable_size_string, size);
|
return ByteString::formatted("{} ({} bytes)", human_readable_size_string, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString human_readable_time(i64 time_in_seconds)
|
ByteString human_readable_time(i64 time_in_seconds)
|
||||||
{
|
{
|
||||||
auto days = time_in_seconds / 86400;
|
auto days = time_in_seconds / 86400;
|
||||||
time_in_seconds = time_in_seconds % 86400;
|
time_in_seconds = time_in_seconds % 86400;
|
||||||
|
@ -99,10 +99,10 @@ DeprecatedString human_readable_time(i64 time_in_seconds)
|
||||||
|
|
||||||
builder.appendff("{} second{}", time_in_seconds, time_in_seconds == 1 ? "" : "s");
|
builder.appendff("{} second{}", time_in_seconds, time_in_seconds == 1 ? "" : "s");
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString human_readable_digital_time(i64 time_in_seconds)
|
ByteString human_readable_digital_time(i64 time_in_seconds)
|
||||||
{
|
{
|
||||||
auto hours = time_in_seconds / 3600;
|
auto hours = time_in_seconds / 3600;
|
||||||
time_in_seconds = time_in_seconds % 3600;
|
time_in_seconds = time_in_seconds % 3600;
|
||||||
|
@ -117,7 +117,7 @@ DeprecatedString human_readable_digital_time(i64 time_in_seconds)
|
||||||
builder.appendff("{:02}:", minutes);
|
builder.appendff("{:02}:", minutes);
|
||||||
builder.appendff("{:02}", time_in_seconds);
|
builder.appendff("{:02}", time_in_seconds);
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ enum class UseThousandsSeparator {
|
||||||
No
|
No
|
||||||
};
|
};
|
||||||
|
|
||||||
DeprecatedString human_readable_size(u64 size, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
ByteString human_readable_size(u64 size, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
||||||
DeprecatedString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, StringView unit = "B"sv, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
ByteString human_readable_quantity(u64 quantity, HumanReadableBasedOn based_on = HumanReadableBasedOn::Base2, StringView unit = "B"sv, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
||||||
|
|
||||||
DeprecatedString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
ByteString human_readable_size_long(u64 size, UseThousandsSeparator use_thousands_separator = UseThousandsSeparator::No);
|
||||||
DeprecatedString human_readable_time(i64 time_in_seconds);
|
ByteString human_readable_time(i64 time_in_seconds);
|
||||||
DeprecatedString human_readable_digital_time(i64 time_in_seconds);
|
ByteString human_readable_digital_time(i64 time_in_seconds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ private:
|
||||||
static constexpr SimpleReverseIterator rbegin(Container& container)
|
static constexpr SimpleReverseIterator rbegin(Container& container)
|
||||||
{
|
{
|
||||||
using RawContainerType = RemoveCV<Container>;
|
using RawContainerType = RemoveCV<Container>;
|
||||||
if constexpr (IsSame<StringView, RawContainerType> || IsSame<DeprecatedString, RawContainerType>)
|
if constexpr (IsSame<StringView, RawContainerType> || IsSame<ByteString, RawContainerType>)
|
||||||
return { container, static_cast<int>(container.length()) - 1 };
|
return { container, static_cast<int>(container.length()) - 1 };
|
||||||
else
|
else
|
||||||
return { container, static_cast<int>(container.size()) - 1 };
|
return { container, static_cast<int>(container.size()) - 1 };
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/SourceLocation.h>
|
#include <AK/SourceLocation.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ public:
|
||||||
for (auto indent = m_depth++; indent > 0; indent--)
|
for (auto indent = m_depth++; indent > 0; indent--)
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
if (m_extra.is_empty())
|
if (m_extra.is_empty())
|
||||||
dbgln("\033[1;{}m{}entering {}\033[0m", m_depth % 8 + 30, sb.to_deprecated_string(), m_location);
|
dbgln("\033[1;{}m{}entering {}\033[0m", m_depth % 8 + 30, sb.to_byte_string(), m_location);
|
||||||
else
|
else
|
||||||
dbgln("\033[1;{}m{}entering {}\033[0m ({})", m_depth % 8 + 30, sb.to_deprecated_string(), m_location, m_extra);
|
dbgln("\033[1;{}m{}entering {}\033[0m ({})", m_depth % 8 + 30, sb.to_byte_string(), m_location, m_extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeLogger(SourceLocation location = SourceLocation::current())
|
ScopeLogger(SourceLocation location = SourceLocation::current())
|
||||||
|
@ -42,15 +42,15 @@ public:
|
||||||
for (auto indent = --m_depth; indent > 0; indent--)
|
for (auto indent = --m_depth; indent > 0; indent--)
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
if (m_extra.is_empty())
|
if (m_extra.is_empty())
|
||||||
dbgln("\033[1;{}m{}leaving {}\033[0m", depth % 8 + 30, sb.to_deprecated_string(), m_location);
|
dbgln("\033[1;{}m{}leaving {}\033[0m", depth % 8 + 30, sb.to_byte_string(), m_location);
|
||||||
else
|
else
|
||||||
dbgln("\033[1;{}m{}leaving {}\033[0m ({})", depth % 8 + 30, sb.to_deprecated_string(), m_location, m_extra);
|
dbgln("\033[1;{}m{}leaving {}\033[0m ({})", depth % 8 + 30, sb.to_byte_string(), m_location, m_extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline size_t m_depth = 0;
|
static inline size_t m_depth = 0;
|
||||||
SourceLocation m_location;
|
SourceLocation m_location;
|
||||||
DeprecatedString m_extra;
|
ByteString m_extra;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/GenericLexer.h>
|
#include <AK/GenericLexer.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
@ -116,12 +116,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: These are deprecated.
|
// FIXME: These are deprecated.
|
||||||
void set(StringView key, DeprecatedString value)
|
void set(StringView key, ByteString value)
|
||||||
{
|
{
|
||||||
set(key, MUST(String::from_deprecated_string(value)));
|
set(key, MUST(String::from_byte_string(value)));
|
||||||
}
|
}
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
void set(char const (&key)[N], DeprecatedString value)
|
void set(char const (&key)[N], ByteString value)
|
||||||
{
|
{
|
||||||
set(StringView { key, N - 1 }, value);
|
set(StringView { key, N - 1 }, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -621,14 +621,14 @@ void String::did_create_fly_string(Badge<FlyString>) const
|
||||||
m_data->set_fly_string(true);
|
m_data->set_fly_string(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString String::to_deprecated_string() const
|
ByteString String::to_byte_string() const
|
||||||
{
|
{
|
||||||
return DeprecatedString(bytes_as_string_view());
|
return ByteString(bytes_as_string_view());
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> String::from_deprecated_string(DeprecatedString const& deprecated_string)
|
ErrorOr<String> String::from_byte_string(ByteString const& byte_string)
|
||||||
{
|
{
|
||||||
return String::from_utf8(deprecated_string.view());
|
return String::from_utf8(byte_string.view());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::equals_ignoring_ascii_case(StringView other) const
|
bool String::equals_ignoring_ascii_case(StringView other) const
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
// Creates a new String from a sequence of UTF-8 encoded code points.
|
// Creates a new String from a sequence of UTF-8 encoded code points.
|
||||||
static ErrorOr<String> from_utf8(StringView);
|
static ErrorOr<String> from_utf8(StringView);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(IsOneOf<RemoveCVReference<T>, DeprecatedString, DeprecatedFlyString, FlyString, String>)
|
requires(IsOneOf<RemoveCVReference<T>, ByteString, DeprecatedFlyString, FlyString, String>)
|
||||||
static ErrorOr<String> from_utf8(T&&) = delete;
|
static ErrorOr<String> from_utf8(T&&) = delete;
|
||||||
|
|
||||||
// Creates a new String by reading byte_count bytes from a UTF-8 encoded Stream.
|
// Creates a new String by reading byte_count bytes from a UTF-8 encoded Stream.
|
||||||
|
@ -221,11 +221,11 @@ public:
|
||||||
void did_create_fly_string(Badge<FlyString>) const;
|
void did_create_fly_string(Badge<FlyString>) const;
|
||||||
|
|
||||||
// FIXME: Remove these once all code has been ported to String
|
// FIXME: Remove these once all code has been ported to String
|
||||||
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
[[nodiscard]] ByteString to_byte_string() const;
|
||||||
static ErrorOr<String> from_deprecated_string(DeprecatedString const&);
|
static ErrorOr<String> from_byte_string(ByteString const&);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(IsSame<RemoveCVReference<T>, StringView>)
|
requires(IsSame<RemoveCVReference<T>, StringView>)
|
||||||
static ErrorOr<String> from_deprecated_string(T&&) = delete;
|
static ErrorOr<String> from_byte_string(T&&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// NOTE: If the least significant bit of the pointer is set, this is a short string.
|
// NOTE: If the least significant bit of the pointer is set, this is a short string.
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <AK/Utf32View.h>
|
#include <AK/Utf32View.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
# include <AK/FlyString.h>
|
# include <AK/FlyString.h>
|
||||||
# include <AK/Utf16View.h>
|
# include <AK/Utf16View.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -144,11 +144,11 @@ ErrorOr<ByteBuffer> StringBuilder::to_byte_buffer() const
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
DeprecatedString StringBuilder::to_deprecated_string() const
|
ByteString StringBuilder::to_byte_string() const
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return DeprecatedString::empty();
|
return ByteString::empty();
|
||||||
return DeprecatedString((char const*)data(), length());
|
return ByteString((char const*)data(), length());
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> StringBuilder::to_string() const
|
ErrorOr<String> StringBuilder::to_string() const
|
||||||
|
|
|
@ -18,7 +18,7 @@ class StringBuilder {
|
||||||
public:
|
public:
|
||||||
static constexpr size_t inline_capacity = 256;
|
static constexpr size_t inline_capacity = 256;
|
||||||
|
|
||||||
using OutputType = DeprecatedString;
|
using OutputType = ByteString;
|
||||||
|
|
||||||
static ErrorOr<StringBuilder> create(size_t initial_capacity = inline_capacity);
|
static ErrorOr<StringBuilder> create(size_t initial_capacity = inline_capacity);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
[[nodiscard]] ByteString to_byte_string() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ErrorOr<String> to_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
# include <Kernel/Library/StdLib.h>
|
# include <Kernel/Library/StdLib.h>
|
||||||
#else
|
#else
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
# include <AK/FloatingPointStringConversions.h>
|
# include <AK/FloatingPointStringConversions.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -465,7 +465,7 @@ Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDire
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
DeprecatedString to_snakecase(StringView str)
|
ByteString to_snakecase(StringView str)
|
||||||
{
|
{
|
||||||
auto should_insert_underscore = [&](auto i, auto current_char) {
|
auto should_insert_underscore = [&](auto i, auto current_char) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
|
@ -488,10 +488,10 @@ DeprecatedString to_snakecase(StringView str)
|
||||||
builder.append('_');
|
builder.append('_');
|
||||||
builder.append_as_lowercase(ch);
|
builder.append_as_lowercase(ch);
|
||||||
}
|
}
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString to_titlecase(StringView str)
|
ByteString to_titlecase(StringView str)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
bool next_is_upper = true;
|
bool next_is_upper = true;
|
||||||
|
@ -504,10 +504,10 @@ DeprecatedString to_titlecase(StringView str)
|
||||||
next_is_upper = ch == ' ';
|
next_is_upper = ch == ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString invert_case(StringView str)
|
ByteString invert_case(StringView str)
|
||||||
{
|
{
|
||||||
StringBuilder builder(str.length());
|
StringBuilder builder(str.length());
|
||||||
|
|
||||||
|
@ -518,10 +518,10 @@ DeprecatedString invert_case(StringView str)
|
||||||
builder.append(to_ascii_lowercase(ch));
|
builder.append(to_ascii_lowercase(ch));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString replace(StringView str, StringView needle, StringView replacement, ReplaceMode replace_mode)
|
ByteString replace(StringView str, StringView needle, StringView replacement, ReplaceMode replace_mode)
|
||||||
{
|
{
|
||||||
if (str.is_empty())
|
if (str.is_empty())
|
||||||
return str;
|
return str;
|
||||||
|
@ -546,7 +546,7 @@ DeprecatedString replace(StringView str, StringView needle, StringView replaceme
|
||||||
last_position = position + needle.length();
|
last_position = position + needle.length();
|
||||||
}
|
}
|
||||||
replaced_string.append(str.substring_view(last_position, str.length() - last_position));
|
replaced_string.append(str.substring_view(last_position, str.length() - last_position));
|
||||||
return replaced_string.to_deprecated_string();
|
return replaced_string.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> replace(String const& haystack, StringView needle, StringView replacement, ReplaceMode replace_mode)
|
ErrorOr<String> replace(String const& haystack, StringView needle, StringView replacement, ReplaceMode replace_mode)
|
||||||
|
|
|
@ -106,11 +106,11 @@ enum class SearchDirection {
|
||||||
};
|
};
|
||||||
Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDirection);
|
Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDirection);
|
||||||
|
|
||||||
DeprecatedString to_snakecase(StringView);
|
ByteString to_snakecase(StringView);
|
||||||
DeprecatedString to_titlecase(StringView);
|
ByteString to_titlecase(StringView);
|
||||||
DeprecatedString invert_case(StringView);
|
ByteString invert_case(StringView);
|
||||||
|
|
||||||
DeprecatedString replace(StringView, StringView needle, StringView replacement, ReplaceMode);
|
ByteString replace(StringView, StringView needle, StringView replacement, ReplaceMode);
|
||||||
ErrorOr<String> replace(String const&, StringView needle, StringView replacement, ReplaceMode);
|
ErrorOr<String> replace(String const&, StringView needle, StringView replacement, ReplaceMode);
|
||||||
|
|
||||||
size_t count(StringView, StringView needle);
|
size_t count(StringView, StringView needle);
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
|
# include <AK/ByteString.h>
|
||||||
# include <AK/DeprecatedFlyString.h>
|
# include <AK/DeprecatedFlyString.h>
|
||||||
# include <AK/DeprecatedString.h>
|
|
||||||
# include <AK/FlyString.h>
|
# include <AK/FlyString.h>
|
||||||
# include <AK/String.h>
|
# include <AK/String.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -34,7 +34,7 @@ StringView::StringView(FlyString const& string)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView::StringView(DeprecatedString const& string)
|
StringView::StringView(ByteString const& string)
|
||||||
: m_characters(string.characters())
|
: m_characters(string.characters())
|
||||||
, m_length(string.length())
|
, m_length(string.length())
|
||||||
{
|
{
|
||||||
|
@ -176,17 +176,17 @@ bool StringView::equals_ignoring_ascii_case(StringView other) const
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
DeprecatedString StringView::to_lowercase_string() const
|
ByteString StringView::to_lowercase_string() const
|
||||||
{
|
{
|
||||||
return StringImpl::create_lowercased(characters_without_null_termination(), length()).release_nonnull();
|
return StringImpl::create_lowercased(characters_without_null_termination(), length()).release_nonnull();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString StringView::to_uppercase_string() const
|
ByteString StringView::to_uppercase_string() const
|
||||||
{
|
{
|
||||||
return StringImpl::create_uppercased(characters_without_null_termination(), length()).release_nonnull();
|
return StringImpl::create_uppercased(characters_without_null_termination(), length()).release_nonnull();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString StringView::to_titlecase_string() const
|
ByteString StringView::to_titlecase_string() const
|
||||||
{
|
{
|
||||||
return StringUtils::to_titlecase(*this);
|
return StringUtils::to_titlecase(*this);
|
||||||
}
|
}
|
||||||
|
@ -257,14 +257,14 @@ Optional<float> StringView::to_float(TrimWhitespace trim_whitespace) const
|
||||||
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
|
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringView::operator==(DeprecatedString const& string) const
|
bool StringView::operator==(ByteString const& string) const
|
||||||
{
|
{
|
||||||
return *this == string.view();
|
return *this == string.view();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString StringView::to_deprecated_string() const { return DeprecatedString { *this }; }
|
ByteString StringView::to_byte_string() const { return ByteString { *this }; }
|
||||||
|
|
||||||
DeprecatedString StringView::replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const
|
ByteString StringView::replace(StringView needle, StringView replacement, ReplaceMode replace_mode) const
|
||||||
{
|
{
|
||||||
return StringUtils::replace(*this, needle, replacement, replace_mode);
|
return StringUtils::replace(*this, needle, replacement, replace_mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
StringView(String const&);
|
StringView(String const&);
|
||||||
StringView(FlyString const&);
|
StringView(FlyString const&);
|
||||||
StringView(DeprecatedString const&);
|
StringView(ByteString const&);
|
||||||
StringView(DeprecatedFlyString const&);
|
StringView(DeprecatedFlyString const&);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -58,11 +58,11 @@ public:
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
explicit StringView(String&&) = delete;
|
explicit StringView(String&&) = delete;
|
||||||
explicit StringView(FlyString&&) = delete;
|
explicit StringView(FlyString&&) = delete;
|
||||||
explicit StringView(DeprecatedString&&) = delete;
|
explicit StringView(ByteString&&) = delete;
|
||||||
explicit StringView(DeprecatedFlyString&&) = delete;
|
explicit StringView(DeprecatedFlyString&&) = delete;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<OneOf<String, FlyString, DeprecatedString, DeprecatedFlyString, ByteBuffer> StringType>
|
template<OneOf<String, FlyString, ByteString, DeprecatedFlyString, ByteBuffer> StringType>
|
||||||
StringView& operator=(StringType&&) = delete;
|
StringView& operator=(StringType&&) = delete;
|
||||||
|
|
||||||
[[nodiscard]] constexpr bool is_null() const
|
[[nodiscard]] constexpr bool is_null() const
|
||||||
|
@ -110,9 +110,9 @@ public:
|
||||||
[[nodiscard]] StringView trim_whitespace(TrimMode mode = TrimMode::Both) const { return StringUtils::trim_whitespace(*this, mode); }
|
[[nodiscard]] StringView trim_whitespace(TrimMode mode = TrimMode::Both) const { return StringUtils::trim_whitespace(*this, mode); }
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
[[nodiscard]] DeprecatedString to_lowercase_string() const;
|
[[nodiscard]] ByteString to_lowercase_string() const;
|
||||||
[[nodiscard]] DeprecatedString to_uppercase_string() const;
|
[[nodiscard]] ByteString to_uppercase_string() const;
|
||||||
[[nodiscard]] DeprecatedString to_titlecase_string() const;
|
[[nodiscard]] ByteString to_titlecase_string() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const
|
[[nodiscard]] Optional<size_t> find(char needle, size_t start = 0) const
|
||||||
|
@ -272,7 +272,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
bool operator==(DeprecatedString const&) const;
|
bool operator==(ByteString const&) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] constexpr int compare(StringView other) const
|
[[nodiscard]] constexpr int compare(StringView other) const
|
||||||
|
@ -314,7 +314,7 @@ public:
|
||||||
constexpr bool operator>=(StringView other) const { return compare(other) >= 0; }
|
constexpr bool operator>=(StringView other) const { return compare(other) >= 0; }
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
[[nodiscard]] ByteString to_byte_string() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] bool is_whitespace() const
|
[[nodiscard]] bool is_whitespace() const
|
||||||
|
@ -323,7 +323,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
[[nodiscard]] DeprecatedString replace(StringView needle, StringView replacement, ReplaceMode) const;
|
[[nodiscard]] ByteString replace(StringView needle, StringView replacement, ReplaceMode) const;
|
||||||
#endif
|
#endif
|
||||||
[[nodiscard]] size_t count(StringView needle) const
|
[[nodiscard]] size_t count(StringView needle) const
|
||||||
{
|
{
|
||||||
|
@ -354,7 +354,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class DeprecatedString;
|
friend class ByteString;
|
||||||
char const* m_characters { nullptr };
|
char const* m_characters { nullptr };
|
||||||
size_t m_length { 0 };
|
size_t m_length { 0 };
|
||||||
};
|
};
|
||||||
|
|
66
AK/URL.cpp
66
AK/URL.cpp
|
@ -38,21 +38,21 @@ URL URL::complete_url(StringView relative_url) const
|
||||||
|
|
||||||
ErrorOr<String> URL::username() const
|
ErrorOr<String> URL::username() const
|
||||||
{
|
{
|
||||||
return String::from_deprecated_string(percent_decode(m_username));
|
return String::from_byte_string(percent_decode(m_username));
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> URL::password() const
|
ErrorOr<String> URL::password() const
|
||||||
{
|
{
|
||||||
return String::from_deprecated_string(percent_decode(m_password));
|
return String::from_byte_string(percent_decode(m_password));
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString URL::path_segment_at_index(size_t index) const
|
ByteString URL::path_segment_at_index(size_t index) const
|
||||||
{
|
{
|
||||||
VERIFY(index < path_segment_count());
|
VERIFY(index < path_segment_count());
|
||||||
return percent_decode(m_paths[index]);
|
return percent_decode(m_paths[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString URL::basename() const
|
ByteString URL::basename() const
|
||||||
{
|
{
|
||||||
if (!m_valid)
|
if (!m_valid)
|
||||||
return {};
|
return {};
|
||||||
|
@ -72,7 +72,7 @@ void URL::set_scheme(String scheme)
|
||||||
ErrorOr<void> URL::set_username(StringView username)
|
ErrorOr<void> URL::set_username(StringView username)
|
||||||
{
|
{
|
||||||
// To set the username given a url and username, set url’s username to the result of running UTF-8 percent-encode on username using the userinfo percent-encode set.
|
// To set the username given a url and username, set url’s username to the result of running UTF-8 percent-encode on username using the userinfo percent-encode set.
|
||||||
m_username = TRY(String::from_deprecated_string(percent_encode(username, PercentEncodeSet::Userinfo)));
|
m_username = TRY(String::from_byte_string(percent_encode(username, PercentEncodeSet::Userinfo)));
|
||||||
m_valid = compute_validity();
|
m_valid = compute_validity();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ ErrorOr<void> URL::set_username(StringView username)
|
||||||
ErrorOr<void> URL::set_password(StringView password)
|
ErrorOr<void> URL::set_password(StringView password)
|
||||||
{
|
{
|
||||||
// To set the password given a url and password, set url’s password to the result of running UTF-8 percent-encode on password using the userinfo percent-encode set.
|
// To set the password given a url and password, set url’s password to the result of running UTF-8 percent-encode on password using the userinfo percent-encode set.
|
||||||
m_password = TRY(String::from_deprecated_string(percent_encode(password, PercentEncodeSet::Userinfo)));
|
m_password = TRY(String::from_byte_string(percent_encode(password, PercentEncodeSet::Userinfo)));
|
||||||
m_valid = compute_validity();
|
m_valid = compute_validity();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -108,18 +108,18 @@ void URL::set_port(Optional<u16> port)
|
||||||
m_valid = compute_validity();
|
m_valid = compute_validity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void URL::set_paths(Vector<DeprecatedString> const& paths)
|
void URL::set_paths(Vector<ByteString> const& paths)
|
||||||
{
|
{
|
||||||
m_paths.clear_with_capacity();
|
m_paths.clear_with_capacity();
|
||||||
m_paths.ensure_capacity(paths.size());
|
m_paths.ensure_capacity(paths.size());
|
||||||
for (auto const& segment : paths)
|
for (auto const& segment : paths)
|
||||||
m_paths.unchecked_append(String::from_deprecated_string(percent_encode(segment, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
|
m_paths.unchecked_append(String::from_byte_string(percent_encode(segment, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
|
||||||
m_valid = compute_validity();
|
m_valid = compute_validity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void URL::append_path(StringView path)
|
void URL::append_path(StringView path)
|
||||||
{
|
{
|
||||||
m_paths.append(String::from_deprecated_string(percent_encode(path, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
|
m_paths.append(String::from_byte_string(percent_encode(path, PercentEncodeSet::Path)).release_value_but_fixme_should_propagate_errors());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
|
// https://url.spec.whatwg.org/#cannot-have-a-username-password-port
|
||||||
|
@ -182,7 +182,7 @@ Optional<u16> URL::default_port_for_scheme(StringView scheme)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString const& fragment, DeprecatedString const& hostname)
|
URL URL::create_with_file_scheme(ByteString const& path, ByteString const& fragment, ByteString const& hostname)
|
||||||
{
|
{
|
||||||
LexicalPath lexical_path(path);
|
LexicalPath lexical_path(path);
|
||||||
if (!lexical_path.is_absolute())
|
if (!lexical_path.is_absolute())
|
||||||
|
@ -190,38 +190,38 @@ URL URL::create_with_file_scheme(DeprecatedString const& path, DeprecatedString
|
||||||
|
|
||||||
URL url;
|
URL url;
|
||||||
url.set_scheme("file"_string);
|
url.set_scheme("file"_string);
|
||||||
url.set_host(hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
|
url.set_host(hostname == "localhost" ? String {} : String::from_byte_string(hostname).release_value_but_fixme_should_propagate_errors());
|
||||||
url.set_paths(lexical_path.parts());
|
url.set_paths(lexical_path.parts());
|
||||||
if (path.ends_with('/'))
|
if (path.ends_with('/'))
|
||||||
url.append_slash();
|
url.append_slash();
|
||||||
if (!fragment.is_empty())
|
if (!fragment.is_empty())
|
||||||
url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors());
|
url.set_fragment(String::from_byte_string(fragment).release_value_but_fixme_should_propagate_errors());
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
URL URL::create_with_help_scheme(DeprecatedString const& path, DeprecatedString const& fragment, DeprecatedString const& hostname)
|
URL URL::create_with_help_scheme(ByteString const& path, ByteString const& fragment, ByteString const& hostname)
|
||||||
{
|
{
|
||||||
LexicalPath lexical_path(path);
|
LexicalPath lexical_path(path);
|
||||||
|
|
||||||
URL url;
|
URL url;
|
||||||
url.set_scheme("help"_string);
|
url.set_scheme("help"_string);
|
||||||
url.set_host(hostname == "localhost" ? String {} : String::from_deprecated_string(hostname).release_value_but_fixme_should_propagate_errors());
|
url.set_host(hostname == "localhost" ? String {} : String::from_byte_string(hostname).release_value_but_fixme_should_propagate_errors());
|
||||||
|
|
||||||
url.set_paths(lexical_path.parts());
|
url.set_paths(lexical_path.parts());
|
||||||
if (path.ends_with('/'))
|
if (path.ends_with('/'))
|
||||||
url.append_slash();
|
url.append_slash();
|
||||||
if (!fragment.is_empty())
|
if (!fragment.is_empty())
|
||||||
url.set_fragment(String::from_deprecated_string(fragment).release_value_but_fixme_should_propagate_errors());
|
url.set_fragment(String::from_byte_string(fragment).release_value_but_fixme_should_propagate_errors());
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
URL URL::create_with_url_or_path(DeprecatedString const& url_or_path)
|
URL URL::create_with_url_or_path(ByteString const& url_or_path)
|
||||||
{
|
{
|
||||||
URL url = url_or_path;
|
URL url = url_or_path;
|
||||||
if (url.is_valid())
|
if (url.is_valid())
|
||||||
return url;
|
return url;
|
||||||
|
|
||||||
DeprecatedString path = LexicalPath::canonicalized_path(url_or_path);
|
ByteString path = LexicalPath::canonicalized_path(url_or_path);
|
||||||
return URL::create_with_file_scheme(path);
|
return URL::create_with_file_scheme(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ URL URL::create_with_data(StringView mime_type, StringView payload, bool is_base
|
||||||
builder.append(";base64"sv);
|
builder.append(";base64"sv);
|
||||||
builder.append(',');
|
builder.append(',');
|
||||||
builder.append(payload);
|
builder.append(payload);
|
||||||
url.set_paths({ builder.to_deprecated_string() });
|
url.set_paths({ builder.to_byte_string() });
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,12 +248,12 @@ bool URL::is_special_scheme(StringView scheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#url-path-serializer
|
// https://url.spec.whatwg.org/#url-path-serializer
|
||||||
DeprecatedString URL::serialize_path(ApplyPercentDecoding apply_percent_decoding) const
|
ByteString URL::serialize_path(ApplyPercentDecoding apply_percent_decoding) const
|
||||||
{
|
{
|
||||||
// 1. If url has an opaque path, then return url’s path.
|
// 1. If url has an opaque path, then return url’s path.
|
||||||
// FIXME: Reimplement this step once we modernize the URL implementation to meet the spec.
|
// FIXME: Reimplement this step once we modernize the URL implementation to meet the spec.
|
||||||
if (cannot_be_a_base_url())
|
if (cannot_be_a_base_url())
|
||||||
return m_paths[0].to_deprecated_string();
|
return m_paths[0].to_byte_string();
|
||||||
|
|
||||||
// 2. Let output be the empty string.
|
// 2. Let output be the empty string.
|
||||||
StringBuilder output;
|
StringBuilder output;
|
||||||
|
@ -261,15 +261,15 @@ DeprecatedString URL::serialize_path(ApplyPercentDecoding apply_percent_decoding
|
||||||
// 3. For each segment of url’s path: append U+002F (/) followed by segment to output.
|
// 3. For each segment of url’s path: append U+002F (/) followed by segment to output.
|
||||||
for (auto const& segment : m_paths) {
|
for (auto const& segment : m_paths) {
|
||||||
output.append('/');
|
output.append('/');
|
||||||
output.append(apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(segment) : segment.to_deprecated_string());
|
output.append(apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(segment) : segment.to_byte_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Return output.
|
// 4. Return output.
|
||||||
return output.to_deprecated_string();
|
return output.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#concept-url-serializer
|
// https://url.spec.whatwg.org/#concept-url-serializer
|
||||||
DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
|
ByteString URL::serialize(ExcludeFragment exclude_fragment) const
|
||||||
{
|
{
|
||||||
// 1. Let output be url’s scheme and U+003A (:) concatenated.
|
// 1. Let output be url’s scheme and U+003A (:) concatenated.
|
||||||
StringBuilder output;
|
StringBuilder output;
|
||||||
|
@ -331,14 +331,14 @@ DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Return output.
|
// 7. Return output.
|
||||||
return output.to_deprecated_string();
|
return output.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#url-rendering
|
// https://url.spec.whatwg.org/#url-rendering
|
||||||
// NOTE: This does e.g. not display credentials.
|
// 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
|
// 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.
|
// resulting from percent-decoding those sequences converted to bytes, unless that renders those sequences invisible.
|
||||||
DeprecatedString URL::serialize_for_display() const
|
ByteString URL::serialize_for_display() const
|
||||||
{
|
{
|
||||||
VERIFY(m_valid);
|
VERIFY(m_valid);
|
||||||
|
|
||||||
|
@ -374,17 +374,17 @@ DeprecatedString URL::serialize_for_display() const
|
||||||
builder.append(*m_fragment);
|
builder.append(*m_fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> URL::to_string() const
|
ErrorOr<String> URL::to_string() const
|
||||||
{
|
{
|
||||||
return String::from_deprecated_string(serialize());
|
return String::from_byte_string(serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin
|
// https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin
|
||||||
// https://url.spec.whatwg.org/#concept-url-origin
|
// https://url.spec.whatwg.org/#concept-url-origin
|
||||||
DeprecatedString URL::serialize_origin() const
|
ByteString URL::serialize_origin() const
|
||||||
{
|
{
|
||||||
VERIFY(m_valid);
|
VERIFY(m_valid);
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ DeprecatedString URL::serialize_origin() const
|
||||||
builder.append(serialized_host().release_value_but_fixme_should_propagate_errors());
|
builder.append(serialized_host().release_value_but_fixme_should_propagate_errors());
|
||||||
if (m_port.has_value())
|
if (m_port.has_value())
|
||||||
builder.appendff(":{}", *m_port);
|
builder.appendff(":{}", *m_port);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool URL::equals(URL const& other, ExcludeFragment exclude_fragments) const
|
bool URL::equals(URL const& other, ExcludeFragment exclude_fragments) const
|
||||||
|
@ -544,7 +544,7 @@ void URL::append_percent_encoded_if_necessary(StringBuilder& builder, u32 code_p
|
||||||
builder.append_code_point(code_point);
|
builder.append_code_point(code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString URL::percent_encode(StringView input, URL::PercentEncodeSet set, SpaceAsPlus space_as_plus)
|
ByteString URL::percent_encode(StringView input, URL::PercentEncodeSet set, SpaceAsPlus space_as_plus)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (auto code_point : Utf8View(input)) {
|
for (auto code_point : Utf8View(input)) {
|
||||||
|
@ -553,10 +553,10 @@ DeprecatedString URL::percent_encode(StringView input, URL::PercentEncodeSet set
|
||||||
else
|
else
|
||||||
append_percent_encoded_if_necessary(builder, code_point, set);
|
append_percent_encoded_if_necessary(builder, code_point, set);
|
||||||
}
|
}
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString URL::percent_decode(StringView input)
|
ByteString URL::percent_decode(StringView input)
|
||||||
{
|
{
|
||||||
if (!input.contains('%'))
|
if (!input.contains('%'))
|
||||||
return input;
|
return input;
|
||||||
|
@ -575,7 +575,7 @@ DeprecatedString URL::percent_decode(StringView input)
|
||||||
builder.append(byte);
|
builder.append(byte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
32
AK/URL.h
32
AK/URL.h
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
URL() = default;
|
URL() = default;
|
||||||
URL(StringView);
|
URL(StringView);
|
||||||
URL(DeprecatedString const& string)
|
URL(ByteString const& string)
|
||||||
: URL(string.view())
|
: URL(string.view())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,11 @@ public:
|
||||||
ErrorOr<String> password() const;
|
ErrorOr<String> password() const;
|
||||||
Host const& host() const { return m_host; }
|
Host const& host() const { return m_host; }
|
||||||
ErrorOr<String> serialized_host() const;
|
ErrorOr<String> serialized_host() const;
|
||||||
DeprecatedString basename() const;
|
ByteString basename() const;
|
||||||
Optional<String> const& query() const { return m_query; }
|
Optional<String> const& query() const { return m_query; }
|
||||||
Optional<String> const& fragment() const { return m_fragment; }
|
Optional<String> const& fragment() const { return m_fragment; }
|
||||||
Optional<u16> port() const { return m_port; }
|
Optional<u16> port() const { return m_port; }
|
||||||
DeprecatedString path_segment_at_index(size_t index) const;
|
ByteString path_segment_at_index(size_t index) const;
|
||||||
size_t path_segment_count() const { return m_paths.size(); }
|
size_t path_segment_count() const { return m_paths.size(); }
|
||||||
|
|
||||||
u16 port_or_default() const { return m_port.value_or(default_port_for_scheme(m_scheme).value_or(0)); }
|
u16 port_or_default() const { return m_port.value_or(default_port_for_scheme(m_scheme).value_or(0)); }
|
||||||
|
@ -96,7 +96,7 @@ public:
|
||||||
ErrorOr<void> set_password(StringView);
|
ErrorOr<void> set_password(StringView);
|
||||||
void set_host(Host);
|
void set_host(Host);
|
||||||
void set_port(Optional<u16>);
|
void set_port(Optional<u16>);
|
||||||
void set_paths(Vector<DeprecatedString> const&);
|
void set_paths(Vector<ByteString> const&);
|
||||||
void set_query(Optional<String> query) { m_query = move(query); }
|
void set_query(Optional<String> query) { m_query = move(query); }
|
||||||
void set_fragment(Optional<String> fragment) { m_fragment = move(fragment); }
|
void set_fragment(Optional<String> fragment) { m_fragment = move(fragment); }
|
||||||
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; }
|
void set_cannot_be_a_base_url(bool value) { m_cannot_be_a_base_url = value; }
|
||||||
|
@ -111,14 +111,14 @@ public:
|
||||||
Yes,
|
Yes,
|
||||||
No
|
No
|
||||||
};
|
};
|
||||||
DeprecatedString serialize_path(ApplyPercentDecoding = ApplyPercentDecoding::Yes) const;
|
ByteString serialize_path(ApplyPercentDecoding = ApplyPercentDecoding::Yes) const;
|
||||||
DeprecatedString serialize(ExcludeFragment = ExcludeFragment::No) const;
|
ByteString serialize(ExcludeFragment = ExcludeFragment::No) const;
|
||||||
DeprecatedString serialize_for_display() const;
|
ByteString serialize_for_display() const;
|
||||||
DeprecatedString to_deprecated_string() const { return serialize(); }
|
ByteString to_byte_string() const { return serialize(); }
|
||||||
ErrorOr<String> to_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
|
|
||||||
// HTML origin
|
// HTML origin
|
||||||
DeprecatedString serialize_origin() const;
|
ByteString serialize_origin() const;
|
||||||
|
|
||||||
bool equals(URL const& other, ExcludeFragment = ExcludeFragment::No) const;
|
bool equals(URL const& other, ExcludeFragment = ExcludeFragment::No) const;
|
||||||
|
|
||||||
|
@ -130,9 +130,9 @@ public:
|
||||||
};
|
};
|
||||||
ErrorOr<DataURL> process_data_url() const;
|
ErrorOr<DataURL> process_data_url() const;
|
||||||
|
|
||||||
static URL create_with_url_or_path(DeprecatedString const&);
|
static URL create_with_url_or_path(ByteString const&);
|
||||||
static URL create_with_file_scheme(DeprecatedString const& path, DeprecatedString const& fragment = {}, DeprecatedString const& hostname = {});
|
static URL create_with_file_scheme(ByteString const& path, ByteString const& fragment = {}, ByteString const& hostname = {});
|
||||||
static URL create_with_help_scheme(DeprecatedString const& path, DeprecatedString const& fragment = {}, DeprecatedString const& hostname = {});
|
static URL create_with_help_scheme(ByteString const& path, ByteString const& fragment = {}, ByteString const& hostname = {});
|
||||||
static URL create_with_data(StringView mime_type, StringView payload, bool is_base64 = false);
|
static URL create_with_data(StringView mime_type, StringView payload, bool is_base64 = false);
|
||||||
|
|
||||||
static Optional<u16> default_port_for_scheme(StringView);
|
static Optional<u16> default_port_for_scheme(StringView);
|
||||||
|
@ -142,8 +142,8 @@ public:
|
||||||
No,
|
No,
|
||||||
Yes,
|
Yes,
|
||||||
};
|
};
|
||||||
static DeprecatedString percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo, SpaceAsPlus = SpaceAsPlus::No);
|
static ByteString percent_encode(StringView input, PercentEncodeSet set = PercentEncodeSet::Userinfo, SpaceAsPlus = SpaceAsPlus::No);
|
||||||
static DeprecatedString percent_decode(StringView input);
|
static ByteString percent_decode(StringView input);
|
||||||
|
|
||||||
bool operator==(URL const& other) const { return equals(other, ExcludeFragment::No); }
|
bool operator==(URL const& other) const { return equals(other, ExcludeFragment::No); }
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ struct Formatter<URL> : Formatter<StringView> {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Traits<URL> : public DefaultTraits<URL> {
|
struct Traits<URL> : public DefaultTraits<URL> {
|
||||||
static unsigned hash(URL const& url) { return url.to_deprecated_string().hash(); }
|
static unsigned hash(URL const& url) { return url.to_byte_string().hash(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/Debug.h>
|
#include <AK/Debug.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/IntegralMath.h>
|
#include <AK/IntegralMath.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/SourceLocation.h>
|
#include <AK/SourceLocation.h>
|
||||||
|
@ -57,7 +57,7 @@ static Optional<URL::Host> parse_opaque_host(StringView input)
|
||||||
// currently report validation errors, they are only useful for debugging efforts in the URL parsing code.
|
// currently report validation errors, they are only useful for debugging efforts in the URL parsing code.
|
||||||
|
|
||||||
// 4. Return the result of running UTF-8 percent-encode on input using the C0 control percent-encode set.
|
// 4. Return the result of running UTF-8 percent-encode on input using the C0 control percent-encode set.
|
||||||
return String::from_deprecated_string(URL::percent_encode(input, URL::PercentEncodeSet::C0Control)).release_value_but_fixme_should_propagate_errors();
|
return String::from_byte_string(URL::percent_encode(input, URL::PercentEncodeSet::C0Control)).release_value_but_fixme_should_propagate_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ParsedIPv4Number {
|
struct ParsedIPv4Number {
|
||||||
|
@ -606,7 +606,7 @@ static Optional<URL::Host> parse_host(StringView input, bool is_opaque = false)
|
||||||
// NOTE: This is handled in Unicode::create_unicode_url, to work around the fact that we can't call into LibUnicode here
|
// NOTE: This is handled in Unicode::create_unicode_url, to work around the fact that we can't call into LibUnicode here
|
||||||
// FIXME: 5. Let asciiDomain be the result of running domain to ASCII with domain and false.
|
// FIXME: 5. Let asciiDomain be the result of running domain to ASCII with domain and false.
|
||||||
// FIXME: 6. If asciiDomain is failure, then return failure.
|
// FIXME: 6. If asciiDomain is failure, then return failure.
|
||||||
auto ascii_domain_or_error = String::from_deprecated_string(domain);
|
auto ascii_domain_or_error = String::from_byte_string(domain);
|
||||||
if (ascii_domain_or_error.is_error())
|
if (ascii_domain_or_error.is_error())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -792,7 +792,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
||||||
if (start_index >= end_index)
|
if (start_index >= end_index)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
DeprecatedString processed_input = raw_input.substring_view(start_index, end_index - start_index);
|
ByteString processed_input = raw_input.substring_view(start_index, end_index - start_index);
|
||||||
|
|
||||||
// 2. If input contains any ASCII tab or newline, invalid-URL-unit validation error.
|
// 2. If input contains any ASCII tab or newline, invalid-URL-unit validation error.
|
||||||
// 3. Remove all ASCII tab or newline from input.
|
// 3. Remove all ASCII tab or newline from input.
|
||||||
|
@ -1116,7 +1116,7 @@ URL URLParser::basic_parse(StringView raw_input, Optional<URL> const& base_url,
|
||||||
|
|
||||||
// 2. If atSignSeen is true, then prepend "%40" to buffer.
|
// 2. If atSignSeen is true, then prepend "%40" to buffer.
|
||||||
if (at_sign_seen) {
|
if (at_sign_seen) {
|
||||||
auto content = buffer.to_deprecated_string();
|
auto content = buffer.to_byte_string();
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
buffer.append("%40"sv);
|
buffer.append("%40"sv);
|
||||||
buffer.append(content);
|
buffer.append(content);
|
||||||
|
|
|
@ -81,9 +81,9 @@ u32 Utf16View::decode_surrogate_pair(u16 high_surrogate, u16 low_surrogate)
|
||||||
return ((high_surrogate - high_surrogate_min) << 10) + (low_surrogate - low_surrogate_min) + first_supplementary_plane_code_point;
|
return ((high_surrogate - high_surrogate_min) << 10) + (low_surrogate - low_surrogate_min) + first_supplementary_plane_code_point;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<DeprecatedString> Utf16View::to_deprecated_string(AllowInvalidCodeUnits allow_invalid_code_units) const
|
ErrorOr<ByteString> Utf16View::to_byte_string(AllowInvalidCodeUnits allow_invalid_code_units) const
|
||||||
{
|
{
|
||||||
return TRY(to_utf8(allow_invalid_code_units)).to_deprecated_string();
|
return TRY(to_utf8(allow_invalid_code_units)).to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<String> Utf16View::to_utf8(AllowInvalidCodeUnits allow_invalid_code_units) const
|
ErrorOr<String> Utf16View::to_utf8(AllowInvalidCodeUnits allow_invalid_code_units) const
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
No,
|
No,
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorOr<DeprecatedString> to_deprecated_string(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
|
ErrorOr<ByteString> to_byte_string(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
|
||||||
ErrorOr<String> to_utf8(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
|
ErrorOr<String> to_utf8(AllowInvalidCodeUnits = AllowInvalidCodeUnits::No) const;
|
||||||
|
|
||||||
bool is_null() const { return m_code_units.is_null(); }
|
bool is_null() const { return m_code_units.is_null(); }
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
# include <AK/DeprecatedString.h>
|
# include <AK/ByteString.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -72,12 +72,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
explicit Utf8View(DeprecatedString& string)
|
explicit Utf8View(ByteString& string)
|
||||||
: m_string(string.view())
|
: m_string(string.view())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Utf8View(DeprecatedString&&) = delete;
|
explicit Utf8View(ByteString&&) = delete;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
~Utf8View() = default;
|
~Utf8View() = default;
|
||||||
|
@ -255,14 +255,14 @@ public:
|
||||||
return Utf8View(m_string).byte_offset_of(m_it);
|
return Utf8View(m_string).byte_offset_of(m_it);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedStringCodePointIterator(DeprecatedString string)
|
DeprecatedStringCodePointIterator(ByteString string)
|
||||||
: m_string(move(string))
|
: m_string(move(string))
|
||||||
, m_it(Utf8View(m_string).begin())
|
, m_it(Utf8View(m_string).begin())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeprecatedString m_string;
|
ByteString m_string;
|
||||||
Utf8CodePointIterator m_it;
|
Utf8CodePointIterator m_it;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,17 +5,17 @@ clipboard - Data formats specific to Clipboard and drag & drop
|
||||||
## Clipboard
|
## Clipboard
|
||||||
|
|
||||||
The clipboard feature works through the Clipboard server, which generally acts as a global storage or three things:
|
The clipboard feature works through the Clipboard server, which generally acts as a global storage or three things:
|
||||||
- a `DeprecatedString` mime type,
|
- a `ByteString` mime type,
|
||||||
- a (potentially large) block of data, shared as an anonymous file,
|
- a (potentially large) block of data, shared as an anonymous file,
|
||||||
- a `HashMap<DeprecatedString, DeprecatedString>` of arbitrary metadata, depending on the mime type.
|
- a `HashMap<ByteString, ByteString>` of arbitrary metadata, depending on the mime type.
|
||||||
|
|
||||||
See also [`Userland/Libraries/LibGUI/Clipboard.h`](../../../../../Userland/Libraries/LibGUI/Clipboard.h).
|
See also [`Userland/Libraries/LibGUI/Clipboard.h`](../../../../../Userland/Libraries/LibGUI/Clipboard.h).
|
||||||
|
|
||||||
## Drag & drop
|
## Drag & drop
|
||||||
|
|
||||||
In contrast to the clipboard, the drag & drop feature works through WindowServer, and a bouquet of data is transmitted:
|
In contrast to the clipboard, the drag & drop feature works through WindowServer, and a bouquet of data is transmitted:
|
||||||
- a `[UTF8] DeprecatedString` to be displayed while dragging,
|
- a `[UTF8] ByteString` to be displayed while dragging,
|
||||||
- a `HashMap<DeprecatedString, ByteBuffer>` map that contains arbitrary data for a variety of possible mime types,
|
- a `HashMap<ByteString, ByteBuffer>` map that contains arbitrary data for a variety of possible mime types,
|
||||||
- a `Gfx::ShareableBitmap` to be displayed while dragging
|
- a `Gfx::ShareableBitmap` to be displayed while dragging
|
||||||
|
|
||||||
Drag & drop is most prominently supported by File Manager, Spreadsheet, and Terminal.
|
Drag & drop is most prominently supported by File Manager, Spreadsheet, and Terminal.
|
||||||
|
|
|
@ -91,7 +91,7 @@ Start from defining an endpoint in the IPC file in `MyServer.ipc`.
|
||||||
```ipc
|
```ipc
|
||||||
endpoint MyServer
|
endpoint MyServer
|
||||||
{
|
{
|
||||||
SyncAPI(DeprecatedString text) => (i32 status)
|
SyncAPI(ByteString text) => (i32 status)
|
||||||
AsyncAPI(i32 mode) =|
|
AsyncAPI(i32 mode) =|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -102,7 +102,7 @@ Part of the generated C++ messages:
|
||||||
class SyncAPI final : public IPC::Message {
|
class SyncAPI final : public IPC::Message {
|
||||||
public:
|
public:
|
||||||
using ResponseType = SyncAPIResponse;
|
using ResponseType = SyncAPIResponse;
|
||||||
SyncAPI(const DeprecatedString& text) : m_text(text) {}
|
SyncAPI(const ByteString& text) : m_text(text) {}
|
||||||
virtual ~SyncAPI() override {}
|
virtual ~SyncAPI() override {}
|
||||||
static OwnPtr<SyncAPI> decode(...);
|
static OwnPtr<SyncAPI> decode(...);
|
||||||
virtual IPC::MessageBuffer encode(...) const override;
|
virtual IPC::MessageBuffer encode(...) const override;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# String Formatting
|
# String Formatting
|
||||||
|
|
||||||
Many places in Serenity allow you to format strings, similar to `printf()`, for example `DeprecatedString::formatted()`
|
Many places in Serenity allow you to format strings, similar to `printf()`, for example `ByteString::formatted()`
|
||||||
, `StringBuilder::appendff()`, or `dbgln()`. These are checked at compile time to ensure the format string matches the
|
, `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
|
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)
|
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:
|
form, in order:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
DeprecatedString::formatted("Well, {} my {} friends!", "hello", 42) == "Well, hello my 42 friends!";
|
ByteString::formatted("Well, {} my {} friends!", "hello", 42) == "Well, hello my 42 friends!";
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to include a literal `{` in the output, use `{{`:
|
If you want to include a literal `{` in the output, use `{{`:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
DeprecatedString::formatted("{{ {}", "hello") == "{ hello";
|
ByteString::formatted("{{ {}", "hello") == "{ hello";
|
||||||
```
|
```
|
||||||
|
|
||||||
You can refer to the arguments by index, if you want to repeat one or change the order:
|
You can refer to the arguments by index, if you want to repeat one or change the order:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
DeprecatedString::formatted("{2}{0}{1}", "a", "b", "c") == "cab";
|
ByteString::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
|
To control how the arguments are formatted, add colon after the optional index, and then add format specifier
|
||||||
characters:
|
characters:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
DeprecatedString::formatted("{:.4}", "cool dude") == "cool";
|
ByteString::formatted("{:.4}", "cool dude") == "cool";
|
||||||
DeprecatedString::formatted("{0:.4}", "cool dude") == "cool";
|
ByteString::formatted("{0:.4}", "cool dude") == "cool";
|
||||||
```
|
```
|
||||||
|
|
||||||
## Format specifiers
|
## Format specifiers
|
||||||
|
@ -135,6 +135,6 @@ type cannot be formatted. For example:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
// B has a Formatter defined, but A does not.
|
// B has a Formatter defined, but A does not.
|
||||||
DeprecatedString::formatted("{}", FormatIfSupported { A {} }) == "?";
|
ByteString::formatted("{}", FormatIfSupported { A {} }) == "?";
|
||||||
DeprecatedString::formatted("{}", FormatIfSupported { B {} }) == "B";
|
ByteString::formatted("{}", FormatIfSupported { B {} }) == "B";
|
||||||
```
|
```
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "ALooperEventLoopImplementation.h"
|
#include "ALooperEventLoopImplementation.h"
|
||||||
#include "JNIHelpers.h"
|
#include "JNIHelpers.h"
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/LexicalPath.h>
|
#include <AK/LexicalPath.h>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
static ErrorOr<void> extract_tar_archive(String archive_file, DeprecatedString output_directory);
|
static ErrorOr<void> extract_tar_archive(String archive_file, ByteString output_directory);
|
||||||
|
|
||||||
JavaVM* global_vm;
|
JavaVM* global_vm;
|
||||||
static OwnPtr<Core::EventLoop> s_main_event_loop;
|
static OwnPtr<Core::EventLoop> s_main_event_loop;
|
||||||
|
@ -89,29 +89,29 @@ Java_org_serenityos_ladybird_LadybirdActivity_disposeNativeCode(JNIEnv* env, job
|
||||||
delete &Core::EventLoopManager::the();
|
delete &Core::EventLoopManager::the();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> extract_tar_archive(String archive_file, DeprecatedString output_directory)
|
ErrorOr<void> extract_tar_archive(String archive_file, ByteString output_directory)
|
||||||
{
|
{
|
||||||
constexpr size_t buffer_size = 4096;
|
constexpr size_t buffer_size = 4096;
|
||||||
|
|
||||||
auto file = TRY(Core::InputBufferedFile::create(TRY(Core::File::open(archive_file, Core::File::OpenMode::Read))));
|
auto file = TRY(Core::InputBufferedFile::create(TRY(Core::File::open(archive_file, Core::File::OpenMode::Read))));
|
||||||
|
|
||||||
DeprecatedString old_pwd = TRY(Core::System::getcwd());
|
ByteString old_pwd = TRY(Core::System::getcwd());
|
||||||
|
|
||||||
TRY(Core::System::chdir(output_directory));
|
TRY(Core::System::chdir(output_directory));
|
||||||
ScopeGuard go_back = [&old_pwd] { MUST(Core::System::chdir(old_pwd)); };
|
ScopeGuard go_back = [&old_pwd] { MUST(Core::System::chdir(old_pwd)); };
|
||||||
|
|
||||||
auto tar_stream = TRY(Archive::TarInputStream::construct(move(file)));
|
auto tar_stream = TRY(Archive::TarInputStream::construct(move(file)));
|
||||||
|
|
||||||
HashMap<DeprecatedString, DeprecatedString> global_overrides;
|
HashMap<ByteString, ByteString> global_overrides;
|
||||||
HashMap<DeprecatedString, DeprecatedString> local_overrides;
|
HashMap<ByteString, ByteString> local_overrides;
|
||||||
|
|
||||||
auto get_override = [&](StringView key) -> Optional<DeprecatedString> {
|
auto get_override = [&](StringView key) -> Optional<ByteString> {
|
||||||
Optional<DeprecatedString> maybe_local = local_overrides.get(key);
|
Optional<ByteString> maybe_local = local_overrides.get(key);
|
||||||
|
|
||||||
if (maybe_local.has_value())
|
if (maybe_local.has_value())
|
||||||
return maybe_local;
|
return maybe_local;
|
||||||
|
|
||||||
Optional<DeprecatedString> maybe_global = global_overrides.get(key);
|
Optional<ByteString> maybe_global = global_overrides.get(key);
|
||||||
|
|
||||||
if (maybe_global.has_value())
|
if (maybe_global.has_value())
|
||||||
return maybe_global;
|
return maybe_global;
|
||||||
|
@ -163,7 +163,7 @@ ErrorOr<void> extract_tar_archive(String archive_file, DeprecatedString output_d
|
||||||
long_name.append(reinterpret_cast<char*>(slice.data()), slice.size());
|
long_name.append(reinterpret_cast<char*>(slice.data()), slice.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
local_overrides.set("path", long_name.to_deprecated_string());
|
local_overrides.set("path", long_name.to_byte_string());
|
||||||
TRY(tar_stream->advance());
|
TRY(tar_stream->advance());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -175,9 +175,9 @@ ErrorOr<void> extract_tar_archive(String archive_file, DeprecatedString output_d
|
||||||
LexicalPath path = LexicalPath(header.filename());
|
LexicalPath path = LexicalPath(header.filename());
|
||||||
if (!header.prefix().is_empty())
|
if (!header.prefix().is_empty())
|
||||||
path = path.prepend(header.prefix());
|
path = path.prepend(header.prefix());
|
||||||
DeprecatedString filename = get_override("path"sv).value_or(path.string());
|
ByteString filename = get_override("path"sv).value_or(path.string());
|
||||||
|
|
||||||
DeprecatedString absolute_path = TRY(FileSystem::absolute_path(filename)).to_deprecated_string();
|
ByteString absolute_path = TRY(FileSystem::absolute_path(filename)).to_byte_string();
|
||||||
auto parent_path = LexicalPath(absolute_path).parent();
|
auto parent_path = LexicalPath(absolute_path).parent();
|
||||||
auto header_mode = TRY(header.mode());
|
auto header_mode = TRY(header.mode());
|
||||||
|
|
||||||
|
|
|
@ -122,9 +122,9 @@ ErrorOr<NonnullRefPtr<Client>> bind_service(void (*bind_method)(int, int))
|
||||||
|
|
||||||
static ErrorOr<void> load_content_filters()
|
static ErrorOr<void> load_content_filters()
|
||||||
{
|
{
|
||||||
auto file_or_error = Core::File::open(DeprecatedString::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
auto file_or_error = Core::File::open(ByteString::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
||||||
if (file_or_error.is_error())
|
if (file_or_error.is_error())
|
||||||
file_or_error = Core::File::open(DeprecatedString::formatted("{}/res/ladybird/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
file_or_error = Core::File::open(ByteString::formatted("{}/res/ladybird/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
||||||
if (file_or_error.is_error())
|
if (file_or_error.is_error())
|
||||||
return file_or_error.release_error();
|
return file_or_error.release_error();
|
||||||
|
|
||||||
|
|
|
@ -474,7 +474,7 @@
|
||||||
[submenu addItem:[NSMenuItem separatorItem]];
|
[submenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
auto* spoof_user_agent_menu = [[NSMenu alloc] init];
|
auto* spoof_user_agent_menu = [[NSMenu alloc] init];
|
||||||
auto add_user_agent = [spoof_user_agent_menu](DeprecatedString name) {
|
auto add_user_agent = [spoof_user_agent_menu](ByteString name) {
|
||||||
[spoof_user_agent_menu addItem:[[NSMenuItem alloc] initWithTitle:Ladybird::string_to_ns_string(name)
|
[spoof_user_agent_menu addItem:[[NSMenuItem alloc] initWithTitle:Ladybird::string_to_ns_string(name)
|
||||||
action:@selector(setUserAgentSpoof:)
|
action:@selector(setUserAgentSpoof:)
|
||||||
keyEquivalent:@""]];
|
keyEquivalent:@""]];
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)is_redirect;
|
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)is_redirect;
|
||||||
- (void)onLoadFinish:(URL const&)url;
|
- (void)onLoadFinish:(URL const&)url;
|
||||||
|
|
||||||
- (void)onTitleChange:(DeprecatedString const&)title;
|
- (void)onTitleChange:(ByteString const&)title;
|
||||||
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap;
|
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap;
|
||||||
|
|
||||||
- (void)onNavigateBack;
|
- (void)onNavigateBack;
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
- (void)resetZoom;
|
- (void)resetZoom;
|
||||||
- (float)zoomLevel;
|
- (float)zoomLevel;
|
||||||
|
|
||||||
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument;
|
- (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument;
|
||||||
|
|
||||||
- (void)viewSource;
|
- (void)viewSource;
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ struct HideCursor {
|
||||||
m_web_view_bridge->set_preferred_color_scheme(color_scheme);
|
m_web_view_bridge->set_preferred_color_scheme(color_scheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument
|
- (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument
|
||||||
{
|
{
|
||||||
m_web_view_bridge->debug_request(request, argument);
|
m_web_view_bridge->debug_request(request, argument);
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,7 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
||||||
return [delegate cookieJar].get_named_cookie(url, name);
|
return [delegate cookieJar].get_named_cookie(url, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_web_view_bridge->on_get_cookie = [](auto const& url, auto source) -> DeprecatedString {
|
m_web_view_bridge->on_get_cookie = [](auto const& url, auto source) -> ByteString {
|
||||||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||||
return [delegate cookieJar].get_cookie(url, source);
|
return [delegate cookieJar].get_cookie(url, source);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <Ladybird/Utilities.h>
|
#include <Ladybird/Utilities.h>
|
||||||
#include <LibCore/Resource.h>
|
#include <LibCore/Resource.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
@ -33,7 +33,7 @@ Core::AnonymousBuffer create_system_palette()
|
||||||
|
|
||||||
auto theme_file = is_dark ? "Dark"sv : "Default"sv;
|
auto theme_file = is_dark ? "Dark"sv : "Default"sv;
|
||||||
auto theme_ini = MUST(Core::Resource::load_from_uri(MUST(String::formatted("resource://themes/{}.ini", theme_file))));
|
auto theme_ini = MUST(Core::Resource::load_from_uri(MUST(String::formatted("resource://themes/{}.ini", theme_file))));
|
||||||
auto theme = Gfx::load_system_theme(theme_ini->filesystem_path().to_deprecated_string()).release_value_but_fixme_should_propagate_errors();
|
auto theme = Gfx::load_system_theme(theme_ini->filesystem_path().to_byte_string()).release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
||||||
auto palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
|
auto palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
|
||||||
auto palette = Gfx::Palette(move(palette_impl));
|
auto palette = Gfx::Palette(move(palette_impl));
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/URL.h>
|
#include <AK/URL.h>
|
||||||
#include <Ladybird/Utilities.h>
|
#include <Ladybird/Utilities.h>
|
||||||
|
@ -247,7 +247,7 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onTitleChange:(DeprecatedString const&)title
|
- (void)onTitleChange:(ByteString const&)title
|
||||||
{
|
{
|
||||||
[[self tabController] onTitleChange:title];
|
[[self tabController] onTitleChange:title];
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct TabSettings {
|
||||||
BOOL scripting_enabled { YES };
|
BOOL scripting_enabled { YES };
|
||||||
BOOL block_popups { YES };
|
BOOL block_popups { YES };
|
||||||
BOOL same_origin_policy_enabled { NO };
|
BOOL same_origin_policy_enabled { NO };
|
||||||
DeprecatedString user_agent_name { "Disabled"sv };
|
ByteString user_agent_name { "Disabled"sv };
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface TabController : NSWindowController <NSWindowDelegate>
|
@interface TabController : NSWindowController <NSWindowDelegate>
|
||||||
|
@ -27,14 +27,14 @@ struct TabSettings {
|
||||||
- (void)loadHTML:(StringView)html url:(URL const&)url;
|
- (void)loadHTML:(StringView)html url:(URL const&)url;
|
||||||
|
|
||||||
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect;
|
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect;
|
||||||
- (void)onTitleChange:(DeprecatedString const&)title;
|
- (void)onTitleChange:(ByteString const&)title;
|
||||||
|
|
||||||
- (void)navigateBack:(id)sender;
|
- (void)navigateBack:(id)sender;
|
||||||
- (void)navigateForward:(id)sender;
|
- (void)navigateForward:(id)sender;
|
||||||
- (void)reload:(id)sender;
|
- (void)reload:(id)sender;
|
||||||
- (void)clearHistory;
|
- (void)clearHistory;
|
||||||
|
|
||||||
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument;
|
- (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument;
|
||||||
|
|
||||||
- (void)focusLocationToolbarItem;
|
- (void)focusLocationToolbarItem;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ enum class IsHistoryNavigation {
|
||||||
|
|
||||||
@interface TabController () <NSToolbarDelegate, NSSearchFieldDelegate>
|
@interface TabController () <NSToolbarDelegate, NSSearchFieldDelegate>
|
||||||
{
|
{
|
||||||
DeprecatedString m_title;
|
ByteString m_title;
|
||||||
|
|
||||||
WebView::History m_history;
|
WebView::History m_history;
|
||||||
IsHistoryNavigation m_is_history_navigation;
|
IsHistoryNavigation m_is_history_navigation;
|
||||||
|
@ -133,7 +133,7 @@ enum class IsHistoryNavigation {
|
||||||
[self updateNavigationButtonStates];
|
[self updateNavigationButtonStates];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onTitleChange:(DeprecatedString const&)title
|
- (void)onTitleChange:(ByteString const&)title
|
||||||
{
|
{
|
||||||
m_title = title;
|
m_title = title;
|
||||||
m_history.update_title(m_title);
|
m_history.update_title(m_title);
|
||||||
|
@ -201,7 +201,7 @@ enum class IsHistoryNavigation {
|
||||||
[self updateNavigationButtonStates];
|
[self updateNavigationButtonStates];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)debugRequest:(DeprecatedString const&)request argument:(DeprecatedString const&)argument
|
- (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument
|
||||||
{
|
{
|
||||||
if (request == "dump-history") {
|
if (request == "dump-history") {
|
||||||
m_history.dump();
|
m_history.dump();
|
||||||
|
@ -390,8 +390,8 @@ enum class IsHistoryNavigation {
|
||||||
|
|
||||||
- (void)setUserAgentSpoof:(NSMenuItem*)sender
|
- (void)setUserAgentSpoof:(NSMenuItem*)sender
|
||||||
{
|
{
|
||||||
DeprecatedString const user_agent_name = [[sender title] UTF8String];
|
ByteString const user_agent_name = [[sender title] UTF8String];
|
||||||
DeprecatedString user_agent = "";
|
ByteString user_agent = "";
|
||||||
if (user_agent_name == "Disabled"sv) {
|
if (user_agent_name == "Disabled"sv) {
|
||||||
user_agent = Web::default_user_agent;
|
user_agent = Web::default_user_agent;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FontPlugin.h"
|
#include "FontPlugin.h"
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
#include <LibGfx/Font/Emoji.h>
|
#include <LibGfx/Font/Emoji.h>
|
||||||
#include <LibGfx/Font/FontDatabase.h>
|
#include <LibGfx/Font/FontDatabase.h>
|
||||||
|
|
||||||
extern DeprecatedString s_serenity_resource_root;
|
extern ByteString s_serenity_resource_root;
|
||||||
|
|
||||||
namespace Ladybird {
|
namespace Ladybird {
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ ErrorOr<void> AutoComplete::parse_google_autocomplete(Vector<JsonValue> const& j
|
||||||
|
|
||||||
if (!json[0].is_string())
|
if (!json[0].is_string())
|
||||||
return Error::from_string_view("Invalid JSON, expected first element to be a string"sv);
|
return Error::from_string_view("Invalid JSON, expected first element to be a string"sv);
|
||||||
auto query = TRY(String::from_deprecated_string(json[0].as_string()));
|
auto query = TRY(String::from_byte_string(json[0].as_string()));
|
||||||
|
|
||||||
if (!json[1].is_array())
|
if (!json[1].is_array())
|
||||||
return Error::from_string_view("Invalid JSON, expected second element to be an array"sv);
|
return Error::from_string_view("Invalid JSON, expected second element to be an array"sv);
|
||||||
|
@ -55,7 +55,7 @@ ErrorOr<void> AutoComplete::parse_google_autocomplete(Vector<JsonValue> const& j
|
||||||
return Error::from_string_view("Invalid JSON, query does not match"sv);
|
return Error::from_string_view("Invalid JSON, query does not match"sv);
|
||||||
|
|
||||||
for (auto& suggestion : suggestions_array) {
|
for (auto& suggestion : suggestions_array) {
|
||||||
m_auto_complete_model->add(TRY(String::from_deprecated_string(suggestion.as_string())));
|
m_auto_complete_model->add(TRY(String::from_byte_string(suggestion.as_string())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -67,7 +67,7 @@ ErrorOr<void> AutoComplete::parse_duckduckgo_autocomplete(Vector<JsonValue> cons
|
||||||
auto maybe_value = suggestion.as_object().get("phrase"sv);
|
auto maybe_value = suggestion.as_object().get("phrase"sv);
|
||||||
if (!maybe_value.has_value())
|
if (!maybe_value.has_value())
|
||||||
continue;
|
continue;
|
||||||
m_auto_complete_model->add(TRY(String::from_deprecated_string(maybe_value->as_string())));
|
m_auto_complete_model->add(TRY(String::from_byte_string(maybe_value->as_string())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -77,7 +77,7 @@ ErrorOr<void> AutoComplete::parse_yahoo_autocomplete(JsonObject const& json)
|
||||||
{
|
{
|
||||||
if (!json.get("q"sv).has_value() || !json.get("q"sv)->is_string())
|
if (!json.get("q"sv).has_value() || !json.get("q"sv)->is_string())
|
||||||
return Error::from_string_view("Invalid JSON, expected \"q\" to be a string"sv);
|
return Error::from_string_view("Invalid JSON, expected \"q\" to be a string"sv);
|
||||||
auto query = TRY(String::from_deprecated_string(json.get("q"sv)->as_string()));
|
auto query = TRY(String::from_byte_string(json.get("q"sv)->as_string()));
|
||||||
|
|
||||||
if (!json.get("r"sv).has_value() || !json.get("r"sv)->is_array())
|
if (!json.get("r"sv).has_value() || !json.get("r"sv)->is_array())
|
||||||
return Error::from_string_view("Invalid JSON, expected \"r\" to be an object"sv);
|
return Error::from_string_view("Invalid JSON, expected \"r\" to be an object"sv);
|
||||||
|
@ -94,7 +94,7 @@ ErrorOr<void> AutoComplete::parse_yahoo_autocomplete(JsonObject const& json)
|
||||||
if (!suggestion.get("k"sv).has_value() || !suggestion.get("k"sv)->is_string())
|
if (!suggestion.get("k"sv).has_value() || !suggestion.get("k"sv)->is_string())
|
||||||
return Error::from_string_view("Invalid JSON, expected \"k\" to be a string"sv);
|
return Error::from_string_view("Invalid JSON, expected \"k\" to be a string"sv);
|
||||||
|
|
||||||
m_auto_complete_model->add(TRY(String::from_deprecated_string(suggestion.get("k"sv)->as_string())));
|
m_auto_complete_model->add(TRY(String::from_byte_string(suggestion.get("k"sv)->as_string())));
|
||||||
};
|
};
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -105,7 +105,7 @@ ErrorOr<void> AutoComplete::got_network_response(QNetworkReply* reply)
|
||||||
if (reply->error() == QNetworkReply::NetworkError::OperationCanceledError)
|
if (reply->error() == QNetworkReply::NetworkError::OperationCanceledError)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
AK::JsonParser parser(ak_deprecated_string_from_qstring(reply->readAll()));
|
AK::JsonParser parser(ak_byte_string_from_qstring(reply->readAll()));
|
||||||
auto json = TRY(parser.parse());
|
auto json = TRY(parser.parse());
|
||||||
|
|
||||||
auto engine_name = Settings::the()->autocomplete_engine().name;
|
auto engine_name = Settings::the()->autocomplete_engine().name;
|
||||||
|
|
|
@ -331,7 +331,7 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
|
||||||
auto* disable_spoofing = add_user_agent("Disabled"sv, Web::default_user_agent);
|
auto* disable_spoofing = add_user_agent("Disabled"sv, Web::default_user_agent);
|
||||||
disable_spoofing->setChecked(true);
|
disable_spoofing->setChecked(true);
|
||||||
for (auto const& user_agent : WebView::user_agents)
|
for (auto const& user_agent : WebView::user_agents)
|
||||||
add_user_agent(user_agent.key, user_agent.value.to_deprecated_string());
|
add_user_agent(user_agent.key, user_agent.value.to_byte_string());
|
||||||
|
|
||||||
auto* custom_user_agent_action = new QAction("Custom...", this);
|
auto* custom_user_agent_action = new QAction("Custom...", this);
|
||||||
custom_user_agent_action->setCheckable(true);
|
custom_user_agent_action->setCheckable(true);
|
||||||
|
@ -340,7 +340,7 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
|
||||||
QObject::connect(custom_user_agent_action, &QAction::triggered, this, [this, disable_spoofing] {
|
QObject::connect(custom_user_agent_action, &QAction::triggered, this, [this, disable_spoofing] {
|
||||||
auto user_agent = QInputDialog::getText(this, "Custom User Agent", "Enter User Agent:");
|
auto user_agent = QInputDialog::getText(this, "Custom User Agent", "Enter User Agent:");
|
||||||
if (!user_agent.isEmpty()) {
|
if (!user_agent.isEmpty()) {
|
||||||
debug_request("spoof-user-agent", ak_deprecated_string_from_qstring(user_agent));
|
debug_request("spoof-user-agent", ak_byte_string_from_qstring(user_agent));
|
||||||
debug_request("clear-cache"); // clear the cache to ensure requests are re-done with the new user agent
|
debug_request("clear-cache"); // clear the cache to ensure requests are re-done with the new user agent
|
||||||
} else {
|
} else {
|
||||||
disable_spoofing->activate(QAction::Trigger);
|
disable_spoofing->activate(QAction::Trigger);
|
||||||
|
@ -455,7 +455,7 @@ void BrowserWindow::set_current_tab(Tab* tab)
|
||||||
update_displayed_zoom_level();
|
update_displayed_zoom_level();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
|
void BrowserWindow::debug_request(ByteString const& request, ByteString const& argument)
|
||||||
{
|
{
|
||||||
if (!m_current_tab)
|
if (!m_current_tab)
|
||||||
return;
|
return;
|
||||||
|
@ -505,7 +505,7 @@ Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab)
|
||||||
};
|
};
|
||||||
|
|
||||||
tab->view().on_tab_open_request = [this](auto url, auto activate_tab) {
|
tab->view().on_tab_open_request = [this](auto url, auto activate_tab) {
|
||||||
auto& tab = new_tab(qstring_from_ak_string(url.to_deprecated_string()), activate_tab);
|
auto& tab = new_tab(qstring_from_ak_string(url.to_byte_string()), activate_tab);
|
||||||
return tab.view().handle();
|
return tab.view().handle();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -533,7 +533,7 @@ Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab)
|
||||||
return m_cookie_jar.get_named_cookie(url, name);
|
return m_cookie_jar.get_named_cookie(url, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
tab->view().on_get_cookie = [this](auto& url, auto source) -> DeprecatedString {
|
tab->view().on_get_cookie = [this](auto& url, auto source) -> ByteString {
|
||||||
return m_cookie_jar.get_cookie(url, source);
|
return m_cookie_jar.get_cookie(url, source);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ private:
|
||||||
|
|
||||||
Tab& create_new_tab(Web::HTML::ActivateTab activate_tab);
|
Tab& create_new_tab(Web::HTML::ActivateTab activate_tab);
|
||||||
|
|
||||||
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");
|
void debug_request(ByteString const& request, ByteString const& argument = "");
|
||||||
|
|
||||||
void set_current_tab(Tab* tab);
|
void set_current_tab(Tab* tab);
|
||||||
void update_displayed_zoom_level();
|
void update_displayed_zoom_level();
|
||||||
|
|
|
@ -24,7 +24,7 @@ void RequestManagerQt::reply_finished(QNetworkReply* reply)
|
||||||
request->did_finish();
|
request->did_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<Web::ResourceLoaderConnectorRequest> RequestManagerQt::start_request(DeprecatedString const& method, AK::URL const& url, HashMap<DeprecatedString, DeprecatedString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const& proxy)
|
RefPtr<Web::ResourceLoaderConnectorRequest> RequestManagerQt::start_request(ByteString const& method, AK::URL const& url, HashMap<ByteString, ByteString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const& proxy)
|
||||||
{
|
{
|
||||||
if (!url.scheme().bytes_as_string_view().is_one_of_ignoring_ascii_case("http"sv, "https"sv)) {
|
if (!url.scheme().bytes_as_string_view().is_one_of_ignoring_ascii_case("http"sv, "https"sv)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -38,9 +38,9 @@ RefPtr<Web::ResourceLoaderConnectorRequest> RequestManagerQt::start_request(Depr
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<RequestManagerQt::Request>> RequestManagerQt::Request::create(QNetworkAccessManager& qnam, DeprecatedString const& method, AK::URL const& url, HashMap<DeprecatedString, DeprecatedString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&)
|
ErrorOr<NonnullRefPtr<RequestManagerQt::Request>> RequestManagerQt::Request::create(QNetworkAccessManager& qnam, ByteString const& method, AK::URL const& url, HashMap<ByteString, ByteString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&)
|
||||||
{
|
{
|
||||||
QNetworkRequest request { QString(url.to_deprecated_string().characters()) };
|
QNetworkRequest request { QString(url.to_byte_string().characters()) };
|
||||||
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::ManualRedirectPolicy);
|
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::ManualRedirectPolicy);
|
||||||
request.setAttribute(QNetworkRequest::CookieLoadControlAttribute, QNetworkRequest::Manual);
|
request.setAttribute(QNetworkRequest::CookieLoadControlAttribute, QNetworkRequest::Manual);
|
||||||
request.setAttribute(QNetworkRequest::CookieSaveControlAttribute, QNetworkRequest::Manual);
|
request.setAttribute(QNetworkRequest::CookieSaveControlAttribute, QNetworkRequest::Manual);
|
||||||
|
@ -87,11 +87,11 @@ void RequestManagerQt::Request::did_finish()
|
||||||
{
|
{
|
||||||
auto buffer = m_reply.readAll();
|
auto buffer = m_reply.readAll();
|
||||||
auto http_status_code = m_reply.attribute(QNetworkRequest::Attribute::HttpStatusCodeAttribute).toInt();
|
auto http_status_code = m_reply.attribute(QNetworkRequest::Attribute::HttpStatusCodeAttribute).toInt();
|
||||||
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> response_headers;
|
HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> response_headers;
|
||||||
Vector<DeprecatedString> set_cookie_headers;
|
Vector<ByteString> set_cookie_headers;
|
||||||
for (auto& it : m_reply.rawHeaderPairs()) {
|
for (auto& it : m_reply.rawHeaderPairs()) {
|
||||||
auto name = DeprecatedString(it.first.data(), it.first.length());
|
auto name = ByteString(it.first.data(), it.first.length());
|
||||||
auto value = DeprecatedString(it.second.data(), it.second.length());
|
auto value = ByteString(it.second.data(), it.second.length());
|
||||||
if (name.equals_ignoring_ascii_case("set-cookie"sv)) {
|
if (name.equals_ignoring_ascii_case("set-cookie"sv)) {
|
||||||
// NOTE: Qt may have bundled multiple Set-Cookie headers into a single one.
|
// NOTE: Qt may have bundled multiple Set-Cookie headers into a single one.
|
||||||
// We have to extract the full list of cookies via QNetworkReply::header().
|
// We have to extract the full list of cookies via QNetworkReply::header().
|
||||||
|
@ -104,7 +104,7 @@ void RequestManagerQt::Request::did_finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!set_cookie_headers.is_empty()) {
|
if (!set_cookie_headers.is_empty()) {
|
||||||
response_headers.set("set-cookie"sv, JsonArray { set_cookie_headers }.to_deprecated_string());
|
response_headers.set("set-cookie"sv, JsonArray { set_cookie_headers }.to_byte_string());
|
||||||
}
|
}
|
||||||
bool success = http_status_code != 0;
|
bool success = http_status_code != 0;
|
||||||
on_buffered_request_finish(success, buffer.length(), response_headers, http_status_code, ReadonlyBytes { buffer.data(), (size_t)buffer.size() });
|
on_buffered_request_finish(success, buffer.length(), response_headers, http_status_code, ReadonlyBytes { buffer.data(), (size_t)buffer.size() });
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
virtual void prefetch_dns(AK::URL const&) override { }
|
virtual void prefetch_dns(AK::URL const&) override { }
|
||||||
virtual void preconnect(AK::URL const&) override { }
|
virtual void preconnect(AK::URL const&) override { }
|
||||||
|
|
||||||
virtual RefPtr<Web::ResourceLoaderConnectorRequest> start_request(DeprecatedString const& method, AK::URL const&, HashMap<DeprecatedString, DeprecatedString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&) override;
|
virtual RefPtr<Web::ResourceLoaderConnectorRequest> start_request(ByteString const& method, AK::URL const&, HashMap<ByteString, ByteString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void reply_finished(QNetworkReply*);
|
void reply_finished(QNetworkReply*);
|
||||||
|
@ -38,7 +38,7 @@ private:
|
||||||
class Request
|
class Request
|
||||||
: public Web::ResourceLoaderConnectorRequest {
|
: public Web::ResourceLoaderConnectorRequest {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullRefPtr<Request>> create(QNetworkAccessManager& qnam, DeprecatedString const& method, AK::URL const& url, HashMap<DeprecatedString, DeprecatedString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&);
|
static ErrorOr<NonnullRefPtr<Request>> create(QNetworkAccessManager& qnam, ByteString const& method, AK::URL const& url, HashMap<ByteString, ByteString> const& request_headers, ReadonlyBytes request_body, Core::ProxyData const&);
|
||||||
|
|
||||||
virtual ~Request() override;
|
virtual ~Request() override;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <LibWebView/SearchEngine.h>
|
#include <LibWebView/SearchEngine.h>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
|
||||||
AK::DeprecatedString ak_deprecated_string_from_qstring(QString const& qstring)
|
AK::ByteString ak_byte_string_from_qstring(QString const& qstring)
|
||||||
{
|
{
|
||||||
return AK::DeprecatedString(qstring.toUtf8().data());
|
return AK::ByteString(qstring.toUtf8().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
String ak_string_from_qstring(QString const& qstring)
|
String ak_string_from_qstring(QString const& qstring)
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
AK::DeprecatedString ak_deprecated_string_from_qstring(QString const&);
|
AK::ByteString ak_byte_string_from_qstring(QString const&);
|
||||||
String ak_string_from_qstring(QString const&);
|
String ak_string_from_qstring(QString const&);
|
||||||
QString qstring_from_ak_string(StringView);
|
QString qstring_from_ak_string(StringView);
|
||||||
|
|
|
@ -107,7 +107,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
||||||
};
|
};
|
||||||
|
|
||||||
view().on_link_hover = [this](auto const& url) {
|
view().on_link_hover = [this](auto const& url) {
|
||||||
m_hover_label->setText(qstring_from_ak_string(url.to_deprecated_string()));
|
m_hover_label->setText(qstring_from_ak_string(url.to_byte_string()));
|
||||||
update_hover_label();
|
update_hover_label();
|
||||||
m_hover_label->show();
|
m_hover_label->show();
|
||||||
};
|
};
|
||||||
|
@ -123,7 +123,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
||||||
m_history.replace_current(url, m_title.toUtf8().data());
|
m_history.replace_current(url, m_title.toUtf8().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_location_edit->setText(url.to_deprecated_string().characters());
|
m_location_edit->setText(url.to_byte_string().characters());
|
||||||
m_location_edit->setCursorPosition(0);
|
m_location_edit->setCursorPosition(0);
|
||||||
|
|
||||||
// Don't add to history if back or forward is pressed
|
// Don't add to history if back or forward is pressed
|
||||||
|
@ -648,7 +648,7 @@ void Tab::back()
|
||||||
|
|
||||||
m_is_history_navigation = true;
|
m_is_history_navigation = true;
|
||||||
m_history.go_back();
|
m_history.go_back();
|
||||||
view().load(m_history.current().url.to_deprecated_string());
|
view().load(m_history.current().url.to_byte_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::forward()
|
void Tab::forward()
|
||||||
|
@ -658,7 +658,7 @@ void Tab::forward()
|
||||||
|
|
||||||
m_is_history_navigation = true;
|
m_is_history_navigation = true;
|
||||||
m_history.go_forward();
|
m_history.go_forward();
|
||||||
view().load(m_history.current().url.to_deprecated_string());
|
view().load(m_history.current().url.to_byte_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::reload()
|
void Tab::reload()
|
||||||
|
@ -667,7 +667,7 @@ void Tab::reload()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_is_history_navigation = true;
|
m_is_history_navigation = true;
|
||||||
view().load(m_history.current().url.to_deprecated_string());
|
view().load(m_history.current().url.to_byte_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::open_link(URL const& url)
|
void Tab::open_link(URL const& url)
|
||||||
|
@ -703,7 +703,7 @@ int Tab::tab_index()
|
||||||
return m_window->tab_index(this);
|
return m_window->tab_index(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
|
void Tab::debug_request(ByteString const& request, ByteString const& argument)
|
||||||
{
|
{
|
||||||
if (request == "dump-history")
|
if (request == "dump-history")
|
||||||
m_history.dump();
|
m_history.dump();
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
void forward();
|
void forward();
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
void debug_request(DeprecatedString const& request, DeprecatedString const& argument);
|
void debug_request(ByteString const& request, ByteString const& argument);
|
||||||
|
|
||||||
void open_file();
|
void open_file();
|
||||||
void update_reset_zoom_button();
|
void update_reset_zoom_button();
|
||||||
|
|
|
@ -576,7 +576,7 @@ static Core::AnonymousBuffer make_system_theme_from_qt_palette(QWidget& widget,
|
||||||
|
|
||||||
auto theme_file = mode == WebContentView::PaletteMode::Default ? "Default"sv : "Dark"sv;
|
auto theme_file = mode == WebContentView::PaletteMode::Default ? "Default"sv : "Dark"sv;
|
||||||
auto theme_ini = MUST(Core::Resource::load_from_uri(MUST(String::formatted("resource://themes/{}.ini", theme_file))));
|
auto theme_ini = MUST(Core::Resource::load_from_uri(MUST(String::formatted("resource://themes/{}.ini", theme_file))));
|
||||||
auto theme = Gfx::load_system_theme(theme_ini->filesystem_path().to_deprecated_string()).release_value_but_fixme_should_propagate_errors();
|
auto theme = Gfx::load_system_theme(theme_ini->filesystem_path().to_byte_string()).release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
||||||
auto palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
|
auto palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
|
||||||
auto palette = Gfx::Palette(move(palette_impl));
|
auto palette = Gfx::Palette(move(palette_impl));
|
||||||
|
@ -752,7 +752,7 @@ bool WebContentView::event(QEvent* event)
|
||||||
|
|
||||||
ErrorOr<String> WebContentView::dump_layout_tree()
|
ErrorOr<String> WebContentView::dump_layout_tree()
|
||||||
{
|
{
|
||||||
return String::from_deprecated_string(client().dump_layout_tree());
|
return String::from_byte_string(client().dump_layout_tree());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
|
|
|
@ -19,7 +19,7 @@ NonnullRefPtr<WebSocketClientManagerQt> WebSocketClientManagerQt::create()
|
||||||
WebSocketClientManagerQt::WebSocketClientManagerQt() = default;
|
WebSocketClientManagerQt::WebSocketClientManagerQt() = default;
|
||||||
WebSocketClientManagerQt::~WebSocketClientManagerQt() = default;
|
WebSocketClientManagerQt::~WebSocketClientManagerQt() = default;
|
||||||
|
|
||||||
RefPtr<Web::WebSockets::WebSocketClientSocket> WebSocketClientManagerQt::connect(AK::URL const& url, DeprecatedString const& origin, Vector<DeprecatedString> const& protocols)
|
RefPtr<Web::WebSockets::WebSocketClientSocket> WebSocketClientManagerQt::connect(AK::URL const& url, ByteString const& origin, Vector<ByteString> const& protocols)
|
||||||
{
|
{
|
||||||
WebSocket::ConnectionInfo connection_info(url);
|
WebSocket::ConnectionInfo connection_info(url);
|
||||||
connection_info.set_origin(origin);
|
connection_info.set_origin(origin);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
static NonnullRefPtr<WebSocketClientManagerQt> create();
|
static NonnullRefPtr<WebSocketClientManagerQt> create();
|
||||||
|
|
||||||
virtual ~WebSocketClientManagerQt() override;
|
virtual ~WebSocketClientManagerQt() override;
|
||||||
virtual RefPtr<Web::WebSockets::WebSocketClientSocket> connect(AK::URL const&, DeprecatedString const& origin, Vector<DeprecatedString> const& protocols) override;
|
virtual RefPtr<Web::WebSockets::WebSocketClientSocket> connect(AK::URL const&, ByteString const& origin, Vector<ByteString> const& protocols) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebSocketClientManagerQt();
|
WebSocketClientManagerQt();
|
||||||
|
|
|
@ -85,13 +85,13 @@ ErrorOr<ByteBuffer> WebSocketImplQt::read(int max_size)
|
||||||
return buffer.slice(0, bytes_read);
|
return buffer.slice(0, bytes_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<DeprecatedString> WebSocketImplQt::read_line(size_t size)
|
ErrorOr<ByteString> WebSocketImplQt::read_line(size_t size)
|
||||||
{
|
{
|
||||||
auto buffer = TRY(ByteBuffer::create_uninitialized(size));
|
auto buffer = TRY(ByteBuffer::create_uninitialized(size));
|
||||||
auto bytes_read = m_socket->readLine(reinterpret_cast<char*>(buffer.data()), buffer.size());
|
auto bytes_read = m_socket->readLine(reinterpret_cast<char*>(buffer.data()), buffer.size());
|
||||||
if (bytes_read == -1)
|
if (bytes_read == -1)
|
||||||
return Error::from_string_literal("WebSocketImplQt::read_line(): Error reading from socket");
|
return Error::from_string_literal("WebSocketImplQt::read_line(): Error reading from socket");
|
||||||
return DeprecatedString::copy(buffer.span().slice(0, bytes_read));
|
return ByteString::copy(buffer.span().slice(0, bytes_read));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
virtual void connect(WebSocket::ConnectionInfo const&) override;
|
virtual void connect(WebSocket::ConnectionInfo const&) override;
|
||||||
virtual bool can_read_line() override;
|
virtual bool can_read_line() override;
|
||||||
virtual ErrorOr<DeprecatedString> read_line(size_t) override;
|
virtual ErrorOr<ByteString> read_line(size_t) override;
|
||||||
virtual ErrorOr<ByteBuffer> read(int max_size) override;
|
virtual ErrorOr<ByteBuffer> read(int max_size) override;
|
||||||
virtual bool send(ReadonlyBytes) override;
|
virtual bool send(ReadonlyBytes) override;
|
||||||
virtual bool eof() override;
|
virtual bool eof() override;
|
||||||
|
|
|
@ -50,7 +50,7 @@ WebSocketQt::WebSocketQt(NonnullRefPtr<WebSocket::WebSocket> underlying_socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
m_websocket->on_close = [weak_this = make_weak_ptr()](u16 code, DeprecatedString reason, bool was_clean) {
|
m_websocket->on_close = [weak_this = make_weak_ptr()](u16 code, ByteString reason, bool was_clean) {
|
||||||
if (auto strong_this = weak_this.strong_ref())
|
if (auto strong_this = weak_this.strong_ref())
|
||||||
if (strong_this->on_close)
|
if (strong_this->on_close)
|
||||||
strong_this->on_close(code, move(reason), was_clean);
|
strong_this->on_close(code, move(reason), was_clean);
|
||||||
|
@ -74,7 +74,7 @@ Web::WebSockets::WebSocket::ReadyState WebSocketQt::ready_state()
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString WebSocketQt::subprotocol_in_use()
|
ByteString WebSocketQt::subprotocol_in_use()
|
||||||
{
|
{
|
||||||
return m_websocket->subprotocol_in_use();
|
return m_websocket->subprotocol_in_use();
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ void WebSocketQt::send(StringView message)
|
||||||
m_websocket->send(WebSocket::Message(message));
|
m_websocket->send(WebSocket::Message(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocketQt::close(u16 code, DeprecatedString reason)
|
void WebSocketQt::close(u16 code, ByteString reason)
|
||||||
{
|
{
|
||||||
m_websocket->close(code, reason);
|
m_websocket->close(code, reason);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ public:
|
||||||
virtual ~WebSocketQt() override;
|
virtual ~WebSocketQt() override;
|
||||||
|
|
||||||
virtual Web::WebSockets::WebSocket::ReadyState ready_state() override;
|
virtual Web::WebSockets::WebSocket::ReadyState ready_state() override;
|
||||||
virtual DeprecatedString subprotocol_in_use() override;
|
virtual ByteString subprotocol_in_use() override;
|
||||||
virtual void send(ByteBuffer binary_or_text_message, bool is_text) override;
|
virtual void send(ByteBuffer binary_or_text_message, bool is_text) override;
|
||||||
virtual void send(StringView message) override;
|
virtual void send(StringView message) override;
|
||||||
virtual void close(u16 code, DeprecatedString reason) override;
|
virtual void close(u16 code, ByteString reason) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit WebSocketQt(NonnullRefPtr<WebSocket::WebSocket>);
|
explicit WebSocketQt(NonnullRefPtr<WebSocket::WebSocket>);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/Directory.h>
|
#include <LibCore/Directory.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
|
@ -17,7 +17,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
AK::set_rich_debug_enabled(true);
|
AK::set_rich_debug_enabled(true);
|
||||||
|
|
||||||
DeprecatedString pid_file;
|
ByteString pid_file;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(pid_file, "Path to the PID file for the SQLServer singleton process", "pid-file", 'p', "pid_file");
|
args_parser.add_option(pid_file, "Path to the PID file for the SQLServer singleton process", "pid-file", 'p', "pid_file");
|
||||||
|
@ -25,7 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
VERIFY(!pid_file.is_empty());
|
VERIFY(!pid_file.is_empty());
|
||||||
|
|
||||||
auto database_path = DeprecatedString::formatted("{}/Ladybird", Core::StandardPaths::data_directory());
|
auto database_path = ByteString::formatted("{}/Ladybird", Core::StandardPaths::data_directory());
|
||||||
TRY(Core::Directory::create(database_path, Core::Directory::CreateDirectories::Yes));
|
TRY(Core::Directory::create(database_path, Core::Directory::CreateDirectories::Yes));
|
||||||
|
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
|
|
||||||
DeprecatedString s_serenity_resource_root;
|
ByteString s_serenity_resource_root;
|
||||||
|
|
||||||
ErrorOr<String> application_directory()
|
ErrorOr<String> application_directory()
|
||||||
{
|
{
|
||||||
auto current_executable_path = TRY(Core::System::current_executable_path());
|
auto current_executable_path = TRY(Core::System::current_executable_path());
|
||||||
auto dirname = LexicalPath::dirname(current_executable_path);
|
auto dirname = LexicalPath::dirname(current_executable_path);
|
||||||
return String::from_deprecated_string(dirname);
|
return String::from_byte_string(dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
void platform_init()
|
void platform_init()
|
||||||
|
@ -26,14 +26,14 @@ void platform_init()
|
||||||
s_serenity_resource_root = [] {
|
s_serenity_resource_root = [] {
|
||||||
auto const* source_dir = getenv("SERENITY_SOURCE_DIR");
|
auto const* source_dir = getenv("SERENITY_SOURCE_DIR");
|
||||||
if (source_dir) {
|
if (source_dir) {
|
||||||
return DeprecatedString::formatted("{}/Base", source_dir);
|
return ByteString::formatted("{}/Base", source_dir);
|
||||||
}
|
}
|
||||||
auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME");
|
auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME");
|
||||||
VERIFY(home);
|
VERIFY(home);
|
||||||
auto home_lagom = DeprecatedString::formatted("{}/.lagom", home);
|
auto home_lagom = ByteString::formatted("{}/.lagom", home);
|
||||||
if (FileSystem::is_directory(home_lagom))
|
if (FileSystem::is_directory(home_lagom))
|
||||||
return home_lagom;
|
return home_lagom;
|
||||||
auto app_dir = application_directory().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
|
auto app_dir = application_directory().release_value_but_fixme_should_propagate_errors().to_byte_string();
|
||||||
#ifdef AK_OS_MACOS
|
#ifdef AK_OS_MACOS
|
||||||
return LexicalPath(app_dir).parent().append("Resources"sv).string();
|
return LexicalPath(app_dir).parent().append("Resources"sv).string();
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
@ -16,4 +16,4 @@ void platform_init();
|
||||||
ErrorOr<String> application_directory();
|
ErrorOr<String> application_directory();
|
||||||
ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name);
|
ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name);
|
||||||
|
|
||||||
extern DeprecatedString s_serenity_resource_root;
|
extern ByteString s_serenity_resource_root;
|
||||||
|
|
|
@ -131,9 +131,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
static ErrorOr<void> load_content_filters()
|
static ErrorOr<void> load_content_filters()
|
||||||
{
|
{
|
||||||
auto file_or_error = Core::File::open(DeprecatedString::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
auto file_or_error = Core::File::open(ByteString::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
||||||
if (file_or_error.is_error())
|
if (file_or_error.is_error())
|
||||||
file_or_error = Core::File::open(DeprecatedString::formatted("{}/res/ladybird/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
file_or_error = Core::File::open(ByteString::formatted("{}/res/ladybird/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
|
||||||
if (file_or_error.is_error())
|
if (file_or_error.is_error())
|
||||||
return file_or_error.release_error();
|
return file_or_error.release_error();
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ static ErrorOr<pid_t> launch_process(StringView application, ReadonlySpan<char c
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path)
|
static ErrorOr<pid_t> launch_browser(ByteString const& socket_path)
|
||||||
{
|
{
|
||||||
return launch_process("Ladybird"sv,
|
return launch_process("Ladybird"sv,
|
||||||
Array {
|
Array {
|
||||||
|
@ -40,9 +40,9 @@ static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_path)
|
static ErrorOr<pid_t> launch_headless_browser(ByteString const& socket_path)
|
||||||
{
|
{
|
||||||
auto resources = DeprecatedString::formatted("{}/res", s_serenity_resource_root);
|
auto resources = ByteString::formatted("{}/res", s_serenity_resource_root);
|
||||||
return launch_process("headless-browser"sv,
|
return launch_process("headless-browser"sv,
|
||||||
Array {
|
Array {
|
||||||
"--resources",
|
"--resources",
|
||||||
|
@ -78,7 +78,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
platform_init();
|
platform_init();
|
||||||
|
|
||||||
auto webdriver_socket_path = DeprecatedString::formatted("{}/webdriver", TRY(Core::StandardPaths::runtime_directory()));
|
auto webdriver_socket_path = ByteString::formatted("{}/webdriver", TRY(Core::StandardPaths::runtime_directory()));
|
||||||
TRY(Core::Directory::create(webdriver_socket_path, Core::Directory::CreateDirectories::Yes));
|
TRY(Core::Directory::create(webdriver_socket_path, Core::Directory::CreateDirectories::Yes));
|
||||||
|
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
NSString* source_root = [[NSBundle mainBundle] executablePath];
|
NSString* source_root = [[NSBundle mainBundle] executablePath];
|
||||||
for (int i = 0; i < 7; ++i)
|
for (int i = 0; i < 7; ++i)
|
||||||
source_root = [source_root stringByDeletingLastPathComponent];
|
source_root = [source_root stringByDeletingLastPathComponent];
|
||||||
auto source_root_string = DeprecatedString([source_root UTF8String]);
|
auto source_root_string = ByteString([source_root UTF8String]);
|
||||||
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::formatted("{}/Base/res", source_root_string))));
|
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::formatted("{}/Base/res", source_root_string))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,16 +68,16 @@ static bool is_ui_dimension_property(StringView property)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Since normal string-based properties take either String or StringView (and the latter can be implicitly constructed from the former),
|
// FIXME: Since normal string-based properties take either String or StringView (and the latter can be implicitly constructed from the former),
|
||||||
// we need to special-case DeprecatedString property setters while those still exist.
|
// we need to special-case ByteString property setters while those still exist.
|
||||||
// Please remove a setter from this list once it uses StringView or String.
|
// Please remove a setter from this list once it uses StringView or String.
|
||||||
static bool takes_deprecated_string(StringView property)
|
static bool takes_byte_string(StringView property)
|
||||||
{
|
{
|
||||||
static HashTable<StringView> deprecated_string_properties;
|
static HashTable<StringView> byte_string_properties;
|
||||||
if (deprecated_string_properties.is_empty()) {
|
if (byte_string_properties.is_empty()) {
|
||||||
deprecated_string_properties.set("icon_from_path"sv);
|
byte_string_properties.set("icon_from_path"sv);
|
||||||
deprecated_string_properties.set("name"sv);
|
byte_string_properties.set("name"sv);
|
||||||
}
|
}
|
||||||
return deprecated_string_properties.contains(property);
|
return byte_string_properties.contains(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<String> include_path_for(StringView class_name, LexicalPath const& gml_file_name)
|
static ErrorOr<String> include_path_for(StringView class_name, LexicalPath const& gml_file_name)
|
||||||
|
@ -141,7 +141,7 @@ static char const footer[] = R"~~~(
|
||||||
|
|
||||||
static ErrorOr<String> escape_string(JsonValue to_escape)
|
static ErrorOr<String> escape_string(JsonValue to_escape)
|
||||||
{
|
{
|
||||||
auto string = TRY(String::from_deprecated_string(to_escape.as_string()));
|
auto string = TRY(String::from_byte_string(to_escape.as_string()));
|
||||||
|
|
||||||
// All C++ simple escape sequences; see https://en.cppreference.com/w/cpp/language/escape
|
// All C++ simple escape sequences; see https://en.cppreference.com/w/cpp/language/escape
|
||||||
// Other commonly-escaped characters are hard-to-type Unicode and therefore fine to include verbatim in UTF-8 coded strings.
|
// Other commonly-escaped characters are hard-to-type Unicode and therefore fine to include verbatim in UTF-8 coded strings.
|
||||||
|
@ -194,7 +194,7 @@ static ErrorOr<String> generate_initializer_for(Optional<StringView> property_na
|
||||||
{
|
{
|
||||||
if (value.is_string()) {
|
if (value.is_string()) {
|
||||||
if (property_name.has_value()) {
|
if (property_name.has_value()) {
|
||||||
if (takes_deprecated_string(*property_name))
|
if (takes_byte_string(*property_name))
|
||||||
return String::formatted(R"~~~("{}"sv)~~~", TRY(escape_string(value)));
|
return String::formatted(R"~~~("{}"sv)~~~", TRY(escape_string(value)));
|
||||||
|
|
||||||
if (auto const enum_value = TRY(generate_enum_initializer_for(*property_name, value)); enum_value.has_value())
|
if (auto const enum_value = TRY(generate_enum_initializer_for(*property_name, value)); enum_value.has_value())
|
||||||
|
@ -252,7 +252,7 @@ static ErrorOr<String> generate_initializer_for(Optional<StringView> property_na
|
||||||
// All loading happens in a separate block.
|
// All loading happens in a separate block.
|
||||||
static ErrorOr<void> generate_loader_for_object(GUI::GML::Object const& gml_object, SourceGenerator generator, String object_name, size_t indentation, UseObjectConstructor use_object_constructor)
|
static ErrorOr<void> generate_loader_for_object(GUI::GML::Object const& gml_object, SourceGenerator generator, String object_name, size_t indentation, UseObjectConstructor use_object_constructor)
|
||||||
{
|
{
|
||||||
generator.set("object_name", object_name.to_deprecated_string());
|
generator.set("object_name", object_name.to_byte_string());
|
||||||
generator.set("class_name", gml_object.name());
|
generator.set("class_name", gml_object.name());
|
||||||
|
|
||||||
auto append = [&]<size_t N>(auto& generator, char const(&text)[N]) -> ErrorOr<void> {
|
auto append = [&]<size_t N>(auto& generator, char const(&text)[N]) -> ErrorOr<void> {
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct Parameter {
|
struct Parameter {
|
||||||
Vector<DeprecatedString> attributes;
|
Vector<ByteString> attributes;
|
||||||
DeprecatedString type;
|
ByteString type;
|
||||||
DeprecatedString name;
|
ByteString name;
|
||||||
};
|
};
|
||||||
|
|
||||||
static DeprecatedString pascal_case(DeprecatedString const& identifier)
|
static ByteString pascal_case(ByteString const& identifier)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
bool was_new_word = true;
|
bool was_new_word = true;
|
||||||
|
@ -37,48 +37,48 @@ static DeprecatedString pascal_case(DeprecatedString const& identifier)
|
||||||
} else
|
} else
|
||||||
builder.append(ch);
|
builder.append(ch);
|
||||||
}
|
}
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Message {
|
struct Message {
|
||||||
DeprecatedString name;
|
ByteString name;
|
||||||
bool is_synchronous { false };
|
bool is_synchronous { false };
|
||||||
Vector<Parameter> inputs;
|
Vector<Parameter> inputs;
|
||||||
Vector<Parameter> outputs;
|
Vector<Parameter> outputs;
|
||||||
|
|
||||||
DeprecatedString response_name() const
|
ByteString response_name() const
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(pascal_case(name));
|
builder.append(pascal_case(name));
|
||||||
builder.append("Response"sv);
|
builder.append("Response"sv);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Endpoint {
|
struct Endpoint {
|
||||||
Vector<DeprecatedString> includes;
|
Vector<ByteString> includes;
|
||||||
DeprecatedString name;
|
ByteString name;
|
||||||
u32 magic;
|
u32 magic;
|
||||||
Vector<Message> messages;
|
Vector<Message> messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool is_primitive_type(DeprecatedString const& type)
|
static bool is_primitive_type(ByteString const& type)
|
||||||
{
|
{
|
||||||
return type.is_one_of("u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "size_t", "bool", "double", "float", "int", "unsigned", "unsigned int");
|
return type.is_one_of("u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "size_t", "bool", "double", "float", "int", "unsigned", "unsigned int");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_simple_type(DeprecatedString const& type)
|
static bool is_simple_type(ByteString const& type)
|
||||||
{
|
{
|
||||||
// Small types that it makes sense just to pass by value.
|
// Small types that it makes sense just to pass by value.
|
||||||
return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode");
|
return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_primitive_or_simple_type(DeprecatedString const& type)
|
static bool is_primitive_or_simple_type(ByteString const& type)
|
||||||
{
|
{
|
||||||
return is_primitive_type(type) || is_simple_type(type);
|
return is_primitive_type(type) || is_simple_type(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeprecatedString message_name(DeprecatedString const& endpoint, DeprecatedString const& message, bool is_response)
|
static ByteString message_name(ByteString const& endpoint, ByteString const& message, bool is_response)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append("Messages::"sv);
|
builder.append("Messages::"sv);
|
||||||
|
@ -87,7 +87,7 @@ static DeprecatedString message_name(DeprecatedString const& endpoint, Deprecate
|
||||||
builder.append(pascal_case(message));
|
builder.append(pascal_case(message));
|
||||||
if (is_response)
|
if (is_response)
|
||||||
builder.append("Response"sv);
|
builder.append("Response"sv);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
||||||
|
@ -133,7 +133,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
||||||
consume_whitespace();
|
consume_whitespace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, DeprecatedString>`.
|
// FIXME: This is not entirely correct. Types can have spaces, for example `HashMap<int, ByteString>`.
|
||||||
// Maybe we should use LibCpp::Parser for parsing types.
|
// Maybe we should use LibCpp::Parser for parsing types.
|
||||||
parameter.type = lexer.consume_until([](char ch) { return isspace(ch); });
|
parameter.type = lexer.consume_until([](char ch) { return isspace(ch); });
|
||||||
if (parameter.type.ends_with(',')) {
|
if (parameter.type.ends_with(',')) {
|
||||||
|
@ -208,7 +208,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parse_include = [&] {
|
auto parse_include = [&] {
|
||||||
DeprecatedString include;
|
ByteString include;
|
||||||
consume_whitespace();
|
consume_whitespace();
|
||||||
include = lexer.consume_while([](char ch) { return ch != '\n'; });
|
include = lexer.consume_while([](char ch) { return ch != '\n'; });
|
||||||
consume_whitespace();
|
consume_whitespace();
|
||||||
|
@ -234,7 +234,7 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
||||||
lexer.consume_specific("endpoint");
|
lexer.consume_specific("endpoint");
|
||||||
consume_whitespace();
|
consume_whitespace();
|
||||||
endpoints.last().name = lexer.consume_while([](char ch) { return !isspace(ch); });
|
endpoints.last().name = lexer.consume_while([](char ch) { return !isspace(ch); });
|
||||||
endpoints.last().magic = Traits<DeprecatedString>::hash(endpoints.last().name);
|
endpoints.last().magic = Traits<ByteString>::hash(endpoints.last().name);
|
||||||
consume_whitespace();
|
consume_whitespace();
|
||||||
assert_specific('{');
|
assert_specific('{');
|
||||||
parse_messages();
|
parse_messages();
|
||||||
|
@ -248,22 +248,22 @@ Vector<Endpoint> parse(ByteBuffer const& file_contents)
|
||||||
return endpoints;
|
return endpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<DeprecatedString, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
|
HashMap<ByteString, int> build_message_ids_for_endpoint(SourceGenerator generator, Endpoint const& endpoint)
|
||||||
{
|
{
|
||||||
HashMap<DeprecatedString, int> message_ids;
|
HashMap<ByteString, int> message_ids;
|
||||||
|
|
||||||
generator.appendln("\nenum class MessageID : i32 {");
|
generator.appendln("\nenum class MessageID : i32 {");
|
||||||
for (auto const& message : endpoint.messages) {
|
for (auto const& message : endpoint.messages) {
|
||||||
|
|
||||||
message_ids.set(message.name, message_ids.size() + 1);
|
message_ids.set(message.name, message_ids.size() + 1);
|
||||||
generator.set("message.pascal_name", pascal_case(message.name));
|
generator.set("message.pascal_name", pascal_case(message.name));
|
||||||
generator.set("message.id", DeprecatedString::number(message_ids.size()));
|
generator.set("message.id", ByteString::number(message_ids.size()));
|
||||||
|
|
||||||
generator.appendln(" @message.pascal_name@ = @message.id@,");
|
generator.appendln(" @message.pascal_name@ = @message.id@,");
|
||||||
if (message.is_synchronous) {
|
if (message.is_synchronous) {
|
||||||
message_ids.set(message.response_name(), message_ids.size() + 1);
|
message_ids.set(message.response_name(), message_ids.size() + 1);
|
||||||
generator.set("message.pascal_name", pascal_case(message.response_name()));
|
generator.set("message.pascal_name", pascal_case(message.response_name()));
|
||||||
generator.set("message.id", DeprecatedString::number(message_ids.size()));
|
generator.set("message.id", ByteString::number(message_ids.size()));
|
||||||
|
|
||||||
generator.appendln(" @message.pascal_name@ = @message.id@,");
|
generator.appendln(" @message.pascal_name@ = @message.id@,");
|
||||||
}
|
}
|
||||||
|
@ -272,14 +272,14 @@ HashMap<DeprecatedString, int> build_message_ids_for_endpoint(SourceGenerator ge
|
||||||
return message_ids;
|
return message_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString constructor_for_message(DeprecatedString const& name, Vector<Parameter> const& parameters)
|
ByteString constructor_for_message(ByteString const& name, Vector<Parameter> const& parameters)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(name);
|
builder.append(name);
|
||||||
|
|
||||||
if (parameters.is_empty()) {
|
if (parameters.is_empty()) {
|
||||||
builder.append("() {}"sv);
|
builder.append("() {}"sv);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
builder.append('(');
|
builder.append('(');
|
||||||
for (size_t i = 0; i < parameters.size(); ++i) {
|
for (size_t i = 0; i < parameters.size(); ++i) {
|
||||||
|
@ -296,10 +296,10 @@ DeprecatedString constructor_for_message(DeprecatedString const& name, Vector<Pa
|
||||||
builder.append(", "sv);
|
builder.append(", "sv);
|
||||||
}
|
}
|
||||||
builder.append(" {}"sv);
|
builder.append(" {}"sv);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_message(SourceGenerator message_generator, DeprecatedString const& name, Vector<Parameter> const& parameters, DeprecatedString const& response_type = {})
|
void do_message(SourceGenerator message_generator, ByteString const& name, Vector<Parameter> const& parameters, ByteString const& response_type = {})
|
||||||
{
|
{
|
||||||
auto pascal_name = pascal_case(name);
|
auto pascal_name = pascal_case(name);
|
||||||
message_generator.set("message.name", name);
|
message_generator.set("message.name", name);
|
||||||
|
@ -377,7 +377,7 @@ public:)~~~");
|
||||||
builder.append(", "sv);
|
builder.append(", "sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
message_generator.set("message.constructor_call_parameters", builder.to_deprecated_string());
|
message_generator.set("message.constructor_call_parameters", builder.to_byte_string());
|
||||||
message_generator.appendln(R"~~~(
|
message_generator.appendln(R"~~~(
|
||||||
return make<@message.pascal_name@>(@message.constructor_call_parameters@);
|
return make<@message.pascal_name@>(@message.constructor_call_parameters@);
|
||||||
})~~~");
|
})~~~");
|
||||||
|
@ -432,17 +432,17 @@ private:
|
||||||
|
|
||||||
void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& endpoint, Message const& message)
|
void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& endpoint, Message const& message)
|
||||||
{
|
{
|
||||||
auto do_implement_proxy = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
|
auto do_implement_proxy = [&](ByteString const& name, Vector<Parameter> const& parameters, bool is_synchronous, bool is_try) {
|
||||||
DeprecatedString return_type = "void";
|
ByteString return_type = "void";
|
||||||
if (is_synchronous) {
|
if (is_synchronous) {
|
||||||
if (message.outputs.size() == 1)
|
if (message.outputs.size() == 1)
|
||||||
return_type = message.outputs[0].type;
|
return_type = message.outputs[0].type;
|
||||||
else if (!message.outputs.is_empty())
|
else if (!message.outputs.is_empty())
|
||||||
return_type = message_name(endpoint.name, message.name, true);
|
return_type = message_name(endpoint.name, message.name, true);
|
||||||
}
|
}
|
||||||
DeprecatedString inner_return_type = return_type;
|
ByteString inner_return_type = return_type;
|
||||||
if (is_try)
|
if (is_try)
|
||||||
return_type = DeprecatedString::formatted("IPC::IPCErrorOr<{}>", return_type);
|
return_type = ByteString::formatted("IPC::IPCErrorOr<{}>", return_type);
|
||||||
|
|
||||||
message_generator.set("message.name", message.name);
|
message_generator.set("message.name", message.name);
|
||||||
message_generator.set("message.pascal_name", pascal_case(message.name));
|
message_generator.set("message.pascal_name", pascal_case(message.name));
|
||||||
|
@ -541,14 +541,14 @@ void do_message_for_proxy(SourceGenerator message_generator, Endpoint const& end
|
||||||
void build_endpoint(SourceGenerator generator, Endpoint const& endpoint)
|
void build_endpoint(SourceGenerator generator, Endpoint const& endpoint)
|
||||||
{
|
{
|
||||||
generator.set("endpoint.name", endpoint.name);
|
generator.set("endpoint.name", endpoint.name);
|
||||||
generator.set("endpoint.magic", DeprecatedString::number(endpoint.magic));
|
generator.set("endpoint.magic", ByteString::number(endpoint.magic));
|
||||||
|
|
||||||
generator.appendln("\nnamespace Messages::@endpoint.name@ {");
|
generator.appendln("\nnamespace Messages::@endpoint.name@ {");
|
||||||
|
|
||||||
HashMap<DeprecatedString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
|
HashMap<ByteString, int> message_ids = build_message_ids_for_endpoint(generator.fork(), endpoint);
|
||||||
|
|
||||||
for (auto const& message : endpoint.messages) {
|
for (auto const& message : endpoint.messages) {
|
||||||
DeprecatedString response_name;
|
ByteString response_name;
|
||||||
if (message.is_synchronous) {
|
if (message.is_synchronous) {
|
||||||
response_name = message.response_name();
|
response_name = message.response_name();
|
||||||
do_message(generator.fork(), response_name, message.outputs);
|
do_message(generator.fork(), response_name, message.outputs);
|
||||||
|
@ -611,7 +611,7 @@ public:
|
||||||
switch (message_id) {)~~~");
|
switch (message_id) {)~~~");
|
||||||
|
|
||||||
for (auto const& message : endpoint.messages) {
|
for (auto const& message : endpoint.messages) {
|
||||||
auto do_decode_message = [&](DeprecatedString const& name) {
|
auto do_decode_message = [&](ByteString const& name) {
|
||||||
auto message_generator = generator.fork();
|
auto message_generator = generator.fork();
|
||||||
|
|
||||||
message_generator.set("message.name", name);
|
message_generator.set("message.name", name);
|
||||||
|
@ -649,13 +649,13 @@ public:
|
||||||
virtual ~@endpoint.name@Stub() override { }
|
virtual ~@endpoint.name@Stub() override { }
|
||||||
|
|
||||||
virtual u32 magic() const override { return @endpoint.magic@; }
|
virtual u32 magic() const override { return @endpoint.magic@; }
|
||||||
virtual DeprecatedString name() const override { return "@endpoint.name@"; }
|
virtual ByteString name() const override { return "@endpoint.name@"; }
|
||||||
|
|
||||||
virtual ErrorOr<OwnPtr<IPC::MessageBuffer>> handle(const IPC::Message& message) override
|
virtual ErrorOr<OwnPtr<IPC::MessageBuffer>> handle(const IPC::Message& message) override
|
||||||
{
|
{
|
||||||
switch (message.message_id()) {)~~~");
|
switch (message.message_id()) {)~~~");
|
||||||
for (auto const& message : endpoint.messages) {
|
for (auto const& message : endpoint.messages) {
|
||||||
auto do_handle_message = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool returns_something) {
|
auto do_handle_message = [&](ByteString const& name, Vector<Parameter> const& parameters, bool returns_something) {
|
||||||
auto message_generator = generator.fork();
|
auto message_generator = generator.fork();
|
||||||
|
|
||||||
StringBuilder argument_generator;
|
StringBuilder argument_generator;
|
||||||
|
@ -671,7 +671,7 @@ public:
|
||||||
message_generator.set("message.pascal_name", pascal_case(name));
|
message_generator.set("message.pascal_name", pascal_case(name));
|
||||||
message_generator.set("message.response_type", pascal_case(message.response_name()));
|
message_generator.set("message.response_type", pascal_case(message.response_name()));
|
||||||
message_generator.set("handler_name", name);
|
message_generator.set("handler_name", name);
|
||||||
message_generator.set("arguments", argument_generator.to_deprecated_string());
|
message_generator.set("arguments", argument_generator.to_byte_string());
|
||||||
message_generator.appendln(R"~~~(
|
message_generator.appendln(R"~~~(
|
||||||
case (int)Messages::@endpoint.name@::MessageID::@message.pascal_name@: {)~~~");
|
case (int)Messages::@endpoint.name@::MessageID::@message.pascal_name@: {)~~~");
|
||||||
if (returns_something) {
|
if (returns_something) {
|
||||||
|
@ -709,8 +709,8 @@ public:
|
||||||
for (auto const& message : endpoint.messages) {
|
for (auto const& message : endpoint.messages) {
|
||||||
auto message_generator = generator.fork();
|
auto message_generator = generator.fork();
|
||||||
|
|
||||||
auto do_handle_message_decl = [&](DeprecatedString const& name, Vector<Parameter> const& parameters, bool is_response) {
|
auto do_handle_message_decl = [&](ByteString const& name, Vector<Parameter> const& parameters, bool is_response) {
|
||||||
DeprecatedString return_type = "void";
|
ByteString return_type = "void";
|
||||||
if (message.is_synchronous && !message.outputs.is_empty() && !is_response)
|
if (message.is_synchronous && !message.outputs.is_empty() && !is_response)
|
||||||
return_type = message_name(endpoint.name, message.name, true);
|
return_type = message_name(endpoint.name, message.name, true);
|
||||||
message_generator.set("message.complex_return_type", return_type);
|
message_generator.set("message.complex_return_type", return_type);
|
||||||
|
@ -719,7 +719,7 @@ public:
|
||||||
message_generator.appendln(R"~~~(
|
message_generator.appendln(R"~~~(
|
||||||
virtual @message.complex_return_type@ @handler_name@()~~~");
|
virtual @message.complex_return_type@ @handler_name@()~~~");
|
||||||
|
|
||||||
auto make_argument_type = [](DeprecatedString const& type) {
|
auto make_argument_type = [](ByteString const& type) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
bool const_ref = !is_primitive_or_simple_type(type);
|
bool const_ref = !is_primitive_or_simple_type(type);
|
||||||
|
@ -728,7 +728,7 @@ public:
|
||||||
if (const_ref)
|
if (const_ref)
|
||||||
builder.append(" const&"sv);
|
builder.append(" const&"sv);
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < parameters.size(); ++i) {
|
for (size_t i = 0; i < parameters.size(); ++i) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/NumericLimits.h>
|
#include <AK/NumericLimits.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
|
@ -18,40 +18,40 @@
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
|
|
||||||
struct ArgumentDefinition {
|
struct ArgumentDefinition {
|
||||||
Optional<DeprecatedString> name;
|
Optional<ByteString> name;
|
||||||
Optional<DeprecatedString> cpp_type;
|
Optional<ByteString> cpp_type;
|
||||||
DeprecatedString expression;
|
ByteString expression;
|
||||||
Optional<DeprecatedString> cast_to;
|
Optional<ByteString> cast_to;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FunctionDefinition {
|
struct FunctionDefinition {
|
||||||
DeprecatedString name;
|
ByteString name;
|
||||||
DeprecatedString return_type;
|
ByteString return_type;
|
||||||
Vector<ArgumentDefinition> arguments;
|
Vector<ArgumentDefinition> arguments;
|
||||||
DeprecatedString implementation;
|
ByteString implementation;
|
||||||
bool unimplemented;
|
bool unimplemented;
|
||||||
DeprecatedString variant_gl_type;
|
ByteString variant_gl_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VariantType {
|
struct VariantType {
|
||||||
DeprecatedString encoded_type;
|
ByteString encoded_type;
|
||||||
Optional<DeprecatedString> implementation;
|
Optional<ByteString> implementation;
|
||||||
bool unimplemented;
|
bool unimplemented;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Variants {
|
struct Variants {
|
||||||
Vector<DeprecatedString> api_suffixes { "" };
|
Vector<ByteString> api_suffixes { "" };
|
||||||
Vector<u32> argument_counts { NumericLimits<u32>::max() };
|
Vector<u32> argument_counts { NumericLimits<u32>::max() };
|
||||||
Vector<DeprecatedString> argument_defaults { "" };
|
Vector<ByteString> argument_defaults { "" };
|
||||||
bool convert_range { false };
|
bool convert_range { false };
|
||||||
Vector<VariantType> types {
|
Vector<VariantType> types {
|
||||||
{
|
{
|
||||||
.encoded_type = "",
|
.encoded_type = "",
|
||||||
.implementation = Optional<DeprecatedString> {},
|
.implementation = Optional<ByteString> {},
|
||||||
.unimplemented = false,
|
.unimplemented = false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
DeprecatedString pointer_argument { "" };
|
ByteString pointer_argument { "" };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EncodedTypeEntry {
|
struct EncodedTypeEntry {
|
||||||
|
@ -76,18 +76,18 @@ constexpr static Array<EncodedTypeEntry, 9> type_definitions = {
|
||||||
|
|
||||||
struct EncodedType {
|
struct EncodedType {
|
||||||
EncodedTypeEntry type_entry;
|
EncodedTypeEntry type_entry;
|
||||||
DeprecatedString cpp_type;
|
ByteString cpp_type;
|
||||||
DeprecatedString function_name_suffix;
|
ByteString function_name_suffix;
|
||||||
bool is_pointer;
|
bool is_pointer;
|
||||||
bool is_const_pointer;
|
bool is_const_pointer;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<DeprecatedString> get_name_list(Optional<JsonValue const&> name_definition)
|
Vector<ByteString> get_name_list(Optional<JsonValue const&> name_definition)
|
||||||
{
|
{
|
||||||
if (!name_definition.has_value() || name_definition->is_null())
|
if (!name_definition.has_value() || name_definition->is_null())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
Vector<DeprecatedString, 1> names;
|
Vector<ByteString, 1> names;
|
||||||
if (name_definition->is_string()) {
|
if (name_definition->is_string()) {
|
||||||
names.append(name_definition->as_string());
|
names.append(name_definition->as_string());
|
||||||
} else if (name_definition->is_array()) {
|
} else if (name_definition->is_array()) {
|
||||||
|
@ -101,12 +101,12 @@ Vector<DeprecatedString> get_name_list(Optional<JsonValue const&> name_definitio
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<EncodedType> get_encoded_type(DeprecatedString encoded_type)
|
Optional<EncodedType> get_encoded_type(ByteString encoded_type)
|
||||||
{
|
{
|
||||||
bool is_const_pointer = !encoded_type.ends_with('!');
|
bool is_const_pointer = !encoded_type.ends_with('!');
|
||||||
if (!is_const_pointer)
|
if (!is_const_pointer)
|
||||||
encoded_type = encoded_type.substring_view(0, encoded_type.length() - 1);
|
encoded_type = encoded_type.substring_view(0, encoded_type.length() - 1);
|
||||||
DeprecatedString function_name_suffix = encoded_type;
|
ByteString function_name_suffix = encoded_type;
|
||||||
|
|
||||||
bool is_pointer = encoded_type.ends_with('v');
|
bool is_pointer = encoded_type.ends_with('v');
|
||||||
if (is_pointer)
|
if (is_pointer)
|
||||||
|
@ -127,7 +127,7 @@ Optional<EncodedType> get_encoded_type(DeprecatedString encoded_type)
|
||||||
|
|
||||||
return EncodedType {
|
return EncodedType {
|
||||||
.type_entry = type_definition.value(),
|
.type_entry = type_definition.value(),
|
||||||
.cpp_type = DeprecatedString::formatted(
|
.cpp_type = ByteString::formatted(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
type_definition->cpp_type,
|
type_definition->cpp_type,
|
||||||
is_pointer && is_const_pointer ? " const" : "",
|
is_pointer && is_const_pointer ? " const" : "",
|
||||||
|
@ -138,7 +138,7 @@ Optional<EncodedType> get_encoded_type(DeprecatedString encoded_type)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString wrap_expression_in_range_conversion(DeprecatedString source_type, DeprecatedString target_type, DeprecatedString expression)
|
ByteString wrap_expression_in_range_conversion(ByteString source_type, ByteString target_type, ByteString expression)
|
||||||
{
|
{
|
||||||
VERIFY(target_type == "GLfloat" || target_type == "GLdouble");
|
VERIFY(target_type == "GLfloat" || target_type == "GLdouble");
|
||||||
|
|
||||||
|
@ -147,19 +147,19 @@ DeprecatedString wrap_expression_in_range_conversion(DeprecatedString source_typ
|
||||||
return expression;
|
return expression;
|
||||||
|
|
||||||
if (source_type == "GLbyte")
|
if (source_type == "GLbyte")
|
||||||
return DeprecatedString::formatted("({} + 128.) / 127.5 - 1.", expression);
|
return ByteString::formatted("({} + 128.) / 127.5 - 1.", expression);
|
||||||
else if (source_type == "GLfloat")
|
else if (source_type == "GLfloat")
|
||||||
return DeprecatedString::formatted("static_cast<GLdouble>({})", expression);
|
return ByteString::formatted("static_cast<GLdouble>({})", expression);
|
||||||
else if (source_type == "GLint")
|
else if (source_type == "GLint")
|
||||||
return DeprecatedString::formatted("({} + 2147483648.) / 2147483647.5 - 1.", expression);
|
return ByteString::formatted("({} + 2147483648.) / 2147483647.5 - 1.", expression);
|
||||||
else if (source_type == "GLshort")
|
else if (source_type == "GLshort")
|
||||||
return DeprecatedString::formatted("({} + 32768.) / 32767.5 - 1.", expression);
|
return ByteString::formatted("({} + 32768.) / 32767.5 - 1.", expression);
|
||||||
else if (source_type == "GLubyte")
|
else if (source_type == "GLubyte")
|
||||||
return DeprecatedString::formatted("{} / 255.", expression);
|
return ByteString::formatted("{} / 255.", expression);
|
||||||
else if (source_type == "GLuint")
|
else if (source_type == "GLuint")
|
||||||
return DeprecatedString::formatted("{} / 4294967296.", expression);
|
return ByteString::formatted("{} / 4294967296.", expression);
|
||||||
else if (source_type == "GLushort")
|
else if (source_type == "GLushort")
|
||||||
return DeprecatedString::formatted("{} / 65536.", expression);
|
return ByteString::formatted("{} / 65536.", expression);
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ Variants read_variants_settings(JsonObject const& variants_obj)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (variants_obj.has_string("pointer_argument"sv)) {
|
if (variants_obj.has_string("pointer_argument"sv)) {
|
||||||
variants.pointer_argument = variants_obj.get_deprecated_string("pointer_argument"sv).value();
|
variants.pointer_argument = variants_obj.get_byte_string("pointer_argument"sv).value();
|
||||||
}
|
}
|
||||||
if (variants_obj.has_object("types"sv)) {
|
if (variants_obj.has_object("types"sv)) {
|
||||||
variants.types.clear_with_capacity();
|
variants.types.clear_with_capacity();
|
||||||
|
@ -197,7 +197,7 @@ Variants read_variants_settings(JsonObject const& variants_obj)
|
||||||
auto const& type = type_value.as_object();
|
auto const& type = type_value.as_object();
|
||||||
variants.types.append(VariantType {
|
variants.types.append(VariantType {
|
||||||
.encoded_type = key,
|
.encoded_type = key,
|
||||||
.implementation = type.get_deprecated_string("implementation"sv),
|
.implementation = type.get_byte_string("implementation"sv),
|
||||||
.unimplemented = type.get_bool("unimplemented"sv).value_or(false),
|
.unimplemented = type.get_bool("unimplemented"sv).value_or(false),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -223,20 +223,20 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
|
||||||
|
|
||||||
// Pointer argument
|
// Pointer argument
|
||||||
if (encoded_type.is_pointer) {
|
if (encoded_type.is_pointer) {
|
||||||
variant_arguments[i].name = (variadic_index == 0) ? variants.pointer_argument : Optional<DeprecatedString> {};
|
variant_arguments[i].name = (variadic_index == 0) ? variants.pointer_argument : Optional<ByteString> {};
|
||||||
|
|
||||||
if (variadic_index >= argument_count) {
|
if (variadic_index >= argument_count) {
|
||||||
// If this variable argument is past the argument count, fall back to the defaults
|
// If this variable argument is past the argument count, fall back to the defaults
|
||||||
variant_arguments[i].expression = variants.argument_defaults[variadic_index];
|
variant_arguments[i].expression = variants.argument_defaults[variadic_index];
|
||||||
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
|
variant_arguments[i].cast_to = Optional<ByteString> {};
|
||||||
|
|
||||||
} else if (argument_count == 1 && variants.argument_counts.size() == 1) {
|
} else if (argument_count == 1 && variants.argument_counts.size() == 1) {
|
||||||
// Otherwise, if the pointer is the only variadic argument, pass it through unchanged
|
// Otherwise, if the pointer is the only variadic argument, pass it through unchanged
|
||||||
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
|
variant_arguments[i].cast_to = Optional<ByteString> {};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, index into the pointer argument
|
// Otherwise, index into the pointer argument
|
||||||
auto indexed_expression = DeprecatedString::formatted("{}[{}]", variants.pointer_argument, variadic_index);
|
auto indexed_expression = ByteString::formatted("{}[{}]", variants.pointer_argument, variadic_index);
|
||||||
if (variants.convert_range && cast_to.has_value())
|
if (variants.convert_range && cast_to.has_value())
|
||||||
indexed_expression = wrap_expression_in_range_conversion(base_cpp_type, cast_to.value(), indexed_expression);
|
indexed_expression = wrap_expression_in_range_conversion(base_cpp_type, cast_to.value(), indexed_expression);
|
||||||
variant_arguments[i].expression = indexed_expression;
|
variant_arguments[i].expression = indexed_expression;
|
||||||
|
@ -246,9 +246,9 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
|
||||||
// Regular argument
|
// Regular argument
|
||||||
if (variadic_index >= argument_count) {
|
if (variadic_index >= argument_count) {
|
||||||
// If the variable argument is past the argument count, fall back to the defaults
|
// If the variable argument is past the argument count, fall back to the defaults
|
||||||
variant_arguments[i].name = Optional<DeprecatedString> {};
|
variant_arguments[i].name = Optional<ByteString> {};
|
||||||
variant_arguments[i].expression = variants.argument_defaults[variadic_index];
|
variant_arguments[i].expression = variants.argument_defaults[variadic_index];
|
||||||
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
|
variant_arguments[i].cast_to = Optional<ByteString> {};
|
||||||
|
|
||||||
} else if (variants.convert_range && cast_to.has_value()) {
|
} else if (variants.convert_range && cast_to.has_value()) {
|
||||||
// Otherwise, if we need to convert the input values, wrap the expression in a range conversion
|
// Otherwise, if we need to convert the input values, wrap the expression in a range conversion
|
||||||
|
@ -261,7 +261,7 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
|
||||||
|
|
||||||
// Determine if we can skip casting to the target type
|
// Determine if we can skip casting to the target type
|
||||||
if (cast_to == base_cpp_type || (variants.convert_range && cast_to == "GLdouble"))
|
if (cast_to == base_cpp_type || (variants.convert_range && cast_to == "GLdouble"))
|
||||||
variant_arguments[i].cast_to = Optional<DeprecatedString> {};
|
variant_arguments[i].cast_to = Optional<ByteString> {};
|
||||||
|
|
||||||
variadic_index++;
|
variadic_index++;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ Vector<ArgumentDefinition> copy_arguments_for_variant(Vector<ArgumentDefinition>
|
||||||
return variant_arguments;
|
return variant_arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<FunctionDefinition> create_function_definitions(DeprecatedString function_name, JsonObject const& function_definition)
|
Vector<FunctionDefinition> create_function_definitions(ByteString function_name, JsonObject const& function_definition)
|
||||||
{
|
{
|
||||||
// A single function definition can expand to multiple generated functions by way of:
|
// A single function definition can expand to multiple generated functions by way of:
|
||||||
// - differing API suffices (ARB, EXT, etc.);
|
// - differing API suffices (ARB, EXT, etc.);
|
||||||
|
@ -284,17 +284,17 @@ Vector<FunctionDefinition> create_function_definitions(DeprecatedString function
|
||||||
VERIFY(argument_value.is_object());
|
VERIFY(argument_value.is_object());
|
||||||
auto const& argument = argument_value.as_object();
|
auto const& argument = argument_value.as_object();
|
||||||
|
|
||||||
auto type = argument.get_deprecated_string("type"sv);
|
auto type = argument.get_byte_string("type"sv);
|
||||||
auto argument_names = get_name_list(argument.get("name"sv));
|
auto argument_names = get_name_list(argument.get("name"sv));
|
||||||
auto expression = argument.get_deprecated_string("expression"sv).value_or("@argument_name@");
|
auto expression = argument.get_byte_string("expression"sv).value_or("@argument_name@");
|
||||||
auto cast_to = argument.get_deprecated_string("cast_to"sv);
|
auto cast_to = argument.get_byte_string("cast_to"sv);
|
||||||
|
|
||||||
// Add an empty dummy name when all we have is an expression
|
// Add an empty dummy name when all we have is an expression
|
||||||
if (argument_names.is_empty() && !expression.is_empty())
|
if (argument_names.is_empty() && !expression.is_empty())
|
||||||
argument_names.append("");
|
argument_names.append("");
|
||||||
|
|
||||||
for (auto const& argument_name : argument_names) {
|
for (auto const& argument_name : argument_names) {
|
||||||
argument_definitions.append({ .name = argument_name.is_empty() ? Optional<DeprecatedString> {} : argument_name,
|
argument_definitions.append({ .name = argument_name.is_empty() ? Optional<ByteString> {} : argument_name,
|
||||||
.cpp_type = type,
|
.cpp_type = type,
|
||||||
.expression = expression,
|
.expression = expression,
|
||||||
.cast_to = cast_to });
|
.cast_to = cast_to });
|
||||||
|
@ -304,8 +304,8 @@ Vector<FunctionDefinition> create_function_definitions(DeprecatedString function
|
||||||
// Create functions for each name and/or variant
|
// Create functions for each name and/or variant
|
||||||
Vector<FunctionDefinition> functions;
|
Vector<FunctionDefinition> functions;
|
||||||
|
|
||||||
auto return_type = function_definition.get_deprecated_string("return_type"sv).value_or("void");
|
auto return_type = function_definition.get_byte_string("return_type"sv).value_or("void");
|
||||||
auto function_implementation = function_definition.get_deprecated_string("implementation"sv).value_or(function_name.to_snakecase());
|
auto function_implementation = function_definition.get_byte_string("implementation"sv).value_or(function_name.to_snakecase());
|
||||||
auto function_unimplemented = function_definition.get_bool("unimplemented"sv).value_or(false);
|
auto function_unimplemented = function_definition.get_bool("unimplemented"sv).value_or(false);
|
||||||
|
|
||||||
if (!function_definition.has("variants"sv)) {
|
if (!function_definition.has("variants"sv)) {
|
||||||
|
@ -336,10 +336,10 @@ Vector<FunctionDefinition> create_function_definitions(DeprecatedString function
|
||||||
|
|
||||||
for (auto const& api_suffix : variants.api_suffixes) {
|
for (auto const& api_suffix : variants.api_suffixes) {
|
||||||
functions.append({
|
functions.append({
|
||||||
.name = DeprecatedString::formatted(
|
.name = ByteString::formatted(
|
||||||
"{}{}{}{}",
|
"{}{}{}{}",
|
||||||
function_name,
|
function_name,
|
||||||
variants.argument_counts.size() > 1 ? DeprecatedString::formatted("{}", argument_count) : "",
|
variants.argument_counts.size() > 1 ? ByteString::formatted("{}", argument_count) : "",
|
||||||
encoded_type.has_value() && variants.types.size() > 1 ? encoded_type->function_name_suffix : "",
|
encoded_type.has_value() && variants.types.size() > 1 ? encoded_type->function_name_suffix : "",
|
||||||
api_suffix),
|
api_suffix),
|
||||||
.return_type = return_type,
|
.return_type = return_type,
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
||||||
#include <AK/AllOf.h>
|
#include <AK/AllOf.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Find.h>
|
#include <AK/Find.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
|
@ -487,7 +487,7 @@ struct AK::Formatter<Locale::HourCycle> : Formatter<FormatString> {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LocaleData {
|
struct LocaleData {
|
||||||
HashMap<DeprecatedString, size_t> calendars;
|
HashMap<ByteString, size_t> calendars;
|
||||||
|
|
||||||
size_t time_zones { 0 };
|
size_t time_zones { 0 };
|
||||||
size_t time_zone_formats { 0 };
|
size_t time_zone_formats { 0 };
|
||||||
|
@ -513,27 +513,27 @@ struct CLDR {
|
||||||
UniqueStorage<DayPeriodList> unique_day_period_lists;
|
UniqueStorage<DayPeriodList> unique_day_period_lists;
|
||||||
UniqueStorage<HourCycleList> unique_hour_cycle_lists;
|
UniqueStorage<HourCycleList> unique_hour_cycle_lists;
|
||||||
|
|
||||||
HashMap<DeprecatedString, LocaleData> locales;
|
HashMap<ByteString, LocaleData> locales;
|
||||||
|
|
||||||
HashMap<DeprecatedString, size_t> hour_cycles;
|
HashMap<ByteString, size_t> hour_cycles;
|
||||||
Vector<DeprecatedString> hour_cycle_regions;
|
Vector<ByteString> hour_cycle_regions;
|
||||||
|
|
||||||
HashMap<DeprecatedString, u8> minimum_days;
|
HashMap<ByteString, u8> minimum_days;
|
||||||
Vector<DeprecatedString> minimum_days_regions;
|
Vector<ByteString> minimum_days_regions;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Locale::Weekday> first_day;
|
HashMap<ByteString, Locale::Weekday> first_day;
|
||||||
Vector<DeprecatedString> first_day_regions;
|
Vector<ByteString> first_day_regions;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Locale::Weekday> weekend_start;
|
HashMap<ByteString, Locale::Weekday> weekend_start;
|
||||||
Vector<DeprecatedString> weekend_start_regions;
|
Vector<ByteString> weekend_start_regions;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Locale::Weekday> weekend_end;
|
HashMap<ByteString, Locale::Weekday> weekend_end;
|
||||||
Vector<DeprecatedString> weekend_end_regions;
|
Vector<ByteString> weekend_end_regions;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Vector<TimeZone::TimeZone>> meta_zones;
|
HashMap<ByteString, Vector<TimeZone::TimeZone>> meta_zones;
|
||||||
Vector<DeprecatedString> time_zones { "UTC"sv };
|
Vector<ByteString> time_zones { "UTC"sv };
|
||||||
|
|
||||||
Vector<DeprecatedString> calendars;
|
Vector<ByteString> calendars;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Optional<Locale::DayPeriod> day_period_from_string(StringView day_period)
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_hour_cycles(DeprecatedString core_path, CLDR& cldr)
|
static ErrorOr<void> parse_hour_cycles(ByteString core_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Data
|
// https://unicode.org/reports/tr35/tr35-dates.html#Time_Data
|
||||||
LexicalPath time_data_path(move(core_path));
|
LexicalPath time_data_path(move(core_path));
|
||||||
|
@ -587,7 +587,7 @@ static ErrorOr<void> parse_hour_cycles(DeprecatedString core_path, CLDR& cldr)
|
||||||
};
|
};
|
||||||
|
|
||||||
time_data_object.for_each_member([&](auto const& key, JsonValue const& value) {
|
time_data_object.for_each_member([&](auto const& key, JsonValue const& value) {
|
||||||
auto allowed_hour_cycles_string = value.as_object().get_deprecated_string("_allowed"sv).value();
|
auto allowed_hour_cycles_string = value.as_object().get_byte_string("_allowed"sv).value();
|
||||||
auto allowed_hour_cycles = allowed_hour_cycles_string.split_view(' ');
|
auto allowed_hour_cycles = allowed_hour_cycles_string.split_view(' ');
|
||||||
|
|
||||||
Vector<Locale::HourCycle> hour_cycles;
|
Vector<Locale::HourCycle> hour_cycles;
|
||||||
|
@ -607,7 +607,7 @@ static ErrorOr<void> parse_hour_cycles(DeprecatedString core_path, CLDR& cldr)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_week_data(DeprecatedString core_path, CLDR& cldr)
|
static ErrorOr<void> parse_week_data(ByteString core_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
// https://unicode.org/reports/tr35/tr35-dates.html#Week_Data
|
// https://unicode.org/reports/tr35/tr35-dates.html#Week_Data
|
||||||
LexicalPath week_data_path(move(core_path));
|
LexicalPath week_data_path(move(core_path));
|
||||||
|
@ -672,7 +672,7 @@ static ErrorOr<void> parse_week_data(DeprecatedString core_path, CLDR& cldr)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_meta_zones(DeprecatedString core_path, CLDR& cldr)
|
static ErrorOr<void> parse_meta_zones(ByteString core_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
// https://unicode.org/reports/tr35/tr35-dates.html#Metazones
|
// https://unicode.org/reports/tr35/tr35-dates.html#Metazones
|
||||||
LexicalPath meta_zone_path(move(core_path));
|
LexicalPath meta_zone_path(move(core_path));
|
||||||
|
@ -686,8 +686,8 @@ static ErrorOr<void> parse_meta_zones(DeprecatedString core_path, CLDR& cldr)
|
||||||
|
|
||||||
meta_zone_array.for_each([&](JsonValue const& value) {
|
meta_zone_array.for_each([&](JsonValue const& value) {
|
||||||
auto const& mapping = value.as_object().get_object("mapZone"sv).value();
|
auto const& mapping = value.as_object().get_object("mapZone"sv).value();
|
||||||
auto const& meta_zone = mapping.get_deprecated_string("_other"sv).value();
|
auto const& meta_zone = mapping.get_byte_string("_other"sv).value();
|
||||||
auto const& golden_zone = mapping.get_deprecated_string("_type"sv).value();
|
auto const& golden_zone = mapping.get_byte_string("_type"sv).value();
|
||||||
|
|
||||||
if (auto time_zone = TimeZone::time_zone_from_string(golden_zone); time_zone.has_value()) {
|
if (auto time_zone = TimeZone::time_zone_from_string(golden_zone); time_zone.has_value()) {
|
||||||
auto& golden_zones = cldr.meta_zones.ensure(meta_zone);
|
auto& golden_zones = cldr.meta_zones.ensure(meta_zone);
|
||||||
|
@ -770,7 +770,7 @@ static ErrorOr<String> remove_period_from_pattern(String pattern)
|
||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<Optional<CalendarPattern>> parse_date_time_pattern_raw(DeprecatedString pattern, DeprecatedString skeleton, CLDR& cldr)
|
static ErrorOr<Optional<CalendarPattern>> parse_date_time_pattern_raw(ByteString pattern, ByteString skeleton, CLDR& cldr)
|
||||||
{
|
{
|
||||||
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
// https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
|
||||||
using Locale::CalendarPatternStyle;
|
using Locale::CalendarPatternStyle;
|
||||||
|
@ -989,16 +989,16 @@ static ErrorOr<Optional<CalendarPattern>> parse_date_time_pattern_raw(Deprecated
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<Optional<size_t>> parse_date_time_pattern(DeprecatedString pattern, DeprecatedString skeleton, CLDR& cldr)
|
static ErrorOr<Optional<size_t>> parse_date_time_pattern(ByteString pattern, ByteString skeleton, CLDR& cldr)
|
||||||
{
|
{
|
||||||
auto format = TRY(parse_date_time_pattern_raw(move(pattern), move(skeleton), cldr));
|
auto format = TRY(parse_date_time_pattern_raw(move(pattern), move(skeleton), cldr));
|
||||||
if (!format.has_value())
|
if (!format.has_value())
|
||||||
return OptionalNone {};
|
return OptionalNone {};
|
||||||
|
|
||||||
format->pattern_index = cldr.unique_strings.ensure(format->pattern.to_deprecated_string());
|
format->pattern_index = cldr.unique_strings.ensure(format->pattern.to_byte_string());
|
||||||
|
|
||||||
if (format->pattern12.has_value())
|
if (format->pattern12.has_value())
|
||||||
format->pattern12_index = cldr.unique_strings.ensure(format->pattern12->to_deprecated_string());
|
format->pattern12_index = cldr.unique_strings.ensure(format->pattern12->to_byte_string());
|
||||||
|
|
||||||
return Optional<size_t> { cldr.unique_patterns.ensure(format.release_value()) };
|
return Optional<size_t> { cldr.unique_patterns.ensure(format.release_value()) };
|
||||||
}
|
}
|
||||||
|
@ -1388,7 +1388,7 @@ static void parse_calendar_symbols(Calendar& calendar, JsonObject const& calenda
|
||||||
calendar.symbols = cldr.unique_calendar_symbols_lists.ensure(move(symbols_list));
|
calendar.symbols = cldr.unique_calendar_symbols_lists.ensure(move(symbols_list));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_calendars(DeprecatedString locale_calendars_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_calendars(ByteString locale_calendars_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath calendars_path(move(locale_calendars_path));
|
LexicalPath calendars_path(move(locale_calendars_path));
|
||||||
if (!calendars_path.basename().starts_with("ca-"sv))
|
if (!calendars_path.basename().starts_with("ca-"sv))
|
||||||
|
@ -1402,10 +1402,10 @@ static ErrorOr<void> parse_calendars(DeprecatedString locale_calendars_path, CLD
|
||||||
|
|
||||||
auto parse_patterns = [&](auto const& patterns_object, auto const& skeletons_object, Vector<CalendarPattern>* patterns) -> ErrorOr<size_t> {
|
auto parse_patterns = [&](auto const& patterns_object, auto const& skeletons_object, Vector<CalendarPattern>* patterns) -> ErrorOr<size_t> {
|
||||||
auto parse_pattern = [&](auto name) -> ErrorOr<size_t> {
|
auto parse_pattern = [&](auto name) -> ErrorOr<size_t> {
|
||||||
auto format = patterns_object.get_deprecated_string(name);
|
auto format = patterns_object.get_byte_string(name);
|
||||||
auto skeleton = skeletons_object.get_deprecated_string(name);
|
auto skeleton = skeletons_object.get_byte_string(name);
|
||||||
|
|
||||||
auto format_index = TRY(parse_date_time_pattern(format.value(), skeleton.value_or(DeprecatedString::empty()), cldr)).value();
|
auto format_index = TRY(parse_date_time_pattern(format.value(), skeleton.value_or(ByteString::empty()), cldr)).value();
|
||||||
|
|
||||||
if (patterns)
|
if (patterns)
|
||||||
patterns->append(cldr.unique_patterns.get(format_index));
|
patterns->append(cldr.unique_patterns.get(format_index));
|
||||||
|
@ -1483,7 +1483,7 @@ static ErrorOr<void> parse_calendars(DeprecatedString locale_calendars_path, CLD
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_names_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_time_zone_names(ByteString locale_time_zone_names_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath time_zone_names_path(move(locale_time_zone_names_path));
|
LexicalPath time_zone_names_path(move(locale_time_zone_names_path));
|
||||||
time_zone_names_path = time_zone_names_path.append("timeZoneNames.json"sv);
|
time_zone_names_path = time_zone_names_path.append("timeZoneNames.json"sv);
|
||||||
|
@ -1494,9 +1494,9 @@ static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_nam
|
||||||
auto const& dates_object = locale_object.get_object("dates"sv).value();
|
auto const& dates_object = locale_object.get_object("dates"sv).value();
|
||||||
auto const& time_zone_names_object = dates_object.get_object("timeZoneNames"sv).value();
|
auto const& time_zone_names_object = dates_object.get_object("timeZoneNames"sv).value();
|
||||||
auto const& meta_zone_object = time_zone_names_object.get_object("metazone"sv);
|
auto const& meta_zone_object = time_zone_names_object.get_object("metazone"sv);
|
||||||
auto const& hour_format_string = time_zone_names_object.get_deprecated_string("hourFormat"sv).value();
|
auto const& hour_format_string = time_zone_names_object.get_byte_string("hourFormat"sv).value();
|
||||||
auto const& gmt_format_string = time_zone_names_object.get_deprecated_string("gmtFormat"sv).value();
|
auto const& gmt_format_string = time_zone_names_object.get_byte_string("gmtFormat"sv).value();
|
||||||
auto const& gmt_zero_format_string = time_zone_names_object.get_deprecated_string("gmtZeroFormat"sv).value();
|
auto const& gmt_zero_format_string = time_zone_names_object.get_byte_string("gmtZeroFormat"sv).value();
|
||||||
|
|
||||||
if (!meta_zone_object.has_value())
|
if (!meta_zone_object.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
@ -1506,7 +1506,7 @@ static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_nam
|
||||||
if (!names.has_value())
|
if (!names.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto const& name = names->get_deprecated_string(key);
|
auto const& name = names->get_byte_string(key);
|
||||||
if (name.has_value())
|
if (name.has_value())
|
||||||
return cldr.unique_strings.ensure(name.value());
|
return cldr.unique_strings.ensure(name.value());
|
||||||
|
|
||||||
|
@ -1592,7 +1592,7 @@ static ErrorOr<void> parse_time_zone_names(DeprecatedString locale_time_zone_nam
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_day_periods(DeprecatedString core_path, CLDR& cldr)
|
static ErrorOr<void> parse_day_periods(ByteString core_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
// https://unicode.org/reports/tr35/tr35-dates.html#Day_Period_Rule_Sets
|
// https://unicode.org/reports/tr35/tr35-dates.html#Day_Period_Rule_Sets
|
||||||
LexicalPath day_periods_path(move(core_path));
|
LexicalPath day_periods_path(move(core_path));
|
||||||
|
@ -1622,8 +1622,8 @@ static ErrorOr<void> parse_day_periods(DeprecatedString core_path, CLDR& cldr)
|
||||||
if (!day_period.has_value())
|
if (!day_period.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto begin = parse_hour(ranges.get_deprecated_string("_from"sv).value());
|
auto begin = parse_hour(ranges.get_byte_string("_from"sv).value());
|
||||||
auto end = parse_hour(ranges.get_deprecated_string("_before"sv).value());
|
auto end = parse_hour(ranges.get_byte_string("_before"sv).value());
|
||||||
|
|
||||||
return DayPeriod { *day_period, begin, end };
|
return DayPeriod { *day_period, begin, end };
|
||||||
};
|
};
|
||||||
|
@ -1648,13 +1648,13 @@ static ErrorOr<void> parse_day_periods(DeprecatedString core_path, CLDR& cldr)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString dates_path, CLDR& cldr)
|
static ErrorOr<void> parse_all_locales(ByteString core_path, ByteString dates_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
TRY(parse_hour_cycles(core_path, cldr));
|
TRY(parse_hour_cycles(core_path, cldr));
|
||||||
TRY(parse_week_data(core_path, cldr));
|
TRY(parse_week_data(core_path, cldr));
|
||||||
TRY(parse_meta_zones(core_path, cldr));
|
TRY(parse_meta_zones(core_path, cldr));
|
||||||
|
|
||||||
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
|
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
|
||||||
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -1664,7 +1664,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
|
||||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||||
builder.appendff("-{}", region);
|
builder.appendff("-{}", region);
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
||||||
|
@ -1687,15 +1687,15 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
|
static ByteString format_identifier(StringView owner, ByteString identifier)
|
||||||
{
|
{
|
||||||
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||||
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
|
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
|
||||||
|
|
||||||
if (all_of(identifier, is_ascii_digit))
|
if (all_of(identifier, is_ascii_digit))
|
||||||
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
|
return ByteString::formatted("{}_{}", owner[0], identifier);
|
||||||
if (is_ascii_lower_alpha(identifier[0]))
|
if (is_ascii_lower_alpha(identifier[0]))
|
||||||
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1953,9 +1953,9 @@ struct DayPeriodData {
|
||||||
cldr.unique_day_period_lists.generate(generator, cldr.unique_day_periods.type_that_fits(), "s_day_period_lists"sv);
|
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);
|
cldr.unique_hour_cycle_lists.generate(generator, cldr.unique_hour_cycle_lists.type_that_fits(), "s_hour_cycle_lists"sv);
|
||||||
|
|
||||||
auto append_calendars = [&](DeprecatedString name, auto const& calendars) {
|
auto append_calendars = [&](ByteString name, auto const& calendars) {
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(calendars.size()));
|
generator.set("size", ByteString::number(calendars.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
|
static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
|
||||||
|
@ -1965,7 +1965,7 @@ static constexpr Array<@calendar_index_type@, @size@> @name@ { {)~~~");
|
||||||
auto calendar = calendars.find(calendar_key)->value;
|
auto calendar = calendars.find(calendar_key)->value;
|
||||||
|
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::number(calendar));
|
generator.append(ByteString::number(calendar));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1975,7 +1975,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) {
|
auto append_mapping = [&](auto const& keys, auto const& map, auto type, auto name, auto mapping_getter) {
|
||||||
generator.set("type", type);
|
generator.set("type", type);
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(keys.size()));
|
generator.set("size", ByteString::number(keys.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||||
|
@ -1986,7 +1986,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||||
auto mapping = mapping_getter(value);
|
auto mapping = mapping_getter(value);
|
||||||
|
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::number(mapping));
|
generator.append(ByteString::number(mapping));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2008,7 +2008,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||||
generator.append("\n");
|
generator.append("\n");
|
||||||
|
|
||||||
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
|
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
|
||||||
HashValueMap<DeprecatedString> hashes;
|
HashValueMap<ByteString> hashes;
|
||||||
TRY(hashes.try_ensure_capacity(values.size()));
|
TRY(hashes.try_ensure_capacity(values.size()));
|
||||||
|
|
||||||
for (auto const& value : values)
|
for (auto const& value : values)
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
||||||
#include <AK/AllOf.h>
|
#include <AK/AllOf.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
@ -22,14 +22,14 @@
|
||||||
#include <LibCore/Directory.h>
|
#include <LibCore/Directory.h>
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
|
|
||||||
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
|
static ByteString format_identifier(StringView owner, ByteString identifier)
|
||||||
{
|
{
|
||||||
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||||
|
|
||||||
if (all_of(identifier, is_ascii_digit))
|
if (all_of(identifier, is_ascii_digit))
|
||||||
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
|
return ByteString::formatted("{}_{}", owner[0], identifier);
|
||||||
if (is_ascii_lower_alpha(identifier[0]))
|
if (is_ascii_lower_alpha(identifier[0]))
|
||||||
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,9 +153,9 @@ using KeywordList = Vector<size_t>;
|
||||||
using ListPatternList = Vector<size_t>;
|
using ListPatternList = Vector<size_t>;
|
||||||
|
|
||||||
struct LocaleData {
|
struct LocaleData {
|
||||||
DeprecatedString language;
|
ByteString language;
|
||||||
Optional<DeprecatedString> territory;
|
Optional<ByteString> territory;
|
||||||
Optional<DeprecatedString> variant;
|
Optional<ByteString> variant;
|
||||||
size_t display_patterns { 0 };
|
size_t display_patterns { 0 };
|
||||||
size_t languages { 0 };
|
size_t languages { 0 };
|
||||||
size_t territories { 0 };
|
size_t territories { 0 };
|
||||||
|
@ -195,25 +195,25 @@ struct CLDR {
|
||||||
UniqueStorage<ListPatternList> unique_list_pattern_lists;
|
UniqueStorage<ListPatternList> unique_list_pattern_lists;
|
||||||
UniqueStorage<TextLayout> unique_text_layouts;
|
UniqueStorage<TextLayout> unique_text_layouts;
|
||||||
|
|
||||||
HashMap<DeprecatedString, LocaleData> locales;
|
HashMap<ByteString, LocaleData> locales;
|
||||||
Vector<Alias> locale_aliases;
|
Vector<Alias> locale_aliases;
|
||||||
|
|
||||||
Vector<DeprecatedString> languages;
|
Vector<ByteString> languages;
|
||||||
HashMap<StringView, size_t> language_indices;
|
HashMap<StringView, size_t> language_indices;
|
||||||
|
|
||||||
Vector<DeprecatedString> territories;
|
Vector<ByteString> territories;
|
||||||
HashMap<StringView, size_t> territory_indices;
|
HashMap<StringView, size_t> territory_indices;
|
||||||
|
|
||||||
Vector<DeprecatedString> scripts;
|
Vector<ByteString> scripts;
|
||||||
HashMap<StringView, size_t> script_indices;
|
HashMap<StringView, size_t> script_indices;
|
||||||
|
|
||||||
Vector<DeprecatedString> variants;
|
Vector<ByteString> variants;
|
||||||
HashMap<StringView, size_t> variant_indices;
|
HashMap<StringView, size_t> variant_indices;
|
||||||
|
|
||||||
Vector<DeprecatedString> currencies;
|
Vector<ByteString> currencies;
|
||||||
HashMap<StringView, size_t> currency_indices;
|
HashMap<StringView, size_t> currency_indices;
|
||||||
|
|
||||||
Vector<DeprecatedString> date_fields;
|
Vector<ByteString> date_fields;
|
||||||
HashMap<StringView, size_t> date_fields_indices;
|
HashMap<StringView, size_t> date_fields_indices;
|
||||||
|
|
||||||
Vector<Alias> date_field_aliases {
|
Vector<Alias> date_field_aliases {
|
||||||
|
@ -224,17 +224,17 @@ struct CLDR {
|
||||||
{ "zone"sv, "timeZoneName"sv },
|
{ "zone"sv, "timeZoneName"sv },
|
||||||
};
|
};
|
||||||
|
|
||||||
HashMap<DeprecatedString, Vector<DeprecatedString>> keywords;
|
HashMap<ByteString, Vector<ByteString>> keywords;
|
||||||
HashMap<DeprecatedString, Vector<Alias>> keyword_aliases;
|
HashMap<ByteString, Vector<Alias>> keyword_aliases;
|
||||||
HashMap<DeprecatedString, DeprecatedString> keyword_names;
|
HashMap<ByteString, ByteString> keyword_names;
|
||||||
|
|
||||||
Vector<DeprecatedString> list_pattern_types;
|
Vector<ByteString> list_pattern_types;
|
||||||
Vector<DeprecatedString> character_orders;
|
Vector<ByteString> character_orders;
|
||||||
HashMap<DeprecatedString, size_t> language_aliases;
|
HashMap<ByteString, size_t> language_aliases;
|
||||||
HashMap<DeprecatedString, size_t> territory_aliases;
|
HashMap<ByteString, size_t> territory_aliases;
|
||||||
HashMap<DeprecatedString, size_t> script_aliases;
|
HashMap<ByteString, size_t> script_aliases;
|
||||||
HashMap<DeprecatedString, size_t> variant_aliases;
|
HashMap<ByteString, size_t> variant_aliases;
|
||||||
HashMap<DeprecatedString, size_t> subdivision_aliases;
|
HashMap<ByteString, size_t> subdivision_aliases;
|
||||||
Vector<LanguageMapping> complex_mappings;
|
Vector<LanguageMapping> complex_mappings;
|
||||||
Vector<LanguageMapping> likely_subtags;
|
Vector<LanguageMapping> likely_subtags;
|
||||||
size_t max_variant_size { 0 };
|
size_t max_variant_size { 0 };
|
||||||
|
@ -253,9 +253,9 @@ struct CLDR {
|
||||||
})
|
})
|
||||||
|
|
||||||
// NOTE: We return a pointer only because ErrorOr cannot store references. You may safely assume the pointer is non-null.
|
// NOTE: We return a pointer only because ErrorOr cannot store references. You may safely assume the pointer is non-null.
|
||||||
ErrorOr<JsonValue const*> read_json_file_with_cache(DeprecatedString const& path)
|
ErrorOr<JsonValue const*> read_json_file_with_cache(ByteString const& path)
|
||||||
{
|
{
|
||||||
static HashMap<DeprecatedString, JsonValue> parsed_json_cache;
|
static HashMap<ByteString, JsonValue> parsed_json_cache;
|
||||||
|
|
||||||
if (auto parsed_json = parsed_json_cache.get(path); parsed_json.has_value())
|
if (auto parsed_json = parsed_json_cache.get(path); parsed_json.has_value())
|
||||||
return &parsed_json.value();
|
return &parsed_json.value();
|
||||||
|
@ -273,7 +273,7 @@ static ErrorOr<LanguageMapping> parse_language_mapping(CLDR& cldr, StringView ke
|
||||||
return LanguageMapping { move(parsed_key), move(parsed_alias) };
|
return LanguageMapping { move(parsed_key), move(parsed_alias) };
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_core_aliases(DeprecatedString core_supplemental_path, CLDR& cldr)
|
static ErrorOr<void> parse_core_aliases(ByteString core_supplemental_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath core_aliases_path(move(core_supplemental_path));
|
LexicalPath core_aliases_path(move(core_supplemental_path));
|
||||||
core_aliases_path = core_aliases_path.append("aliases.json"sv);
|
core_aliases_path = core_aliases_path.append("aliases.json"sv);
|
||||||
|
@ -285,7 +285,7 @@ static ErrorOr<void> parse_core_aliases(DeprecatedString core_supplemental_path,
|
||||||
|
|
||||||
auto append_aliases = [&](auto& alias_object, auto& alias_map) {
|
auto append_aliases = [&](auto& alias_object, auto& alias_map) {
|
||||||
alias_object.for_each_member([&](auto const& key, JsonValue const& value) {
|
alias_object.for_each_member([&](auto const& key, JsonValue const& value) {
|
||||||
auto alias = value.as_object().get_deprecated_string("_replacement"sv).value();
|
auto alias = value.as_object().get_byte_string("_replacement"sv).value();
|
||||||
|
|
||||||
if (key.contains('-')) {
|
if (key.contains('-')) {
|
||||||
auto mapping = TRY_OR_DISCARD(parse_language_mapping(cldr, key, alias));
|
auto mapping = TRY_OR_DISCARD(parse_language_mapping(cldr, key, alias));
|
||||||
|
@ -307,7 +307,7 @@ static ErrorOr<void> parse_core_aliases(DeprecatedString core_supplemental_path,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_likely_subtags(DeprecatedString core_supplemental_path, CLDR& cldr)
|
static ErrorOr<void> parse_likely_subtags(ByteString core_supplemental_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath likely_subtags_path(move(core_supplemental_path));
|
LexicalPath likely_subtags_path(move(core_supplemental_path));
|
||||||
likely_subtags_path = likely_subtags_path.append("likelySubtags.json"sv);
|
likely_subtags_path = likely_subtags_path.append("likelySubtags.json"sv);
|
||||||
|
@ -326,7 +326,7 @@ static ErrorOr<void> parse_likely_subtags(DeprecatedString core_supplemental_pat
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_identity(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_identity(ByteString locale_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath locale_display_names_path(move(locale_path)); // Note: Every JSON file defines identity data, so we can use any of them.
|
LexicalPath locale_display_names_path(move(locale_path)); // Note: Every JSON file defines identity data, so we can use any of them.
|
||||||
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
|
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
|
||||||
|
@ -335,10 +335,10 @@ static ErrorOr<void> parse_identity(DeprecatedString locale_path, CLDR& cldr, Lo
|
||||||
auto const& main_object = locale_display_names.as_object().get_object("main"sv).value();
|
auto const& main_object = locale_display_names.as_object().get_object("main"sv).value();
|
||||||
auto const& locale_object = main_object.get_object(locale_display_names_path.parent().basename()).value();
|
auto const& locale_object = main_object.get_object(locale_display_names_path.parent().basename()).value();
|
||||||
auto const& identity_object = locale_object.get_object("identity"sv).value();
|
auto const& identity_object = locale_object.get_object("identity"sv).value();
|
||||||
auto const& language_string = identity_object.get_deprecated_string("language"sv).value();
|
auto const& language_string = identity_object.get_byte_string("language"sv).value();
|
||||||
auto const& territory_string = identity_object.get_deprecated_string("territory"sv);
|
auto const& territory_string = identity_object.get_byte_string("territory"sv);
|
||||||
auto const& script_string = identity_object.get_deprecated_string("script"sv);
|
auto const& script_string = identity_object.get_byte_string("script"sv);
|
||||||
auto const& variant_string = identity_object.get_deprecated_string("variant"sv);
|
auto const& variant_string = identity_object.get_byte_string("variant"sv);
|
||||||
|
|
||||||
locale.language = language_string;
|
locale.language = language_string;
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ static ErrorOr<void> parse_identity(DeprecatedString locale_path, CLDR& cldr, Lo
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_display_patterns(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_display_patterns(ByteString locale_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath locale_display_names_path(move(locale_path));
|
LexicalPath locale_display_names_path(move(locale_path));
|
||||||
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
|
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
|
||||||
|
@ -382,8 +382,8 @@ static ErrorOr<void> parse_locale_display_patterns(DeprecatedString locale_path,
|
||||||
auto const& locale_object = main_object.get_object(locale_display_names_path.parent().basename()).value();
|
auto const& locale_object = main_object.get_object(locale_display_names_path.parent().basename()).value();
|
||||||
auto const& locale_display_names_object = locale_object.get_object("localeDisplayNames"sv).value();
|
auto const& locale_display_names_object = locale_object.get_object("localeDisplayNames"sv).value();
|
||||||
auto const& locale_display_patterns_object = locale_display_names_object.get_object("localeDisplayPattern"sv).value();
|
auto const& locale_display_patterns_object = locale_display_names_object.get_object("localeDisplayPattern"sv).value();
|
||||||
auto const& locale_pattern = locale_display_patterns_object.get_deprecated_string("localePattern"sv).value();
|
auto const& locale_pattern = locale_display_patterns_object.get_byte_string("localePattern"sv).value();
|
||||||
auto const& locale_separator = locale_display_patterns_object.get_deprecated_string("localeSeparator"sv).value();
|
auto const& locale_separator = locale_display_patterns_object.get_byte_string("localeSeparator"sv).value();
|
||||||
|
|
||||||
DisplayPattern patterns {};
|
DisplayPattern patterns {};
|
||||||
patterns.locale_pattern = cldr.unique_strings.ensure(locale_pattern);
|
patterns.locale_pattern = cldr.unique_strings.ensure(locale_pattern);
|
||||||
|
@ -393,7 +393,7 @@ static ErrorOr<void> parse_locale_display_patterns(DeprecatedString locale_path,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> preprocess_languages(DeprecatedString locale_path, CLDR& cldr)
|
static ErrorOr<void> preprocess_languages(ByteString locale_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath languages_path(move(locale_path));
|
LexicalPath languages_path(move(locale_path));
|
||||||
languages_path = languages_path.append("languages.json"sv);
|
languages_path = languages_path.append("languages.json"sv);
|
||||||
|
@ -417,7 +417,7 @@ static ErrorOr<void> preprocess_languages(DeprecatedString locale_path, CLDR& cl
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> preprocess_currencies(DeprecatedString numbers_path, CLDR& cldr)
|
static ErrorOr<void> preprocess_currencies(ByteString numbers_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath currencies_path(move(numbers_path));
|
LexicalPath currencies_path(move(numbers_path));
|
||||||
currencies_path = currencies_path.append("currencies.json"sv);
|
currencies_path = currencies_path.append("currencies.json"sv);
|
||||||
|
@ -445,7 +445,7 @@ static bool is_sanctioned_date_field(StringView field)
|
||||||
return field.is_one_of("era"sv, "year"sv, "quarter"sv, "month"sv, "week"sv, "weekday"sv, "day"sv, "dayperiod"sv, "hour"sv, "minute"sv, "second"sv, "zone"sv);
|
return field.is_one_of("era"sv, "year"sv, "quarter"sv, "month"sv, "week"sv, "weekday"sv, "day"sv, "dayperiod"sv, "hour"sv, "minute"sv, "second"sv, "zone"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> preprocess_date_fields(DeprecatedString dates_path, CLDR& cldr)
|
static ErrorOr<void> preprocess_date_fields(ByteString dates_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath date_fields_path(move(dates_path));
|
LexicalPath date_fields_path(move(dates_path));
|
||||||
date_fields_path = date_fields_path.append("dateFields.json"sv);
|
date_fields_path = date_fields_path.append("dateFields.json"sv);
|
||||||
|
@ -469,7 +469,7 @@ static ErrorOr<void> preprocess_date_fields(DeprecatedString dates_path, CLDR& c
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_path, CLDR& cldr)
|
static ErrorOr<void> parse_unicode_extension_keywords(ByteString bcp47_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
constexpr auto desired_keywords = Array { "ca"sv, "co"sv, "hc"sv, "kf"sv, "kn"sv, "nu"sv };
|
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));
|
auto keywords = TRY(read_json_file(bcp47_path));
|
||||||
|
@ -483,7 +483,7 @@ static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_pat
|
||||||
if (!desired_keywords.span().contains_slow(key))
|
if (!desired_keywords.span().contains_slow(key))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto const& name = value.as_object().get_deprecated_string("_alias"sv).value();
|
auto const& name = value.as_object().get_byte_string("_alias"sv).value();
|
||||||
cldr.keyword_names.set(key, name);
|
cldr.keyword_names.set(key, name);
|
||||||
|
|
||||||
auto& keywords = cldr.keywords.ensure(key);
|
auto& keywords = cldr.keywords.ensure(key);
|
||||||
|
@ -505,12 +505,12 @@ static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_pat
|
||||||
if (key == "nu"sv && keyword.is_one_of("finance"sv, "native"sv, "traditio"sv))
|
if (key == "nu"sv && keyword.is_one_of("finance"sv, "native"sv, "traditio"sv))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (auto const& preferred = properties.as_object().get_deprecated_string("_preferred"sv); preferred.has_value()) {
|
if (auto const& preferred = properties.as_object().get_byte_string("_preferred"sv); preferred.has_value()) {
|
||||||
cldr.keyword_aliases.ensure(key).append({ preferred.value(), keyword });
|
cldr.keyword_aliases.ensure(key).append({ preferred.value(), keyword });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto const& alias = properties.as_object().get_deprecated_string("_alias"sv); alias.has_value())
|
if (auto const& alias = properties.as_object().get_byte_string("_alias"sv); alias.has_value())
|
||||||
cldr.keyword_aliases.ensure(key).append({ keyword, alias.value() });
|
cldr.keyword_aliases.ensure(key).append({ keyword, alias.value() });
|
||||||
|
|
||||||
keywords.append(keyword);
|
keywords.append(keyword);
|
||||||
|
@ -520,7 +520,7 @@ static ErrorOr<void> parse_unicode_extension_keywords(DeprecatedString bcp47_pat
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static Optional<DeprecatedString> find_keyword_alias(StringView key, StringView calendar, CLDR& cldr)
|
static Optional<ByteString> find_keyword_alias(StringView key, StringView calendar, CLDR& cldr)
|
||||||
{
|
{
|
||||||
auto it = cldr.keyword_aliases.find(key);
|
auto it = cldr.keyword_aliases.find(key);
|
||||||
if (it == cldr.keyword_aliases.end())
|
if (it == cldr.keyword_aliases.end())
|
||||||
|
@ -533,7 +533,7 @@ static Optional<DeprecatedString> find_keyword_alias(StringView key, StringView
|
||||||
return alias->name;
|
return alias->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_languages(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_languages(ByteString locale_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath languages_path(move(locale_path));
|
LexicalPath languages_path(move(locale_path));
|
||||||
languages_path = languages_path.append("languages.json"sv);
|
languages_path = languages_path.append("languages.json"sv);
|
||||||
|
@ -567,7 +567,7 @@ static ErrorOr<void> parse_locale_languages(DeprecatedString locale_path, CLDR&
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_territories(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_territories(ByteString locale_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath territories_path(move(locale_path));
|
LexicalPath territories_path(move(locale_path));
|
||||||
territories_path = territories_path.append("territories.json"sv);
|
territories_path = territories_path.append("territories.json"sv);
|
||||||
|
@ -598,7 +598,7 @@ static ErrorOr<void> parse_locale_territories(DeprecatedString locale_path, CLDR
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_scripts(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_scripts(ByteString locale_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath scripts_path(move(locale_path));
|
LexicalPath scripts_path(move(locale_path));
|
||||||
scripts_path = scripts_path.append("scripts.json"sv);
|
scripts_path = scripts_path.append("scripts.json"sv);
|
||||||
|
@ -629,7 +629,7 @@ static ErrorOr<void> parse_locale_scripts(DeprecatedString locale_path, CLDR& cl
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_list_patterns(DeprecatedString misc_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_list_patterns(ByteString misc_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath list_patterns_path(move(misc_path));
|
LexicalPath list_patterns_path(move(misc_path));
|
||||||
list_patterns_path = list_patterns_path.append("listPatterns.json"sv);
|
list_patterns_path = list_patterns_path.append("listPatterns.json"sv);
|
||||||
|
@ -664,10 +664,10 @@ static ErrorOr<void> parse_locale_list_patterns(DeprecatedString misc_path, CLDR
|
||||||
auto type = list_pattern_type(key);
|
auto type = list_pattern_type(key);
|
||||||
auto style = list_pattern_style(key);
|
auto style = list_pattern_style(key);
|
||||||
|
|
||||||
auto start = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("start"sv).value());
|
auto start = cldr.unique_strings.ensure(value.as_object().get_byte_string("start"sv).value());
|
||||||
auto middle = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("middle"sv).value());
|
auto middle = cldr.unique_strings.ensure(value.as_object().get_byte_string("middle"sv).value());
|
||||||
auto end = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("end"sv).value());
|
auto end = cldr.unique_strings.ensure(value.as_object().get_byte_string("end"sv).value());
|
||||||
auto pair = cldr.unique_strings.ensure(value.as_object().get_deprecated_string("2"sv).value());
|
auto pair = cldr.unique_strings.ensure(value.as_object().get_byte_string("2"sv).value());
|
||||||
|
|
||||||
if (!cldr.list_pattern_types.contains_slow(type))
|
if (!cldr.list_pattern_types.contains_slow(type))
|
||||||
cldr.list_pattern_types.append(type);
|
cldr.list_pattern_types.append(type);
|
||||||
|
@ -680,7 +680,7 @@ static ErrorOr<void> parse_locale_list_patterns(DeprecatedString misc_path, CLDR
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_layout(DeprecatedString misc_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_layout(ByteString misc_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath layout_path(move(misc_path));
|
LexicalPath layout_path(move(misc_path));
|
||||||
layout_path = layout_path.append("layout.json"sv);
|
layout_path = layout_path.append("layout.json"sv);
|
||||||
|
@ -699,7 +699,7 @@ static ErrorOr<void> parse_locale_layout(DeprecatedString misc_path, CLDR& cldr,
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
};
|
};
|
||||||
|
|
||||||
auto character_order = orientation_object.get_deprecated_string("characterOrder"sv).value();
|
auto character_order = orientation_object.get_byte_string("characterOrder"sv).value();
|
||||||
|
|
||||||
TextLayout layout {};
|
TextLayout layout {};
|
||||||
layout.character_order = text_layout_character_order(character_order);
|
layout.character_order = text_layout_character_order(character_order);
|
||||||
|
@ -711,7 +711,7 @@ static ErrorOr<void> parse_locale_layout(DeprecatedString misc_path, CLDR& cldr,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_currencies(DeprecatedString numbers_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_currencies(ByteString numbers_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath currencies_path(move(numbers_path));
|
LexicalPath currencies_path(move(numbers_path));
|
||||||
currencies_path = currencies_path.append("currencies.json"sv);
|
currencies_path = currencies_path.append("currencies.json"sv);
|
||||||
|
@ -735,10 +735,10 @@ static ErrorOr<void> parse_locale_currencies(DeprecatedString numbers_path, CLDR
|
||||||
numeric_currencies.resize(cldr.currencies.size());
|
numeric_currencies.resize(cldr.currencies.size());
|
||||||
|
|
||||||
currencies_object.for_each_member([&](auto const& key, JsonValue const& value) {
|
currencies_object.for_each_member([&](auto const& key, JsonValue const& value) {
|
||||||
auto long_name = value.as_object().get_deprecated_string("displayName"sv).value_or(key);
|
auto long_name = value.as_object().get_byte_string("displayName"sv).value_or(key);
|
||||||
auto short_name = value.as_object().get_deprecated_string("symbol"sv).value_or(key);
|
auto short_name = value.as_object().get_byte_string("symbol"sv).value_or(key);
|
||||||
auto narrow_name = value.as_object().get_deprecated_string("symbol-alt-narrow"sv);
|
auto narrow_name = value.as_object().get_byte_string("symbol-alt-narrow"sv);
|
||||||
auto numeric_name = value.as_object().get_deprecated_string("displayName-count-other"sv);
|
auto numeric_name = value.as_object().get_byte_string("displayName-count-other"sv);
|
||||||
|
|
||||||
auto index = cldr.currency_indices.get(key).value();
|
auto index = cldr.currency_indices.get(key).value();
|
||||||
long_currencies[index] = cldr.unique_strings.ensure(move(long_name));
|
long_currencies[index] = cldr.unique_strings.ensure(move(long_name));
|
||||||
|
@ -754,7 +754,7 @@ static ErrorOr<void> parse_locale_currencies(DeprecatedString numbers_path, CLDR
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_calendars(DeprecatedString locale_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_calendars(ByteString locale_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath locale_display_names_path(move(locale_path));
|
LexicalPath locale_display_names_path(move(locale_path));
|
||||||
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
|
locale_display_names_path = locale_display_names_path.append("localeDisplayNames.json"sv);
|
||||||
|
@ -789,7 +789,7 @@ static ErrorOr<void> parse_locale_calendars(DeprecatedString locale_path, CLDR&
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_locale_date_fields(DeprecatedString dates_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_locale_date_fields(ByteString dates_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath date_fields_path(move(dates_path));
|
LexicalPath date_fields_path(move(dates_path));
|
||||||
date_fields_path = date_fields_path.append("dateFields.json"sv);
|
date_fields_path = date_fields_path.append("dateFields.json"sv);
|
||||||
|
@ -813,9 +813,9 @@ static ErrorOr<void> parse_locale_date_fields(DeprecatedString dates_path, CLDR&
|
||||||
if (!is_sanctioned_date_field(key))
|
if (!is_sanctioned_date_field(key))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto const& long_name = value.as_object().get_deprecated_string("displayName"sv).value();
|
auto const& long_name = value.as_object().get_byte_string("displayName"sv).value();
|
||||||
auto const& short_name = fields_object.get_object(DeprecatedString::formatted("{}-short", key))->get_deprecated_string("displayName"sv).value();
|
auto const& short_name = fields_object.get_object(ByteString::formatted("{}-short", key))->get_byte_string("displayName"sv).value();
|
||||||
auto const& narrow_name = fields_object.get_object(DeprecatedString::formatted("{}-narrow", key))->get_deprecated_string("displayName"sv).value();
|
auto const& narrow_name = fields_object.get_object(ByteString::formatted("{}-narrow", key))->get_byte_string("displayName"sv).value();
|
||||||
|
|
||||||
auto index = cldr.date_fields_indices.get(key).value();
|
auto index = cldr.date_fields_indices.get(key).value();
|
||||||
long_date_fields[index] = cldr.unique_strings.ensure(long_name);
|
long_date_fields[index] = cldr.unique_strings.ensure(long_name);
|
||||||
|
@ -829,7 +829,7 @@ static ErrorOr<void> parse_locale_date_fields(DeprecatedString dates_path, CLDR&
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_numbers_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_number_system_keywords(ByteString locale_numbers_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath numbers_path(move(locale_numbers_path));
|
LexicalPath numbers_path(move(locale_numbers_path));
|
||||||
numbers_path = numbers_path.append("numbers.json"sv);
|
numbers_path = numbers_path.append("numbers.json"sv);
|
||||||
|
@ -838,12 +838,12 @@ static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_number
|
||||||
auto const& main_object = numbers.as_object().get_object("main"sv).value();
|
auto const& main_object = numbers.as_object().get_object("main"sv).value();
|
||||||
auto const& locale_object = main_object.get_object(numbers_path.parent().basename()).value();
|
auto const& locale_object = main_object.get_object(numbers_path.parent().basename()).value();
|
||||||
auto const& locale_numbers_object = locale_object.get_object("numbers"sv).value();
|
auto const& locale_numbers_object = locale_object.get_object("numbers"sv).value();
|
||||||
auto const& default_numbering_system_object = locale_numbers_object.get_deprecated_string("defaultNumberingSystem"sv).value();
|
auto const& default_numbering_system_object = locale_numbers_object.get_byte_string("defaultNumberingSystem"sv).value();
|
||||||
auto const& other_numbering_systems_object = locale_numbers_object.get_object("otherNumberingSystems"sv).value();
|
auto const& other_numbering_systems_object = locale_numbers_object.get_object("otherNumberingSystems"sv).value();
|
||||||
|
|
||||||
KeywordList keywords {};
|
KeywordList keywords {};
|
||||||
|
|
||||||
auto append_numbering_system = [&](DeprecatedString system_name) {
|
auto append_numbering_system = [&](ByteString system_name) {
|
||||||
if (auto system_alias = find_keyword_alias("nu"sv, system_name, cldr); system_alias.has_value())
|
if (auto system_alias = find_keyword_alias("nu"sv, system_name, cldr); system_alias.has_value())
|
||||||
system_name = system_alias.release_value();
|
system_name = system_alias.release_value();
|
||||||
|
|
||||||
|
@ -868,7 +868,7 @@ static ErrorOr<void> parse_number_system_keywords(DeprecatedString locale_number
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_calendar_keywords(DeprecatedString locale_dates_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_calendar_keywords(ByteString locale_dates_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
KeywordList keywords {};
|
KeywordList keywords {};
|
||||||
|
|
||||||
|
@ -934,7 +934,7 @@ static void fill_in_collation_keywords(CLDR& cldr, LocaleData& locale)
|
||||||
locale.collation_numeric_keywords = kn_index;
|
locale.collation_numeric_keywords = kn_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_default_content_locales(DeprecatedString core_path, CLDR& cldr)
|
static ErrorOr<void> parse_default_content_locales(ByteString core_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath default_content_path(move(core_path));
|
LexicalPath default_content_path(move(core_path));
|
||||||
default_content_path = default_content_path.append("defaultContent.json"sv);
|
default_content_path = default_content_path.append("defaultContent.json"sv);
|
||||||
|
@ -983,7 +983,7 @@ static ErrorOr<void> define_aliases_without_scripts(CLDR& cldr)
|
||||||
if ((parsed_locale.language == 0) || (parsed_locale.script == 0) || (parsed_locale.region == 0))
|
if ((parsed_locale.language == 0) || (parsed_locale.script == 0) || (parsed_locale.region == 0))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto locale_without_script = DeprecatedString::formatted("{}-{}",
|
auto locale_without_script = ByteString::formatted("{}-{}",
|
||||||
cldr.unique_strings.get(parsed_locale.language),
|
cldr.unique_strings.get(parsed_locale.language),
|
||||||
cldr.unique_strings.get(parsed_locale.region));
|
cldr.unique_strings.get(parsed_locale.region));
|
||||||
|
|
||||||
|
@ -1008,7 +1008,7 @@ static ErrorOr<void> define_aliases_without_scripts(CLDR& cldr)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
static ErrorOr<void> parse_all_locales(ByteString bcp47_path, ByteString core_path, ByteString locale_names_path, ByteString misc_path, ByteString numbers_path, ByteString dates_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath core_supplemental_path(core_path);
|
LexicalPath core_supplemental_path(core_path);
|
||||||
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
|
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
|
||||||
|
@ -1017,7 +1017,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedSt
|
||||||
TRY(parse_core_aliases(core_supplemental_path.string(), cldr));
|
TRY(parse_core_aliases(core_supplemental_path.string(), cldr));
|
||||||
TRY(parse_likely_subtags(core_supplemental_path.string(), cldr));
|
TRY(parse_likely_subtags(core_supplemental_path.string(), cldr));
|
||||||
|
|
||||||
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
|
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
|
||||||
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -1027,7 +1027,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString bcp47_path, DeprecatedSt
|
||||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||||
builder.appendff("-{}", region);
|
builder.appendff("-{}", region);
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
||||||
|
@ -1156,7 +1156,7 @@ namespace Locale {
|
||||||
|
|
||||||
for (auto& keyword : cldr.keywords) {
|
for (auto& keyword : cldr.keywords) {
|
||||||
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
|
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
|
||||||
auto enum_name = DeprecatedString::formatted("Keyword{}", format_identifier({}, keyword_name));
|
auto enum_name = ByteString::formatted("Keyword{}", format_identifier({}, keyword_name));
|
||||||
|
|
||||||
if (auto aliases = cldr.keyword_aliases.find(keyword.key); aliases != cldr.keyword_aliases.end())
|
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);
|
generate_enum(generator, format_identifier, enum_name, {}, keyword.value, aliases->value);
|
||||||
|
@ -1179,9 +1179,9 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::InputBufferedF
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
generator.set("string_index_type"sv, string_index_type);
|
generator.set("string_index_type"sv, string_index_type);
|
||||||
generator.set("locales_size"sv, DeprecatedString::number(cldr.locales.size()));
|
generator.set("locales_size"sv, ByteString::number(cldr.locales.size()));
|
||||||
generator.set("territories_size", DeprecatedString::number(cldr.territories.size()));
|
generator.set("territories_size", ByteString::number(cldr.territories.size()));
|
||||||
generator.set("variants_size", DeprecatedString::number(cldr.max_variant_size));
|
generator.set("variants_size", ByteString::number(cldr.max_variant_size));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
|
@ -1285,7 +1285,7 @@ ReadonlySpan<StringView> get_available_keyword_values(StringView key)
|
||||||
cldr.unique_text_layouts.generate(generator, "TextLayout"sv, "s_text_layouts"sv, 30);
|
cldr.unique_text_layouts.generate(generator, "TextLayout"sv, "s_text_layouts"sv, 30);
|
||||||
|
|
||||||
auto append_index = [&](auto index) {
|
auto append_index = [&](auto index) {
|
||||||
generator.append(DeprecatedString::formatted(", {}", index));
|
generator.append(ByteString::formatted(", {}", index));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto append_list_and_size = [&](auto const& list) {
|
auto append_list_and_size = [&](auto const& list) {
|
||||||
|
@ -1298,16 +1298,16 @@ ReadonlySpan<StringView> get_available_keyword_values(StringView key)
|
||||||
generator.append(", {");
|
generator.append(", {");
|
||||||
for (auto const& item : list) {
|
for (auto const& item : list) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::number(item));
|
generator.append(ByteString::number(item));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
generator.append(DeprecatedString::formatted(" }}, {}", list.size()));
|
generator.append(ByteString::formatted(" }}, {}", list.size()));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto append_mapping = [&](auto const& keys, auto const& map, auto type, auto name, auto mapping_getter) {
|
auto append_mapping = [&](auto const& keys, auto const& map, auto type, auto name, auto mapping_getter) {
|
||||||
generator.set("type", type);
|
generator.set("type", type);
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(keys.size()));
|
generator.set("size", ByteString::number(keys.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||||
|
@ -1318,7 +1318,7 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||||
auto mapping = mapping_getter(value);
|
auto mapping = mapping_getter(value);
|
||||||
|
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::number(mapping));
|
generator.append(ByteString::number(mapping));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1396,7 +1396,7 @@ struct LanguageMapping {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
auto append_complex_mapping = [&](StringView name, auto& mappings) {
|
auto append_complex_mapping = [&](StringView name, auto& mappings) {
|
||||||
generator.set("size", DeprecatedString::number(mappings.size()));
|
generator.set("size", ByteString::number(mappings.size()));
|
||||||
generator.set("name"sv, name);
|
generator.set("name"sv, name);
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
|
@ -1416,14 +1416,14 @@ static constexpr Array<LanguageMapping, @size@> s_@name@ { {
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto const& mapping : mappings) {
|
for (auto const& mapping : mappings) {
|
||||||
generator.set("language"sv, DeprecatedString::number(mapping.key.language));
|
generator.set("language"sv, ByteString::number(mapping.key.language));
|
||||||
generator.append(" { { @language@");
|
generator.append(" { { @language@");
|
||||||
|
|
||||||
append_index(mapping.key.script);
|
append_index(mapping.key.script);
|
||||||
append_index(mapping.key.region);
|
append_index(mapping.key.region);
|
||||||
append_list_and_size(mapping.key.variants);
|
append_list_and_size(mapping.key.variants);
|
||||||
|
|
||||||
generator.set("language"sv, DeprecatedString::number(mapping.alias.language));
|
generator.set("language"sv, ByteString::number(mapping.alias.language));
|
||||||
generator.append(" }, { @language@");
|
generator.append(" }, { @language@");
|
||||||
|
|
||||||
append_index(mapping.alias.script);
|
append_index(mapping.alias.script);
|
||||||
|
@ -1563,7 +1563,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 = {}) -> ErrorOr<void> {
|
auto append_from_string = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
|
||||||
HashValueMap<DeprecatedString> hashes;
|
HashValueMap<ByteString> hashes;
|
||||||
TRY(hashes.try_ensure_capacity(values.size()));
|
TRY(hashes.try_ensure_capacity(values.size()));
|
||||||
|
|
||||||
for (auto const& value : values)
|
for (auto const& value : values)
|
||||||
|
@ -1621,8 +1621,8 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
|
||||||
|
|
||||||
for (auto const& keyword : cldr.keywords) {
|
for (auto const& keyword : cldr.keywords) {
|
||||||
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
|
auto const& keyword_name = cldr.keyword_names.find(keyword.key)->value;
|
||||||
auto enum_name = DeprecatedString::formatted("Keyword{}", format_identifier({}, keyword_name));
|
auto enum_name = ByteString::formatted("Keyword{}", format_identifier({}, keyword_name));
|
||||||
auto enum_snake = DeprecatedString::formatted("keyword_{}", keyword.key);
|
auto enum_snake = ByteString::formatted("keyword_{}", keyword.key);
|
||||||
|
|
||||||
if (auto aliases = cldr.keyword_aliases.find(keyword.key); aliases != cldr.keyword_aliases.end())
|
if (auto aliases = cldr.keyword_aliases.find(keyword.key); aliases != cldr.keyword_aliases.end())
|
||||||
TRY(append_from_string(enum_name, enum_snake, keyword.value, aliases->value));
|
TRY(append_from_string(enum_name, enum_snake, keyword.value, aliases->value));
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
||||||
#include <AK/AllOf.h>
|
#include <AK/AllOf.h>
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Find.h>
|
#include <AK/Find.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/HashFunctions.h>
|
#include <AK/HashFunctions.h>
|
||||||
|
@ -85,7 +85,7 @@ struct AK::Formatter<NumberFormat> : Formatter<FormatString> {
|
||||||
format.zero_format_index,
|
format.zero_format_index,
|
||||||
format.positive_format_index,
|
format.positive_format_index,
|
||||||
format.negative_format_index,
|
format.negative_format_index,
|
||||||
identifier_indices.to_deprecated_string());
|
identifier_indices.to_byte_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ struct AK::Traits<Unit> : public DefaultTraits<Unit> {
|
||||||
|
|
||||||
struct LocaleData {
|
struct LocaleData {
|
||||||
Vector<size_t> number_systems;
|
Vector<size_t> number_systems;
|
||||||
HashMap<DeprecatedString, size_t> units {};
|
HashMap<ByteString, size_t> units {};
|
||||||
u8 minimum_grouping_digits { 0 };
|
u8 minimum_grouping_digits { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -227,14 +227,14 @@ struct CLDR {
|
||||||
UniqueStorage<NumberSystem> unique_systems;
|
UniqueStorage<NumberSystem> unique_systems;
|
||||||
UniqueStorage<Unit> unique_units;
|
UniqueStorage<Unit> unique_units;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Array<u32, 10>> number_system_digits;
|
HashMap<ByteString, Array<u32, 10>> number_system_digits;
|
||||||
Vector<DeprecatedString> number_systems;
|
Vector<ByteString> number_systems;
|
||||||
|
|
||||||
HashMap<DeprecatedString, LocaleData> locales;
|
HashMap<ByteString, LocaleData> locales;
|
||||||
size_t max_identifier_count { 0 };
|
size_t max_identifier_count { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
static ErrorOr<void> parse_number_system_digits(DeprecatedString core_supplemental_path, CLDR& cldr)
|
static ErrorOr<void> parse_number_system_digits(ByteString core_supplemental_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath number_systems_path(move(core_supplemental_path));
|
LexicalPath number_systems_path(move(core_supplemental_path));
|
||||||
number_systems_path = number_systems_path.append("numberingSystems.json"sv);
|
number_systems_path = number_systems_path.append("numberingSystems.json"sv);
|
||||||
|
@ -244,11 +244,11 @@ static ErrorOr<void> parse_number_system_digits(DeprecatedString core_supplement
|
||||||
auto const& number_systems_object = supplemental_object.get_object("numberingSystems"sv).value();
|
auto const& number_systems_object = supplemental_object.get_object("numberingSystems"sv).value();
|
||||||
|
|
||||||
number_systems_object.for_each_member([&](auto const& number_system, auto const& digits_object) {
|
number_systems_object.for_each_member([&](auto const& number_system, auto const& digits_object) {
|
||||||
auto type = digits_object.as_object().get_deprecated_string("_type"sv).value();
|
auto type = digits_object.as_object().get_byte_string("_type"sv).value();
|
||||||
if (type != "numeric"sv)
|
if (type != "numeric"sv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto digits = digits_object.as_object().get_deprecated_string("_digits"sv).value();
|
auto digits = digits_object.as_object().get_byte_string("_digits"sv).value();
|
||||||
|
|
||||||
Utf8View utf8_digits { digits };
|
Utf8View utf8_digits { digits };
|
||||||
VERIFY(utf8_digits.length() == 10);
|
VERIFY(utf8_digits.length() == 10);
|
||||||
|
@ -266,7 +266,7 @@ static ErrorOr<void> parse_number_system_digits(DeprecatedString core_supplement
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeprecatedString parse_identifiers(DeprecatedString pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
|
static ByteString parse_identifiers(ByteString pattern, StringView replacement, CLDR& cldr, NumberFormat& format)
|
||||||
{
|
{
|
||||||
static constexpr Utf8View whitespace { "\u0020\u00a0\u200f"sv };
|
static constexpr Utf8View whitespace { "\u0020\u00a0\u200f"sv };
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ static DeprecatedString parse_identifiers(DeprecatedString pattern, StringView r
|
||||||
cldr.max_identifier_count = max(cldr.max_identifier_count, format.identifier_indices.size());
|
cldr.max_identifier_count = max(cldr.max_identifier_count, format.identifier_indices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = DeprecatedString::formatted("{}{{{}:{}}}{}",
|
pattern = ByteString::formatted("{}{{{}:{}}}{}",
|
||||||
*start_index > 0 ? pattern.substring_view(0, *start_index) : ""sv,
|
*start_index > 0 ? pattern.substring_view(0, *start_index) : ""sv,
|
||||||
replacement,
|
replacement,
|
||||||
replacement_index,
|
replacement_index,
|
||||||
|
@ -320,13 +320,13 @@ static DeprecatedString parse_identifiers(DeprecatedString pattern, StringView r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr, NumberFormatType type, NumberFormat& format, NumberSystem* number_system_for_groupings = nullptr)
|
static void parse_number_pattern(Vector<ByteString> 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://unicode.org/reports/tr35/tr35-numbers.html#Number_Format_Patterns
|
||||||
// https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
|
// https://cldr.unicode.org/translation/number-currency-formats/number-and-currency-patterns
|
||||||
VERIFY((patterns.size() == 1) || (patterns.size() == 2));
|
VERIFY((patterns.size() == 1) || (patterns.size() == 2));
|
||||||
|
|
||||||
auto replace_patterns = [&](DeprecatedString pattern) {
|
auto replace_patterns = [&](ByteString pattern) {
|
||||||
static HashMap<StringView, StringView> replacements = {
|
static HashMap<StringView, StringView> replacements = {
|
||||||
{ "{0}"sv, "{number}"sv },
|
{ "{0}"sv, "{number}"sv },
|
||||||
{ "{1}"sv, "{currency}"sv },
|
{ "{1}"sv, "{currency}"sv },
|
||||||
|
@ -340,7 +340,7 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
|
||||||
for (auto const& replacement : replacements)
|
for (auto const& replacement : replacements)
|
||||||
pattern = pattern.replace(replacement.key, replacement.value, ReplaceMode::All);
|
pattern = pattern.replace(replacement.key, replacement.value, ReplaceMode::All);
|
||||||
|
|
||||||
if (auto start_number_index = pattern.find_any_of("#0"sv, DeprecatedString::SearchDirection::Forward); start_number_index.has_value()) {
|
if (auto start_number_index = pattern.find_any_of("#0"sv, ByteString::SearchDirection::Forward); start_number_index.has_value()) {
|
||||||
auto end_number_index = *start_number_index + 1;
|
auto end_number_index = *start_number_index + 1;
|
||||||
|
|
||||||
for (; end_number_index < pattern.length(); ++end_number_index) {
|
for (; end_number_index < pattern.length(); ++end_number_index) {
|
||||||
|
@ -367,7 +367,7 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = DeprecatedString::formatted("{}{{number}}{}",
|
pattern = ByteString::formatted("{}{{number}}{}",
|
||||||
*start_number_index > 0 ? pattern.substring_view(0, *start_number_index) : ""sv,
|
*start_number_index > 0 ? pattern.substring_view(0, *start_number_index) : ""sv,
|
||||||
pattern.substring_view(end_number_index));
|
pattern.substring_view(end_number_index));
|
||||||
|
|
||||||
|
@ -384,19 +384,19 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto zero_format = replace_patterns(move(patterns[0]));
|
auto zero_format = replace_patterns(move(patterns[0]));
|
||||||
format.positive_format_index = cldr.unique_strings.ensure(DeprecatedString::formatted("{{plusSign}}{}", zero_format));
|
format.positive_format_index = cldr.unique_strings.ensure(ByteString::formatted("{{plusSign}}{}", zero_format));
|
||||||
|
|
||||||
if (patterns.size() == 2) {
|
if (patterns.size() == 2) {
|
||||||
auto negative_format = replace_patterns(move(patterns[1]));
|
auto negative_format = replace_patterns(move(patterns[1]));
|
||||||
format.negative_format_index = cldr.unique_strings.ensure(move(negative_format));
|
format.negative_format_index = cldr.unique_strings.ensure(move(negative_format));
|
||||||
} else {
|
} else {
|
||||||
format.negative_format_index = cldr.unique_strings.ensure(DeprecatedString::formatted("{{minusSign}}{}", zero_format));
|
format.negative_format_index = cldr.unique_strings.ensure(ByteString::formatted("{{minusSign}}{}", zero_format));
|
||||||
}
|
}
|
||||||
|
|
||||||
format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
|
format.zero_format_index = cldr.unique_strings.ensure(move(zero_format));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr, NumberFormatType type, size_t& format_index, NumberSystem* number_system_for_groupings = nullptr)
|
static void parse_number_pattern(Vector<ByteString> patterns, CLDR& cldr, NumberFormatType type, size_t& format_index, NumberSystem* number_system_for_groupings = nullptr)
|
||||||
{
|
{
|
||||||
NumberFormat format {};
|
NumberFormat format {};
|
||||||
parse_number_pattern(move(patterns), cldr, type, format, number_system_for_groupings);
|
parse_number_pattern(move(patterns), cldr, type, format, number_system_for_groupings);
|
||||||
|
@ -404,7 +404,7 @@ static void parse_number_pattern(Vector<DeprecatedString> patterns, CLDR& cldr,
|
||||||
format_index = cldr.unique_formats.ensure(move(format));
|
format_index = cldr.unique_formats.ensure(move(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_number_systems(ByteString locale_numbers_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath numbers_path(move(locale_numbers_path));
|
LexicalPath numbers_path(move(locale_numbers_path));
|
||||||
numbers_path = numbers_path.append("numbers.json"sv);
|
numbers_path = numbers_path.append("numbers.json"sv);
|
||||||
|
@ -413,7 +413,7 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
|
||||||
auto const& main_object = numbers.as_object().get_object("main"sv).value();
|
auto const& main_object = numbers.as_object().get_object("main"sv).value();
|
||||||
auto const& locale_object = main_object.get_object(numbers_path.parent().basename()).value();
|
auto const& locale_object = main_object.get_object(numbers_path.parent().basename()).value();
|
||||||
auto const& locale_numbers_object = locale_object.get_object("numbers"sv).value();
|
auto const& locale_numbers_object = locale_object.get_object("numbers"sv).value();
|
||||||
auto const& minimum_grouping_digits = locale_numbers_object.get_deprecated_string("minimumGroupingDigits"sv).value();
|
auto const& minimum_grouping_digits = locale_numbers_object.get_byte_string("minimumGroupingDigits"sv).value();
|
||||||
|
|
||||||
Vector<Optional<NumberSystem>> number_systems;
|
Vector<Optional<NumberSystem>> number_systems;
|
||||||
number_systems.resize(cldr.number_systems.size());
|
number_systems.resize(cldr.number_systems.size());
|
||||||
|
@ -517,9 +517,9 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
|
||||||
|
|
||||||
// The range separator does not appear in the symbols list, we have to extract it from
|
// The range separator does not appear in the symbols list, we have to extract it from
|
||||||
// the range pattern.
|
// the range pattern.
|
||||||
auto misc_patterns_key = DeprecatedString::formatted("{}{}", misc_patterns_prefix, system);
|
auto misc_patterns_key = ByteString::formatted("{}{}", misc_patterns_prefix, system);
|
||||||
auto misc_patterns = locale_numbers_object.get_object(misc_patterns_key).value();
|
auto misc_patterns = locale_numbers_object.get_object(misc_patterns_key).value();
|
||||||
auto range_separator = misc_patterns.get_deprecated_string("range"sv).value();
|
auto range_separator = misc_patterns.get_byte_string("range"sv).value();
|
||||||
|
|
||||||
auto begin_index = range_separator.find("{0}"sv).value() + "{0}"sv.length();
|
auto begin_index = range_separator.find("{0}"sv).value() + "{0}"sv.length();
|
||||||
auto end_index = range_separator.find("{1}"sv).value();
|
auto end_index = range_separator.find("{1}"sv).value();
|
||||||
|
@ -536,7 +536,7 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
|
||||||
auto system = key.substring(decimal_formats_prefix.length());
|
auto system = key.substring(decimal_formats_prefix.length());
|
||||||
auto& number_system = ensure_number_system(system);
|
auto& number_system = ensure_number_system(system);
|
||||||
|
|
||||||
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
|
auto format_object = value.as_object().get_byte_string("standard"sv).value();
|
||||||
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.decimal_format, &number_system);
|
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.decimal_format, &number_system);
|
||||||
|
|
||||||
auto const& long_format = value.as_object().get_object("long"sv)->get_object("decimalFormat"sv).value();
|
auto const& long_format = value.as_object().get_object("long"sv)->get_object("decimalFormat"sv).value();
|
||||||
|
@ -548,10 +548,10 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
|
||||||
auto system = key.substring(currency_formats_prefix.length());
|
auto system = key.substring(currency_formats_prefix.length());
|
||||||
auto& number_system = ensure_number_system(system);
|
auto& number_system = ensure_number_system(system);
|
||||||
|
|
||||||
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
|
auto format_object = value.as_object().get_byte_string("standard"sv).value();
|
||||||
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.currency_format);
|
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.currency_format);
|
||||||
|
|
||||||
format_object = value.as_object().get_deprecated_string("accounting"sv).value();
|
format_object = value.as_object().get_byte_string("accounting"sv).value();
|
||||||
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.accounting_format);
|
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.accounting_format);
|
||||||
|
|
||||||
number_system.currency_unit_formats = parse_number_format(value.as_object());
|
number_system.currency_unit_formats = parse_number_format(value.as_object());
|
||||||
|
@ -559,13 +559,13 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
|
||||||
auto system = key.substring(percent_formats_prefix.length());
|
auto system = key.substring(percent_formats_prefix.length());
|
||||||
auto& number_system = ensure_number_system(system);
|
auto& number_system = ensure_number_system(system);
|
||||||
|
|
||||||
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
|
auto format_object = value.as_object().get_byte_string("standard"sv).value();
|
||||||
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.percent_format);
|
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.percent_format);
|
||||||
} else if (key.starts_with(scientific_formats_prefix)) {
|
} else if (key.starts_with(scientific_formats_prefix)) {
|
||||||
auto system = key.substring(scientific_formats_prefix.length());
|
auto system = key.substring(scientific_formats_prefix.length());
|
||||||
auto& number_system = ensure_number_system(system);
|
auto& number_system = ensure_number_system(system);
|
||||||
|
|
||||||
auto format_object = value.as_object().get_deprecated_string("standard"sv).value();
|
auto format_object = value.as_object().get_byte_string("standard"sv).value();
|
||||||
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.scientific_format);
|
parse_number_pattern(format_object.split(';'), cldr, NumberFormatType::Standard, number_system.scientific_format);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -584,7 +584,7 @@ static ErrorOr<void> parse_number_systems(DeprecatedString locale_numbers_path,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_units(ByteString locale_units_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath units_path(move(locale_units_path));
|
LexicalPath units_path(move(locale_units_path));
|
||||||
units_path = units_path.append("units.json"sv);
|
units_path = units_path.append("units.json"sv);
|
||||||
|
@ -597,7 +597,7 @@ static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr,
|
||||||
auto const& short_object = locale_units_object.get_object("short"sv).value();
|
auto const& short_object = locale_units_object.get_object("short"sv).value();
|
||||||
auto const& narrow_object = locale_units_object.get_object("narrow"sv).value();
|
auto const& narrow_object = locale_units_object.get_object("narrow"sv).value();
|
||||||
|
|
||||||
HashMap<DeprecatedString, Unit> units;
|
HashMap<ByteString, Unit> units;
|
||||||
|
|
||||||
auto ensure_unit = [&](auto const& unit) -> Unit& {
|
auto ensure_unit = [&](auto const& unit) -> Unit& {
|
||||||
return units.ensure(unit, [&]() {
|
return units.ensure(unit, [&]() {
|
||||||
|
@ -687,7 +687,7 @@ static ErrorOr<void> parse_units(DeprecatedString locale_units_path, CLDR& cldr,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString numbers_path, DeprecatedString units_path, CLDR& cldr)
|
static ErrorOr<void> parse_all_locales(ByteString core_path, ByteString numbers_path, ByteString units_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath core_supplemental_path(move(core_path));
|
LexicalPath core_supplemental_path(move(core_path));
|
||||||
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
|
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
|
||||||
|
@ -695,7 +695,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
|
||||||
|
|
||||||
TRY(parse_number_system_digits(core_supplemental_path.string(), cldr));
|
TRY(parse_number_system_digits(core_supplemental_path.string(), cldr));
|
||||||
|
|
||||||
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
|
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
|
||||||
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -705,7 +705,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
|
||||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||||
builder.appendff("-{}", region);
|
builder.appendff("-{}", region);
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", numbers_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", numbers_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
||||||
|
@ -729,7 +729,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeprecatedString format_identifier(StringView, DeprecatedString identifier)
|
static ByteString format_identifier(StringView, ByteString identifier)
|
||||||
{
|
{
|
||||||
return identifier.to_titlecase();
|
return identifier.to_titlecase();
|
||||||
}
|
}
|
||||||
|
@ -765,7 +765,7 @@ static ErrorOr<void> generate_unicode_locale_implementation(Core::InputBufferedF
|
||||||
generator.set("number_format_index_type"sv, cldr.unique_formats.type_that_fits());
|
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("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("numeric_symbol_list_index_type"sv, cldr.unique_symbols.type_that_fits());
|
||||||
generator.set("identifier_count", DeprecatedString::number(cldr.max_identifier_count));
|
generator.set("identifier_count", ByteString::number(cldr.max_identifier_count));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
|
@ -848,22 +848,22 @@ struct Unit {
|
||||||
auto locales = cldr.locales.keys();
|
auto locales = cldr.locales.keys();
|
||||||
quick_sort(locales);
|
quick_sort(locales);
|
||||||
|
|
||||||
generator.set("size", DeprecatedString::number(locales.size()));
|
generator.set("size", ByteString::number(locales.size()));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<u8, @size@> s_minimum_grouping_digits { { )~~~");
|
static constexpr Array<u8, @size@> s_minimum_grouping_digits { { )~~~");
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto const& locale : locales) {
|
for (auto const& locale : locales) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
|
generator.append(ByteString::number(cldr.locales.find(locale)->value.minimum_grouping_digits));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
generator.append(" } };\n");
|
generator.append(" } };\n");
|
||||||
|
|
||||||
auto append_map = [&](DeprecatedString name, auto type, auto const& map) {
|
auto append_map = [&](ByteString name, auto type, auto const& map) {
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("type", type);
|
generator.set("type", type);
|
||||||
generator.set("size", DeprecatedString::number(map.size()));
|
generator.set("size", ByteString::number(map.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||||
|
@ -872,9 +872,9 @@ static constexpr Array<@type@, @size@> @name@ { {)~~~");
|
||||||
for (auto const& item : map) {
|
for (auto const& item : map) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
if constexpr (requires { item.value; })
|
if constexpr (requires { item.value; })
|
||||||
generator.append(DeprecatedString::number(item.value));
|
generator.append(ByteString::number(item.value));
|
||||||
else
|
else
|
||||||
generator.append(DeprecatedString::number(item));
|
generator.append(ByteString::number(item));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonParser.h>
|
#include <AK/JsonParser.h>
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
|
@ -18,14 +18,14 @@
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <LibLocale/PluralRules.h>
|
#include <LibLocale/PluralRules.h>
|
||||||
|
|
||||||
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
|
static ByteString format_identifier(StringView owner, ByteString identifier)
|
||||||
{
|
{
|
||||||
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
identifier = identifier.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||||
|
|
||||||
if (all_of(identifier, is_ascii_digit))
|
if (all_of(identifier, is_ascii_digit))
|
||||||
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
|
return ByteString::formatted("{}_{}", owner[0], identifier);
|
||||||
if (is_ascii_lower_alpha(identifier[0]))
|
if (is_ascii_lower_alpha(identifier[0]))
|
||||||
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,20 +38,20 @@ struct Relation {
|
||||||
Inequality,
|
Inequality,
|
||||||
};
|
};
|
||||||
|
|
||||||
DeprecatedString const& modulus_variable_name() const
|
ByteString const& modulus_variable_name() const
|
||||||
{
|
{
|
||||||
VERIFY(modulus.has_value());
|
VERIFY(modulus.has_value());
|
||||||
|
|
||||||
if (!cached_modulus_variable_name.has_value())
|
if (!cached_modulus_variable_name.has_value())
|
||||||
cached_modulus_variable_name = DeprecatedString::formatted("mod_{}_{}", symbol, *modulus);
|
cached_modulus_variable_name = ByteString::formatted("mod_{}_{}", symbol, *modulus);
|
||||||
|
|
||||||
return *cached_modulus_variable_name;
|
return *cached_modulus_variable_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString const& exponential_variable_name() const
|
ByteString const& exponential_variable_name() const
|
||||||
{
|
{
|
||||||
if (!cached_exponential_variable_name.has_value())
|
if (!cached_exponential_variable_name.has_value())
|
||||||
cached_exponential_variable_name = DeprecatedString::formatted("exp_{}", symbol);
|
cached_exponential_variable_name = ByteString::formatted("exp_{}", symbol);
|
||||||
|
|
||||||
return *cached_exponential_variable_name;
|
return *cached_exponential_variable_name;
|
||||||
}
|
}
|
||||||
|
@ -64,25 +64,25 @@ struct Relation {
|
||||||
else if (symbol == 'e' || symbol == 'c')
|
else if (symbol == 'e' || symbol == 'c')
|
||||||
generator.append(exponential_variable_name());
|
generator.append(exponential_variable_name());
|
||||||
else
|
else
|
||||||
generator.append(DeprecatedString::formatted("ops.{}", Locale::PluralOperands::symbol_to_variable_name(symbol)));
|
generator.append(ByteString::formatted("ops.{}", Locale::PluralOperands::symbol_to_variable_name(symbol)));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto append_value = [&](u32 value) {
|
auto append_value = [&](u32 value) {
|
||||||
append_variable_name();
|
append_variable_name();
|
||||||
generator.append(" == "sv);
|
generator.append(" == "sv);
|
||||||
generator.append(DeprecatedString::number(value));
|
generator.append(ByteString::number(value));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto append_range = [&](auto const& range) {
|
auto append_range = [&](auto const& range) {
|
||||||
// This check avoids generating "0 <= unsigned_value", which is always true.
|
// This check avoids generating "0 <= unsigned_value", which is always true.
|
||||||
if (range[0] != 0 || Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
|
if (range[0] != 0 || Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
|
||||||
generator.append(DeprecatedString::formatted("{} <= ", range[0]));
|
generator.append(ByteString::formatted("{} <= ", range[0]));
|
||||||
append_variable_name();
|
append_variable_name();
|
||||||
generator.append(" && "sv);
|
generator.append(" && "sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
append_variable_name();
|
append_variable_name();
|
||||||
generator.append(DeprecatedString::formatted(" <= {}", range[1]));
|
generator.append(ByteString::formatted(" <= {}", range[1]));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (type == Type::Inequality)
|
if (type == Type::Inequality)
|
||||||
|
@ -105,7 +105,7 @@ struct Relation {
|
||||||
generator.append(")"sv);
|
generator.append(")"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_precomputed_variables(SourceGenerator& generator, HashTable<DeprecatedString>& generated_variables) const
|
void generate_precomputed_variables(SourceGenerator& generator, HashTable<ByteString>& generated_variables) const
|
||||||
{
|
{
|
||||||
// FIXME: How do we handle the exponential symbols? They seem unused by ECMA-402.
|
// FIXME: How do we handle the exponential symbols? They seem unused by ECMA-402.
|
||||||
if (symbol == 'e' || symbol == 'c') {
|
if (symbol == 'e' || symbol == 'c') {
|
||||||
|
@ -127,7 +127,7 @@ struct Relation {
|
||||||
generated_variables.set(variable);
|
generated_variables.set(variable);
|
||||||
generator.set("variable"sv, move(variable));
|
generator.set("variable"sv, move(variable));
|
||||||
generator.set("operand"sv, Locale::PluralOperands::symbol_to_variable_name(symbol));
|
generator.set("operand"sv, Locale::PluralOperands::symbol_to_variable_name(symbol));
|
||||||
generator.set("modulus"sv, DeprecatedString::number(*modulus));
|
generator.set("modulus"sv, ByteString::number(*modulus));
|
||||||
|
|
||||||
if (Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
|
if (Locale::PluralOperands::symbol_requires_floating_point_modulus(symbol)) {
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
|
@ -144,8 +144,8 @@ struct Relation {
|
||||||
Vector<Comparator> comparators;
|
Vector<Comparator> comparators;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable Optional<DeprecatedString> cached_modulus_variable_name;
|
mutable Optional<ByteString> cached_modulus_variable_name;
|
||||||
mutable Optional<DeprecatedString> cached_exponential_variable_name;
|
mutable Optional<ByteString> cached_exponential_variable_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Condition {
|
struct Condition {
|
||||||
|
@ -170,7 +170,7 @@ struct Condition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_precomputed_variables(SourceGenerator& generator, HashTable<DeprecatedString>& generated_variables) const
|
void generate_precomputed_variables(SourceGenerator& generator, HashTable<ByteString>& generated_variables) const
|
||||||
{
|
{
|
||||||
for (auto const& conjunctions : relations) {
|
for (auto const& conjunctions : relations) {
|
||||||
for (auto const& relation : conjunctions)
|
for (auto const& relation : conjunctions)
|
||||||
|
@ -182,18 +182,18 @@ struct Condition {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Range {
|
struct Range {
|
||||||
DeprecatedString start;
|
ByteString start;
|
||||||
DeprecatedString end;
|
ByteString end;
|
||||||
DeprecatedString category;
|
ByteString category;
|
||||||
};
|
};
|
||||||
|
|
||||||
using Conditions = HashMap<DeprecatedString, Condition>;
|
using Conditions = HashMap<ByteString, Condition>;
|
||||||
using Ranges = Vector<Range>;
|
using Ranges = Vector<Range>;
|
||||||
|
|
||||||
struct LocaleData {
|
struct LocaleData {
|
||||||
static DeprecatedString generated_method_name(StringView form, StringView locale)
|
static ByteString generated_method_name(StringView form, StringView locale)
|
||||||
{
|
{
|
||||||
return DeprecatedString::formatted("{}_plurality_{}", form, format_identifier({}, locale));
|
return ByteString::formatted("{}_plurality_{}", form, format_identifier({}, locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
Conditions& rules_for_form(StringView form)
|
Conditions& rules_for_form(StringView form)
|
||||||
|
@ -213,7 +213,7 @@ struct LocaleData {
|
||||||
struct CLDR {
|
struct CLDR {
|
||||||
UniqueStringStorage unique_strings;
|
UniqueStringStorage unique_strings;
|
||||||
|
|
||||||
HashMap<DeprecatedString, LocaleData> locales;
|
HashMap<ByteString, LocaleData> locales;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Relation parse_relation(StringView relation)
|
static Relation parse_relation(StringView relation)
|
||||||
|
@ -321,7 +321,7 @@ static void parse_condition(StringView category, StringView rule, Conditions& ru
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_plural_rules(DeprecatedString core_supplemental_path, StringView file_name, CLDR& cldr)
|
static ErrorOr<void> parse_plural_rules(ByteString core_supplemental_path, StringView file_name, CLDR& cldr)
|
||||||
{
|
{
|
||||||
static constexpr auto form_prefix = "plurals-type-"sv;
|
static constexpr auto form_prefix = "plurals-type-"sv;
|
||||||
static constexpr auto rule_prefix = "pluralRule-count-"sv;
|
static constexpr auto rule_prefix = "pluralRule-count-"sv;
|
||||||
|
@ -356,7 +356,7 @@ static ErrorOr<void> parse_plural_rules(DeprecatedString core_supplemental_path,
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges
|
// https://unicode.org/reports/tr35/tr35-numbers.html#Plural_Ranges
|
||||||
static ErrorOr<void> parse_plural_ranges(DeprecatedString core_supplemental_path, CLDR& cldr)
|
static ErrorOr<void> parse_plural_ranges(ByteString core_supplemental_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
static constexpr auto start_segment = "-start-"sv;
|
static constexpr auto start_segment = "-start-"sv;
|
||||||
static constexpr auto end_segment = "-end-"sv;
|
static constexpr auto end_segment = "-end-"sv;
|
||||||
|
@ -392,13 +392,13 @@ static ErrorOr<void> parse_plural_ranges(DeprecatedString core_supplemental_path
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedString locale_names_path, CLDR& cldr)
|
static ErrorOr<void> parse_all_locales(ByteString core_path, ByteString locale_names_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
LexicalPath core_supplemental_path(move(core_path));
|
LexicalPath core_supplemental_path(move(core_path));
|
||||||
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
|
core_supplemental_path = core_supplemental_path.append("supplemental"sv);
|
||||||
VERIFY(FileSystem::is_directory(core_supplemental_path.string()));
|
VERIFY(FileSystem::is_directory(core_supplemental_path.string()));
|
||||||
|
|
||||||
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
|
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
|
||||||
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -408,7 +408,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString core_path, DeprecatedStr
|
||||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||||
builder.appendff("-{}", region);
|
builder.appendff("-{}", region);
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", locale_names_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
||||||
|
@ -484,7 +484,7 @@ static PluralCategory default_range(PluralCategory, PluralCategory end)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
generator.set("method"sv, LocaleData::generated_method_name(form, locale));
|
generator.set("method"sv, LocaleData::generated_method_name(form, locale));
|
||||||
HashTable<DeprecatedString> generated_variables;
|
HashTable<ByteString> generated_variables;
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static PluralCategory @method@([[maybe_unused]] PluralOperands ops)
|
static PluralCategory @method@([[maybe_unused]] PluralOperands ops)
|
||||||
|
@ -539,7 +539,7 @@ static PluralCategory @method@(PluralCategory start, PluralCategory end)
|
||||||
generator.set("type"sv, type);
|
generator.set("type"sv, type);
|
||||||
generator.set("form"sv, form);
|
generator.set("form"sv, form);
|
||||||
generator.set("default"sv, default_);
|
generator.set("default"sv, default_);
|
||||||
generator.set("size"sv, DeprecatedString::number(locales.size()));
|
generator.set("size"sv, ByteString::number(locales.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
|
static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
|
||||||
|
@ -564,7 +564,7 @@ static constexpr Array<@type@, @size@> s_@form@_functions { {)~~~");
|
||||||
|
|
||||||
auto append_categories = [&](auto const& name, auto const& rules) {
|
auto append_categories = [&](auto const& name, auto const& rules) {
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(rules.size() + 1));
|
generator.set("size", ByteString::number(rules.size() + 1));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<PluralCategory, @size@> @name@ { { PluralCategory::Other)~~~");
|
static constexpr Array<PluralCategory, @size@> @name@ { { PluralCategory::Other)~~~");
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
|
@ -39,9 +39,9 @@ struct RelativeTimeFormat {
|
||||||
&& (pattern == other.pattern);
|
&& (pattern == other.pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString time_unit;
|
ByteString time_unit;
|
||||||
DeprecatedString style;
|
ByteString style;
|
||||||
DeprecatedString plurality;
|
ByteString plurality;
|
||||||
size_t tense_or_number { 0 };
|
size_t tense_or_number { 0 };
|
||||||
size_t pattern { 0 };
|
size_t pattern { 0 };
|
||||||
};
|
};
|
||||||
|
@ -73,10 +73,10 @@ struct CLDR {
|
||||||
UniqueStringStorage unique_strings;
|
UniqueStringStorage unique_strings;
|
||||||
UniqueStorage<RelativeTimeFormat> unique_formats;
|
UniqueStorage<RelativeTimeFormat> unique_formats;
|
||||||
|
|
||||||
HashMap<DeprecatedString, LocaleData> locales;
|
HashMap<ByteString, LocaleData> locales;
|
||||||
};
|
};
|
||||||
|
|
||||||
static ErrorOr<void> parse_date_fields(DeprecatedString locale_dates_path, CLDR& cldr, LocaleData& locale)
|
static ErrorOr<void> parse_date_fields(ByteString locale_dates_path, CLDR& cldr, LocaleData& locale)
|
||||||
{
|
{
|
||||||
LexicalPath date_fields_path(move(locale_dates_path));
|
LexicalPath date_fields_path(move(locale_dates_path));
|
||||||
date_fields_path = date_fields_path.append("dateFields.json"sv);
|
date_fields_path = date_fields_path.append("dateFields.json"sv);
|
||||||
|
@ -135,9 +135,9 @@ static ErrorOr<void> parse_date_fields(DeprecatedString locale_dates_path, CLDR&
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_all_locales(DeprecatedString dates_path, CLDR& cldr)
|
static ErrorOr<void> parse_all_locales(ByteString dates_path, CLDR& cldr)
|
||||||
{
|
{
|
||||||
auto remove_variants_from_path = [&](DeprecatedString path) -> ErrorOr<DeprecatedString> {
|
auto remove_variants_from_path = [&](ByteString path) -> ErrorOr<ByteString> {
|
||||||
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
auto parsed_locale = TRY(CanonicalLanguageID::parse(cldr.unique_strings, LexicalPath::basename(path)));
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
@ -147,7 +147,7 @@ static ErrorOr<void> parse_all_locales(DeprecatedString dates_path, CLDR& cldr)
|
||||||
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
if (auto region = cldr.unique_strings.get(parsed_locale.region); !region.is_empty())
|
||||||
builder.appendff("-{}", region);
|
builder.appendff("-{}", region);
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
};
|
};
|
||||||
|
|
||||||
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
TRY(Core::Directory::for_each_entry(TRY(String::formatted("{}/main", dates_path)), Core::DirIterator::SkipParentAndBaseDir, [&](auto& entry, auto& directory) -> ErrorOr<IterationDecision> {
|
||||||
|
@ -225,9 +225,9 @@ struct RelativeTimeFormatImpl {
|
||||||
|
|
||||||
cldr.unique_formats.generate(generator, "RelativeTimeFormatImpl"sv, "s_relative_time_formats"sv, 10);
|
cldr.unique_formats.generate(generator, "RelativeTimeFormatImpl"sv, "s_relative_time_formats"sv, 10);
|
||||||
|
|
||||||
auto append_list = [&](DeprecatedString name, auto const& list) {
|
auto append_list = [&](ByteString name, auto const& list) {
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(list.size()));
|
generator.set("size", ByteString::number(list.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~");
|
static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~");
|
||||||
|
@ -235,7 +235,7 @@ static constexpr Array<@relative_time_format_index_type@, @size@> @name@ { {)~~~
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto index : list) {
|
for (auto index : list) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::number(index));
|
generator.append(ByteString::number(index));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
#include "../LibUnicode/GeneratorUtil.h" // FIXME: Move this somewhere common.
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/DateConstants.h>
|
#include <AK/DateConstants.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
@ -36,7 +36,7 @@ struct TimeZoneOffset {
|
||||||
i64 offset { 0 };
|
i64 offset { 0 };
|
||||||
Optional<DateTime> until;
|
Optional<DateTime> until;
|
||||||
|
|
||||||
Optional<DeprecatedString> dst_rule;
|
Optional<ByteString> dst_rule;
|
||||||
Optional<i32> dst_rule_index;
|
Optional<i32> dst_rule_index;
|
||||||
i64 dst_offset { 0 };
|
i64 dst_offset { 0 };
|
||||||
|
|
||||||
|
@ -56,17 +56,17 @@ struct DaylightSavingsOffset {
|
||||||
struct TimeZoneData {
|
struct TimeZoneData {
|
||||||
UniqueStringStorage unique_strings;
|
UniqueStringStorage unique_strings;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Vector<TimeZoneOffset>> time_zones;
|
HashMap<ByteString, Vector<TimeZoneOffset>> time_zones;
|
||||||
Vector<DeprecatedString> time_zone_names;
|
Vector<ByteString> time_zone_names;
|
||||||
Vector<Alias> time_zone_aliases;
|
Vector<Alias> time_zone_aliases;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Vector<DaylightSavingsOffset>> dst_offsets;
|
HashMap<ByteString, Vector<DaylightSavingsOffset>> dst_offsets;
|
||||||
Vector<DeprecatedString> dst_offset_names;
|
Vector<ByteString> dst_offset_names;
|
||||||
|
|
||||||
HashMap<DeprecatedString, TimeZone::Location> time_zone_coordinates;
|
HashMap<ByteString, TimeZone::Location> time_zone_coordinates;
|
||||||
|
|
||||||
HashMap<DeprecatedString, Vector<size_t>> time_zone_regions;
|
HashMap<ByteString, Vector<size_t>> time_zone_regions;
|
||||||
Vector<DeprecatedString> time_zone_region_names;
|
Vector<ByteString> time_zone_region_names;
|
||||||
|
|
||||||
Vector<TimeZone::TimeZoneIdentifier> time_zones_and_links;
|
Vector<TimeZone::TimeZoneIdentifier> time_zones_and_links;
|
||||||
};
|
};
|
||||||
|
@ -112,10 +112,10 @@ struct AK::Formatter<DaylightSavingsOffset> : Formatter<FormatString> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, DaylightSavingsOffset const& dst_offset)
|
ErrorOr<void> format(FormatBuilder& builder, DaylightSavingsOffset const& dst_offset)
|
||||||
{
|
{
|
||||||
auto format_time = [&](auto year) {
|
auto format_time = [&](auto year) {
|
||||||
return DeprecatedString::formatted("AK::UnixDateTime::from_unix_time_parts({}, 1, 1, 0, 0, 0, 0)", year);
|
return ByteString::formatted("AK::UnixDateTime::from_unix_time_parts({}, 1, 1, 0, 0, 0, 0)", year);
|
||||||
};
|
};
|
||||||
|
|
||||||
static DeprecatedString max_year_as_time("max_year_as_time"sv);
|
static ByteString max_year_as_time("max_year_as_time"sv);
|
||||||
|
|
||||||
return Formatter<FormatString>::format(builder,
|
return Formatter<FormatString>::format(builder,
|
||||||
"{{ {}, {}, {}, {}, {} }}"sv,
|
"{{ {}, {}, {}, {}, {} }}"sv,
|
||||||
|
@ -439,7 +439,7 @@ static void set_dst_rule_indices(TimeZoneData& time_zone_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeprecatedString format_identifier(StringView owner, DeprecatedString identifier)
|
static ByteString format_identifier(StringView owner, ByteString identifier)
|
||||||
{
|
{
|
||||||
constexpr auto gmt_time_zones = Array { "Etc/GMT"sv, "GMT"sv };
|
constexpr auto gmt_time_zones = Array { "Etc/GMT"sv, "GMT"sv };
|
||||||
|
|
||||||
|
@ -448,9 +448,9 @@ static DeprecatedString format_identifier(StringView owner, DeprecatedString ide
|
||||||
auto offset = identifier.substring_view(gmt_time_zone.length());
|
auto offset = identifier.substring_view(gmt_time_zone.length());
|
||||||
|
|
||||||
if (offset.starts_with('+'))
|
if (offset.starts_with('+'))
|
||||||
identifier = DeprecatedString::formatted("{}_Ahead_{}", gmt_time_zone, offset.substring_view(1));
|
identifier = ByteString::formatted("{}_Ahead_{}", gmt_time_zone, offset.substring_view(1));
|
||||||
else if (offset.starts_with('-'))
|
else if (offset.starts_with('-'))
|
||||||
identifier = DeprecatedString::formatted("{}_Behind_{}", gmt_time_zone, offset.substring_view(1));
|
identifier = ByteString::formatted("{}_Behind_{}", gmt_time_zone, offset.substring_view(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,9 +458,9 @@ static DeprecatedString format_identifier(StringView owner, DeprecatedString ide
|
||||||
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
|
identifier = identifier.replace("/"sv, "_"sv, ReplaceMode::All);
|
||||||
|
|
||||||
if (all_of(identifier, is_ascii_digit))
|
if (all_of(identifier, is_ascii_digit))
|
||||||
return DeprecatedString::formatted("{}_{}", owner[0], identifier);
|
return ByteString::formatted("{}_{}", owner[0], identifier);
|
||||||
if (is_ascii_lower_alpha(identifier[0]))
|
if (is_ascii_lower_alpha(identifier[0]))
|
||||||
return DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
return ByteString::formatted("{:c}{}", to_ascii_uppercase(identifier[0]), identifier.substring_view(1));
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,14 +568,14 @@ struct DaylightSavingsOffset {
|
||||||
auto append_offsets = [&](auto const& name, auto type, auto const& offsets) {
|
auto append_offsets = [&](auto const& name, auto type, auto const& offsets) {
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("type", type);
|
generator.set("type", type);
|
||||||
generator.set("size", DeprecatedString::number(offsets.size()));
|
generator.set("size", ByteString::number(offsets.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@> @name@ { {
|
static constexpr Array<@type@, @size@> @name@ { {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
for (auto const& offset : offsets)
|
for (auto const& offset : offsets)
|
||||||
generator.append(DeprecatedString::formatted(" {},\n", offset));
|
generator.append(ByteString::formatted(" {},\n", offset));
|
||||||
|
|
||||||
generator.append("} };\n");
|
generator.append("} };\n");
|
||||||
};
|
};
|
||||||
|
@ -597,7 +597,7 @@ static constexpr Array<@type@, @size@> @name@ { {
|
||||||
auto const& time_zones = time_zone_data.time_zone_regions.find(value)->value;
|
auto const& time_zones = time_zone_data.time_zone_regions.find(value)->value;
|
||||||
|
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(time_zones.size()));
|
generator.set("size", ByteString::number(time_zones.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@string_index_type@, @size@> @name@ { {)~~~");
|
static constexpr Array<@string_index_type@, @size@> @name@ { {)~~~");
|
||||||
|
@ -605,14 +605,14 @@ static constexpr Array<@string_index_type@, @size@> @name@ { {)~~~");
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto const& time_zone : time_zones) {
|
for (auto const& time_zone : time_zones) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::number(time_zone));
|
generator.append(ByteString::number(time_zone));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.append(" } };");
|
generator.append(" } };");
|
||||||
});
|
});
|
||||||
|
|
||||||
generator.set("size", DeprecatedString::number(time_zone_data.time_zone_names.size()));
|
generator.set("size", ByteString::number(time_zone_data.time_zone_names.size()));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<Location, @size@> s_time_zone_locations { {
|
static constexpr Array<Location, @size@> s_time_zone_locations { {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -620,12 +620,12 @@ static constexpr Array<Location, @size@> s_time_zone_locations { {
|
||||||
for (auto const& time_zone : time_zone_data.time_zone_names) {
|
for (auto const& time_zone : time_zone_data.time_zone_names) {
|
||||||
auto location = time_zone_data.time_zone_coordinates.get(time_zone).value_or({});
|
auto location = time_zone_data.time_zone_coordinates.get(time_zone).value_or({});
|
||||||
|
|
||||||
generator.append(DeprecatedString::formatted(" {},\n", location));
|
generator.append(ByteString::formatted(" {},\n", location));
|
||||||
}
|
}
|
||||||
generator.append("} };\n");
|
generator.append("} };\n");
|
||||||
|
|
||||||
auto append_string_conversions = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
|
auto append_string_conversions = [&](StringView enum_title, StringView enum_snake, auto const& values, Vector<Alias> const& aliases = {}) -> ErrorOr<void> {
|
||||||
HashValueMap<DeprecatedString> hashes;
|
HashValueMap<ByteString> hashes;
|
||||||
TRY(hashes.try_ensure_capacity(values.size()));
|
TRY(hashes.try_ensure_capacity(values.size()));
|
||||||
|
|
||||||
auto hash = [](auto const& value) {
|
auto hash = [](auto const& value) {
|
||||||
|
@ -750,10 +750,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);
|
auto const& time_zone_offset = find_time_zone_offset(time_zone, time);
|
||||||
Array<NamedOffset, 2> named_offsets;
|
Array<NamedOffset, 2> named_offsets;
|
||||||
|
|
||||||
auto format_name = [](auto format, auto offset) -> DeprecatedString {
|
auto format_name = [](auto format, auto offset) -> ByteString {
|
||||||
if (offset == 0)
|
if (offset == 0)
|
||||||
return decode_string(format).replace("{}"sv, ""sv, ReplaceMode::FirstOnly);
|
return decode_string(format).replace("{}"sv, ""sv, ReplaceMode::FirstOnly);
|
||||||
return DeprecatedString::formatted(decode_string(format), decode_string(offset));
|
return ByteString::formatted(decode_string(format), decode_string(offset));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto set_named_offset = [&](auto& named_offset, auto dst_offset, auto in_dst, auto format, auto offset) {
|
auto set_named_offset = [&](auto& named_offset, auto dst_offset, auto in_dst, auto format, auto offset) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "GeneratorUtil.h"
|
#include "GeneratorUtil.h"
|
||||||
#include <AK/AnyOf.h>
|
#include <AK/AnyOf.h>
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
#include <AK/SourceGenerator.h>
|
#include <AK/SourceGenerator.h>
|
||||||
#include <AK/StringUtils.h>
|
#include <AK/StringUtils.h>
|
||||||
|
@ -20,11 +20,11 @@ struct Emoji {
|
||||||
size_t name { 0 };
|
size_t name { 0 };
|
||||||
Optional<size_t> image_path;
|
Optional<size_t> image_path;
|
||||||
Unicode::EmojiGroup group;
|
Unicode::EmojiGroup group;
|
||||||
DeprecatedString subgroup;
|
ByteString subgroup;
|
||||||
u32 display_order { 0 };
|
u32 display_order { 0 };
|
||||||
Vector<u32> code_points;
|
Vector<u32> code_points;
|
||||||
DeprecatedString encoded_code_points;
|
ByteString encoded_code_points;
|
||||||
DeprecatedString status;
|
ByteString status;
|
||||||
size_t code_point_array_index { 0 };
|
size_t code_point_array_index { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ static void set_image_path_for_emoji(StringView emoji_resource_path, EmojiData&
|
||||||
builder.appendff("U+{:X}", code_point);
|
builder.appendff("U+{:X}", code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file = DeprecatedString::formatted("{}.png", builder.to_deprecated_string());
|
auto file = ByteString::formatted("{}.png", builder.to_byte_string());
|
||||||
auto path = DeprecatedString::formatted("{}/{}", emoji_resource_path, file);
|
auto path = ByteString::formatted("{}/{}", emoji_resource_path, file);
|
||||||
if (!FileSystem::exists(path))
|
if (!FileSystem::exists(path))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ static ErrorOr<void> parse_emoji_test_data(Core::InputBufferedFile& file, EmojiD
|
||||||
Array<u8, 1024> buffer;
|
Array<u8, 1024> buffer;
|
||||||
|
|
||||||
Unicode::EmojiGroup group;
|
Unicode::EmojiGroup group;
|
||||||
DeprecatedString subgroup;
|
ByteString subgroup;
|
||||||
u32 display_order { 0 };
|
u32 display_order { 0 };
|
||||||
|
|
||||||
while (TRY(file.can_read_line())) {
|
while (TRY(file.can_read_line())) {
|
||||||
|
@ -157,7 +157,7 @@ static ErrorOr<void> parse_emoji_serenity_data(Core::InputBufferedFile& file, Em
|
||||||
return {};
|
return {};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
auto name = builder.to_deprecated_string();
|
auto name = builder.to_byte_string();
|
||||||
if (!any_of(name, is_ascii_lower_alpha))
|
if (!any_of(name, is_ascii_lower_alpha))
|
||||||
name = name.to_titlecase();
|
name = name.to_titlecase();
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ static ErrorOr<void> generate_emoji_data_implementation(Core::InputBufferedFile&
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
|
|
||||||
generator.set("string_index_type"sv, emoji_data.unique_strings.type_that_fits());
|
generator.set("string_index_type"sv, emoji_data.unique_strings.type_that_fits());
|
||||||
generator.set("emojis_size"sv, DeprecatedString::number(emoji_data.emojis.size()));
|
generator.set("emojis_size"sv, ByteString::number(emoji_data.emojis.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
|
@ -238,7 +238,7 @@ namespace Unicode {
|
||||||
for (auto const& emoji : emoji_data.emojis) {
|
for (auto const& emoji : emoji_data.emojis) {
|
||||||
total_code_point_count += emoji.code_points.size();
|
total_code_point_count += emoji.code_points.size();
|
||||||
}
|
}
|
||||||
generator.set("total_code_point_count", DeprecatedString::number(total_code_point_count));
|
generator.set("total_code_point_count", ByteString::number(total_code_point_count));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<u32, @total_code_point_count@> s_emoji_code_points { {)~~~");
|
static constexpr Array<u32, @total_code_point_count@> s_emoji_code_points { {)~~~");
|
||||||
|
@ -247,7 +247,7 @@ static constexpr Array<u32, @total_code_point_count@> s_emoji_code_points { {)~~
|
||||||
for (auto const& emoji : emoji_data.emojis) {
|
for (auto const& emoji : emoji_data.emojis) {
|
||||||
for (auto code_point : emoji.code_points) {
|
for (auto code_point : emoji.code_points) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::formatted("{:#x}", code_point));
|
generator.append(ByteString::formatted("{:#x}", code_point));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,12 +288,12 @@ struct EmojiData {
|
||||||
static constexpr Array<EmojiData, @emojis_size@> s_emojis { {)~~~");
|
static constexpr Array<EmojiData, @emojis_size@> s_emojis { {)~~~");
|
||||||
|
|
||||||
for (auto const& emoji : emoji_data.emojis) {
|
for (auto const& emoji : emoji_data.emojis) {
|
||||||
generator.set("name"sv, DeprecatedString::number(emoji.name));
|
generator.set("name"sv, ByteString::number(emoji.name));
|
||||||
generator.set("image_path"sv, DeprecatedString::number(emoji.image_path.value_or(0)));
|
generator.set("image_path"sv, ByteString::number(emoji.image_path.value_or(0)));
|
||||||
generator.set("group"sv, DeprecatedString::number(to_underlying(emoji.group)));
|
generator.set("group"sv, ByteString::number(to_underlying(emoji.group)));
|
||||||
generator.set("display_order"sv, DeprecatedString::number(emoji.display_order));
|
generator.set("display_order"sv, ByteString::number(emoji.display_order));
|
||||||
generator.set("code_point_start"sv, DeprecatedString::number(emoji.code_point_array_index));
|
generator.set("code_point_start"sv, ByteString::number(emoji.code_point_array_index));
|
||||||
generator.set("code_point_count"sv, DeprecatedString::number(emoji.code_points.size()));
|
generator.set("code_point_count"sv, ByteString::number(emoji.code_points.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
{ @name@, @image_path@, @group@, @display_order@, @code_point_start@, @code_point_count@ },)~~~");
|
{ @name@, @image_path@, @group@, @display_order@, @code_point_start@, @code_point_count@ },)~~~");
|
||||||
|
@ -370,7 +370,7 @@ static ErrorOr<void> generate_emoji_installation(Core::InputBufferedFile& file,
|
||||||
|
|
||||||
generator.append("@emoji@"sv);
|
generator.append("@emoji@"sv);
|
||||||
generator.append(" - "sv);
|
generator.append(" - "sv);
|
||||||
generator.append(DeprecatedString::join(" "sv, emoji.code_points, "U+{:X}"sv));
|
generator.append(ByteString::join(" "sv, emoji.code_points, "U+{:X}"sv));
|
||||||
generator.append(" @name@ (@status@)\n"sv);
|
generator.append(" @name@ (@status@)\n"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include "GeneratorUtil.h"
|
#include "GeneratorUtil.h"
|
||||||
#include <AK/AllOf.h>
|
#include <AK/AllOf.h>
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
|
#include <AK/ByteString.h>
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Find.h>
|
#include <AK/Find.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
@ -28,8 +28,8 @@ struct SpecialCasing {
|
||||||
Vector<u32> lowercase_mapping;
|
Vector<u32> lowercase_mapping;
|
||||||
Vector<u32> uppercase_mapping;
|
Vector<u32> uppercase_mapping;
|
||||||
Vector<u32> titlecase_mapping;
|
Vector<u32> titlecase_mapping;
|
||||||
DeprecatedString locale;
|
ByteString locale;
|
||||||
DeprecatedString condition;
|
ByteString condition;
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://www.unicode.org/reports/tr44/#CaseFolding.txt
|
// https://www.unicode.org/reports/tr44/#CaseFolding.txt
|
||||||
|
@ -42,13 +42,13 @@ struct CaseFolding {
|
||||||
// https://www.unicode.org/reports/tr44/#Character_Decomposition_Mappings
|
// https://www.unicode.org/reports/tr44/#Character_Decomposition_Mappings
|
||||||
struct CodePointDecomposition {
|
struct CodePointDecomposition {
|
||||||
// `tag` is a string since it's used for codegen as an enum value.
|
// `tag` is a string since it's used for codegen as an enum value.
|
||||||
DeprecatedString tag { "Canonical"sv };
|
ByteString tag { "Canonical"sv };
|
||||||
size_t decomposition_index { 0 };
|
size_t decomposition_index { 0 };
|
||||||
size_t decomposition_size { 0 };
|
size_t decomposition_size { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://www.unicode.org/reports/tr44/#PropList.txt
|
// https://www.unicode.org/reports/tr44/#PropList.txt
|
||||||
using PropList = HashMap<DeprecatedString, Vector<Unicode::CodePointRange>>;
|
using PropList = HashMap<ByteString, Vector<Unicode::CodePointRange>>;
|
||||||
|
|
||||||
// https://www.unicode.org/reports/tr44/#DerivedNormalizationProps.txt
|
// https://www.unicode.org/reports/tr44/#DerivedNormalizationProps.txt
|
||||||
enum class QuickCheck {
|
enum class QuickCheck {
|
||||||
|
@ -63,7 +63,7 @@ struct Normalization {
|
||||||
QuickCheck quick_check { QuickCheck::Yes };
|
QuickCheck quick_check { QuickCheck::Yes };
|
||||||
};
|
};
|
||||||
|
|
||||||
using NormalizationProps = HashMap<DeprecatedString, Vector<Normalization>>;
|
using NormalizationProps = HashMap<ByteString, Vector<Normalization>>;
|
||||||
|
|
||||||
struct CodePointName {
|
struct CodePointName {
|
||||||
Unicode::CodePointRange code_point_range;
|
Unicode::CodePointRange code_point_range;
|
||||||
|
@ -92,16 +92,16 @@ struct CasingTable {
|
||||||
// https://www.unicode.org/reports/tr44/#UnicodeData.txt
|
// https://www.unicode.org/reports/tr44/#UnicodeData.txt
|
||||||
struct CodePointData {
|
struct CodePointData {
|
||||||
u32 code_point { 0 };
|
u32 code_point { 0 };
|
||||||
DeprecatedString name;
|
ByteString name;
|
||||||
Optional<size_t> abbreviation;
|
Optional<size_t> abbreviation;
|
||||||
DeprecatedString bidi_class;
|
ByteString bidi_class;
|
||||||
Optional<CodePointDecomposition> decomposition_mapping;
|
Optional<CodePointDecomposition> decomposition_mapping;
|
||||||
Optional<i8> numeric_value_decimal;
|
Optional<i8> numeric_value_decimal;
|
||||||
Optional<i8> numeric_value_digit;
|
Optional<i8> numeric_value_digit;
|
||||||
Optional<i8> numeric_value_numeric;
|
Optional<i8> numeric_value_numeric;
|
||||||
bool bidi_mirrored { false };
|
bool bidi_mirrored { false };
|
||||||
DeprecatedString unicode_1_name;
|
ByteString unicode_1_name;
|
||||||
DeprecatedString iso_comment;
|
ByteString iso_comment;
|
||||||
CasingTable casing;
|
CasingTable casing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ struct CodePointTables {
|
||||||
|
|
||||||
struct CodePointBidiClass {
|
struct CodePointBidiClass {
|
||||||
Unicode::CodePointRange code_point_range;
|
Unicode::CodePointRange code_point_range;
|
||||||
DeprecatedString bidi_class;
|
ByteString bidi_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UnicodeData {
|
struct UnicodeData {
|
||||||
|
@ -135,12 +135,12 @@ struct UnicodeData {
|
||||||
|
|
||||||
u32 code_points_with_decomposition_mapping { 0 };
|
u32 code_points_with_decomposition_mapping { 0 };
|
||||||
Vector<u32> decomposition_mappings;
|
Vector<u32> decomposition_mappings;
|
||||||
Vector<DeprecatedString> compatibility_tags;
|
Vector<ByteString> compatibility_tags;
|
||||||
|
|
||||||
Vector<SpecialCasing> special_casing;
|
Vector<SpecialCasing> special_casing;
|
||||||
u32 largest_special_casing_mapping_size { 0 };
|
u32 largest_special_casing_mapping_size { 0 };
|
||||||
Vector<DeprecatedString> conditions;
|
Vector<ByteString> conditions;
|
||||||
Vector<DeprecatedString> locales;
|
Vector<ByteString> locales;
|
||||||
|
|
||||||
Vector<CaseFolding> case_folding;
|
Vector<CaseFolding> case_folding;
|
||||||
u32 largest_case_folding_mapping_size { 0 };
|
u32 largest_case_folding_mapping_size { 0 };
|
||||||
|
@ -190,11 +190,11 @@ struct UnicodeData {
|
||||||
CodePointTables<PropertyTable> word_break_tables;
|
CodePointTables<PropertyTable> word_break_tables;
|
||||||
CodePointTables<PropertyTable> sentence_break_tables;
|
CodePointTables<PropertyTable> sentence_break_tables;
|
||||||
|
|
||||||
HashTable<DeprecatedString> bidirectional_classes;
|
HashTable<ByteString> bidirectional_classes;
|
||||||
Vector<CodePointBidiClass> code_point_bidirectional_classes;
|
Vector<CodePointBidiClass> code_point_bidirectional_classes;
|
||||||
};
|
};
|
||||||
|
|
||||||
static DeprecatedString sanitize_entry(DeprecatedString const& entry)
|
static ByteString sanitize_entry(ByteString const& entry)
|
||||||
{
|
{
|
||||||
auto sanitized = entry.replace("-"sv, "_"sv, ReplaceMode::All);
|
auto sanitized = entry.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||||
sanitized = sanitized.replace(" "sv, "_"sv, ReplaceMode::All);
|
sanitized = sanitized.replace(" "sv, "_"sv, ReplaceMode::All);
|
||||||
|
@ -209,7 +209,7 @@ static DeprecatedString sanitize_entry(DeprecatedString const& entry)
|
||||||
next_is_upper = ch == '_';
|
next_is_upper = ch == '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_special_casing(Core::InputBufferedFile& file, UnicodeData& unicode_data)
|
static ErrorOr<void> parse_special_casing(Core::InputBufferedFile& file, UnicodeData& unicode_data)
|
||||||
|
@ -248,7 +248,7 @@ static ErrorOr<void> parse_special_casing(Core::InputBufferedFile& file, Unicode
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!casing.locale.is_empty()) {
|
if (!casing.locale.is_empty()) {
|
||||||
casing.locale = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
|
casing.locale = ByteString::formatted("{:c}{}", to_ascii_uppercase(casing.locale[0]), casing.locale.substring_view(1));
|
||||||
|
|
||||||
if (!unicode_data.locales.contains_slow(casing.locale))
|
if (!unicode_data.locales.contains_slow(casing.locale))
|
||||||
unicode_data.locales.append(casing.locale);
|
unicode_data.locales.append(casing.locale);
|
||||||
|
@ -380,7 +380,7 @@ static ErrorOr<void> parse_prop_list(Core::InputBufferedFile& file, PropList& pr
|
||||||
|
|
||||||
static ErrorOr<void> parse_alias_list(Core::InputBufferedFile& file, PropList const& prop_list, Vector<Alias>& prop_aliases)
|
static ErrorOr<void> parse_alias_list(Core::InputBufferedFile& file, PropList const& prop_list, Vector<Alias>& prop_aliases)
|
||||||
{
|
{
|
||||||
DeprecatedString current_property;
|
ByteString current_property;
|
||||||
Array<u8, 1024> buffer;
|
Array<u8, 1024> buffer;
|
||||||
|
|
||||||
auto append_alias = [&](auto alias, auto property) {
|
auto append_alias = [&](auto alias, auto property) {
|
||||||
|
@ -455,7 +455,7 @@ static ErrorOr<void> parse_name_aliases(Core::InputBufferedFile& file, UnicodeDa
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> parse_value_alias_list(Core::InputBufferedFile& file, StringView desired_category, Vector<DeprecatedString> 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::InputBufferedFile& file, StringView desired_category, Vector<ByteString> const& value_list, Vector<Alias>& prop_aliases, bool primary_value_is_first = true, bool sanitize_alias = false)
|
||||||
{
|
{
|
||||||
TRY(file.seek(0, SeekMode::SetPosition));
|
TRY(file.seek(0, SeekMode::SetPosition));
|
||||||
Array<u8, 1024> buffer;
|
Array<u8, 1024> buffer;
|
||||||
|
@ -518,7 +518,7 @@ static ErrorOr<void> parse_normalization_props(Core::InputBufferedFile& file, Un
|
||||||
VERIFY((segments.size() == 2) || (segments.size() == 3));
|
VERIFY((segments.size() == 2) || (segments.size() == 3));
|
||||||
|
|
||||||
auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
|
auto code_point_range = parse_code_point_range(segments[0].trim_whitespace());
|
||||||
auto property = segments[1].trim_whitespace().to_deprecated_string();
|
auto property = segments[1].trim_whitespace().to_byte_string();
|
||||||
|
|
||||||
Vector<u32> value;
|
Vector<u32> value;
|
||||||
QuickCheck quick_check = QuickCheck::Yes;
|
QuickCheck quick_check = QuickCheck::Yes;
|
||||||
|
@ -620,7 +620,7 @@ static Optional<CodePointDecomposition> parse_decomposition_mapping(StringView s
|
||||||
if (parts.first().starts_with('<')) {
|
if (parts.first().starts_with('<')) {
|
||||||
auto const tag = parts.take_first().trim("<>"sv);
|
auto const tag = parts.take_first().trim("<>"sv);
|
||||||
|
|
||||||
mapping.tag = DeprecatedString::formatted("{:c}{}", to_ascii_uppercase(tag[0]), tag.substring_view(1));
|
mapping.tag = ByteString::formatted("{:c}{}", to_ascii_uppercase(tag[0]), tag.substring_view(1));
|
||||||
|
|
||||||
if (!unicode_data.compatibility_tags.contains_slow(mapping.tag))
|
if (!unicode_data.compatibility_tags.contains_slow(mapping.tag))
|
||||||
unicode_data.compatibility_tags.append(mapping.tag);
|
unicode_data.compatibility_tags.append(mapping.tag);
|
||||||
|
@ -755,15 +755,15 @@ static ErrorOr<void> generate_unicode_data_header(Core::InputBufferedFile& file,
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
generator.set("special_casing_mapping_size", DeprecatedString::number(unicode_data.largest_special_casing_mapping_size));
|
generator.set("special_casing_mapping_size", ByteString::number(unicode_data.largest_special_casing_mapping_size));
|
||||||
generator.set("case_folding_mapping_size", DeprecatedString::number(unicode_data.largest_case_folding_mapping_size));
|
generator.set("case_folding_mapping_size", ByteString::number(unicode_data.largest_case_folding_mapping_size));
|
||||||
|
|
||||||
auto generate_enum = [&](StringView name, StringView default_, auto values, Vector<Alias> aliases = {}) {
|
auto generate_enum = [&](StringView name, StringView default_, auto values, Vector<Alias> aliases = {}) {
|
||||||
quick_sort(values);
|
quick_sort(values);
|
||||||
quick_sort(aliases, [](auto& alias1, auto& alias2) { return alias1.alias < alias2.alias; });
|
quick_sort(aliases, [](auto& alias1, auto& alias2) { return alias1.alias < alias2.alias; });
|
||||||
|
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("underlying", DeprecatedString::formatted("{}UnderlyingType", name));
|
generator.set("underlying", ByteString::formatted("{}UnderlyingType", name));
|
||||||
generator.set("type", ((values.size() + !default_.is_empty()) < 256) ? "u8"sv : "u16"sv);
|
generator.set("type", ((values.size() + !default_.is_empty()) < 256) ? "u8"sv : "u16"sv);
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
|
@ -872,8 +872,8 @@ static ErrorOr<void> generate_unicode_data_implementation(Core::InputBufferedFil
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
|
|
||||||
generator.set("string_index_type"sv, unicode_data.unique_strings.type_that_fits());
|
generator.set("string_index_type"sv, unicode_data.unique_strings.type_that_fits());
|
||||||
generator.set("special_casing_size", DeprecatedString::number(unicode_data.special_casing.size()));
|
generator.set("special_casing_size", ByteString::number(unicode_data.special_casing.size()));
|
||||||
generator.set("case_folding_size", DeprecatedString::number(unicode_data.case_folding.size()));
|
generator.set("case_folding_size", ByteString::number(unicode_data.case_folding.size()));
|
||||||
|
|
||||||
generator.set("CODE_POINT_TABLES_LSB_COUNT", TRY(String::number(CODE_POINT_TABLES_LSB_COUNT)));
|
generator.set("CODE_POINT_TABLES_LSB_COUNT", TRY(String::number(CODE_POINT_TABLES_LSB_COUNT)));
|
||||||
generator.set("CODE_POINT_TABLES_LSB_MASK", TRY(String::formatted("{:#x}", CODE_POINT_TABLES_LSB_MASK)));
|
generator.set("CODE_POINT_TABLES_LSB_MASK", TRY(String::formatted("{:#x}", CODE_POINT_TABLES_LSB_MASK)));
|
||||||
|
@ -884,7 +884,7 @@ static ErrorOr<void> generate_unicode_data_implementation(Core::InputBufferedFil
|
||||||
#include <AK/CharacterTypes.h>
|
#include <AK/CharacterTypes.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <LibUnicode/CharacterTypes.h>
|
#include <LibUnicode/CharacterTypes.h>
|
||||||
#include <LibUnicode/UnicodeData.h>
|
#include <LibUnicode/UnicodeData.h>
|
||||||
|
@ -905,17 +905,17 @@ namespace Unicode {
|
||||||
generator.append(", {");
|
generator.append(", {");
|
||||||
for (auto const& item : list) {
|
for (auto const& item : list) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::formatted(format, item));
|
generator.append(ByteString::formatted(format, item));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
generator.append(DeprecatedString::formatted(" }}, {}", list.size()));
|
generator.append(ByteString::formatted(" }}, {}", list.size()));
|
||||||
};
|
};
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<SpecialCasing, @special_casing_size@> s_special_case { {)~~~");
|
static constexpr Array<SpecialCasing, @special_casing_size@> s_special_case { {)~~~");
|
||||||
|
|
||||||
for (auto const& casing : unicode_data.special_casing) {
|
for (auto const& casing : unicode_data.special_casing) {
|
||||||
generator.set("code_point", DeprecatedString::formatted("{:#x}", casing.code_point));
|
generator.set("code_point", ByteString::formatted("{:#x}", casing.code_point));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
{ @code_point@)~~~");
|
{ @code_point@)~~~");
|
||||||
|
|
||||||
|
@ -939,7 +939,7 @@ static constexpr Array<SpecialCasing, @special_casing_size@> s_special_case { {)
|
||||||
static constexpr Array<CaseFolding, @case_folding_size@> s_case_folding { {)~~~");
|
static constexpr Array<CaseFolding, @case_folding_size@> s_case_folding { {)~~~");
|
||||||
|
|
||||||
for (auto const& folding : unicode_data.case_folding) {
|
for (auto const& folding : unicode_data.case_folding) {
|
||||||
generator.set("code_point", DeprecatedString::formatted("{:#x}", folding.code_point));
|
generator.set("code_point", ByteString::formatted("{:#x}", folding.code_point));
|
||||||
generator.set("status", folding.status);
|
generator.set("status", folding.status);
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
{ @code_point@, CaseFoldingStatus::@status@)~~~");
|
{ @code_point@, CaseFoldingStatus::@status@)~~~");
|
||||||
|
@ -1015,15 +1015,15 @@ struct CodePointBidiClassComparator : public CodePointRangeComparator {
|
||||||
|
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
generator.set("decomposition_mappings_size", DeprecatedString::number(unicode_data.decomposition_mappings.size()));
|
generator.set("decomposition_mappings_size", ByteString::number(unicode_data.decomposition_mappings.size()));
|
||||||
generator.append("\nstatic constexpr Array<u32, @decomposition_mappings_size@> s_decomposition_mappings_data { ");
|
generator.append("\nstatic constexpr Array<u32, @decomposition_mappings_size@> s_decomposition_mappings_data { ");
|
||||||
generator.append(DeprecatedString::join(", "sv, unicode_data.decomposition_mappings, "{:#x}"sv));
|
generator.append(ByteString::join(", "sv, unicode_data.decomposition_mappings, "{:#x}"sv));
|
||||||
generator.append(" };\n");
|
generator.append(" };\n");
|
||||||
|
|
||||||
auto append_code_point_mappings = [&](StringView name, StringView mapping_type, u32 size, auto mapping_getter) {
|
auto append_code_point_mappings = [&](StringView name, StringView mapping_type, u32 size, auto mapping_getter) {
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("mapping_type", mapping_type);
|
generator.set("mapping_type", mapping_type);
|
||||||
generator.set("size", DeprecatedString::number(size));
|
generator.set("size", ByteString::number(size));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
|
static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
|
||||||
|
@ -1046,16 +1046,16 @@ static constexpr Array<@mapping_type@, @size@> s_@name@_mappings { {
|
||||||
if (mappings_in_current_row++ > 0)
|
if (mappings_in_current_row++ > 0)
|
||||||
generator.append(" ");
|
generator.append(" ");
|
||||||
|
|
||||||
generator.set("code_point", DeprecatedString::formatted("{:#x}", data.code_point));
|
generator.set("code_point", ByteString::formatted("{:#x}", data.code_point));
|
||||||
generator.append("{ @code_point@");
|
generator.append("{ @code_point@");
|
||||||
|
|
||||||
if constexpr (IsSame<decltype(mapping), Optional<u32>> || IsSame<decltype(mapping), Optional<size_t>>) {
|
if constexpr (IsSame<decltype(mapping), Optional<u32>> || IsSame<decltype(mapping), Optional<size_t>>) {
|
||||||
generator.set("mapping", DeprecatedString::formatted("{:#x}", *mapping));
|
generator.set("mapping", ByteString::formatted("{:#x}", *mapping));
|
||||||
generator.append(", @mapping@ },");
|
generator.append(", @mapping@ },");
|
||||||
} else if constexpr (IsSame<decltype(mapping), Optional<CodePointDecomposition>>) {
|
} else if constexpr (IsSame<decltype(mapping), Optional<CodePointDecomposition>>) {
|
||||||
generator.set("tag", mapping->tag);
|
generator.set("tag", mapping->tag);
|
||||||
generator.set("start", DeprecatedString::number(mapping->decomposition_index));
|
generator.set("start", ByteString::number(mapping->decomposition_index));
|
||||||
generator.set("size", DeprecatedString::number(mapping->decomposition_size));
|
generator.set("size", ByteString::number(mapping->decomposition_size));
|
||||||
generator.append(", CompatibilityFormattingTag::@tag@, @start@, @size@ },");
|
generator.append(", CompatibilityFormattingTag::@tag@, @start@, @size@ },");
|
||||||
} else {
|
} else {
|
||||||
append_list_and_size(mapping, "&s_@name@[{}]"sv);
|
append_list_and_size(mapping, "&s_@name@[{}]"sv);
|
||||||
|
@ -1195,7 +1195,7 @@ static constexpr Array<@type@, @size@> @name@ { {
|
||||||
|
|
||||||
generator.set("type", type);
|
generator.set("type", type);
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(display_names.size()));
|
generator.set("size", ByteString::number(display_names.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@> @name@ { {
|
static constexpr Array<@type@, @size@> @name@ { {
|
||||||
|
@ -1204,9 +1204,9 @@ static constexpr Array<@type@, @size@> @name@ { {
|
||||||
if (values_in_current_row++ > 0)
|
if (values_in_current_row++ > 0)
|
||||||
generator.append(", ");
|
generator.append(", ");
|
||||||
|
|
||||||
generator.set("first", DeprecatedString::formatted("{:#x}", display_name.code_point_range.first));
|
generator.set("first", ByteString::formatted("{:#x}", display_name.code_point_range.first));
|
||||||
generator.set("last", DeprecatedString::formatted("{:#x}", display_name.code_point_range.last));
|
generator.set("last", ByteString::formatted("{:#x}", display_name.code_point_range.last));
|
||||||
generator.set("name", DeprecatedString::number(display_name.name));
|
generator.set("name", ByteString::number(display_name.name));
|
||||||
generator.append("{ { @first@, @last@ }, @name@ }");
|
generator.append("{ { @first@, @last@ }, @name@ }");
|
||||||
|
|
||||||
if (values_in_current_row == max_values_per_row) {
|
if (values_in_current_row == max_values_per_row) {
|
||||||
|
@ -1226,7 +1226,7 @@ static constexpr Array<@type@, @size@> @name@ { {
|
||||||
constexpr size_t max_bidi_classes_per_row = 20;
|
constexpr size_t max_bidi_classes_per_row = 20;
|
||||||
size_t bidi_classes_in_current_row = 0;
|
size_t bidi_classes_in_current_row = 0;
|
||||||
|
|
||||||
generator.set("size"sv, DeprecatedString::number(unicode_data.code_point_bidirectional_classes.size()));
|
generator.set("size"sv, ByteString::number(unicode_data.code_point_bidirectional_classes.size()));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<BidiClassData, @size@> s_bidirectional_classes { {
|
static constexpr Array<BidiClassData, @size@> s_bidirectional_classes { {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -1234,8 +1234,8 @@ static constexpr Array<BidiClassData, @size@> s_bidirectional_classes { {
|
||||||
if (bidi_classes_in_current_row++ > 0)
|
if (bidi_classes_in_current_row++ > 0)
|
||||||
generator.append(", ");
|
generator.append(", ");
|
||||||
|
|
||||||
generator.set("first", DeprecatedString::formatted("{:#x}", data.code_point_range.first));
|
generator.set("first", ByteString::formatted("{:#x}", data.code_point_range.first));
|
||||||
generator.set("last", DeprecatedString::formatted("{:#x}", data.code_point_range.last));
|
generator.set("last", ByteString::formatted("{:#x}", data.code_point_range.last));
|
||||||
generator.set("bidi_class", data.bidi_class);
|
generator.set("bidi_class", data.bidi_class);
|
||||||
generator.append("{ { @first@, @last@ }, BidirectionalClass::@bidi_class@ }");
|
generator.append("{ { @first@, @last@ }, BidirectionalClass::@bidi_class@ }");
|
||||||
|
|
||||||
|
@ -1274,13 +1274,13 @@ ReadonlySpan<BlockName> block_display_names()
|
||||||
return display_names.span();
|
return display_names.span();
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<DeprecatedString> code_point_display_name(u32 code_point)
|
Optional<ByteString> code_point_display_name(u32 code_point)
|
||||||
{
|
{
|
||||||
if (auto const* entry = binary_search(s_code_point_display_names, code_point, nullptr, CodePointNameComparator {})) {
|
if (auto const* entry = binary_search(s_code_point_display_names, code_point, nullptr, CodePointNameComparator {})) {
|
||||||
auto display_name = decode_string(entry->display_name);
|
auto display_name = decode_string(entry->display_name);
|
||||||
|
|
||||||
if (display_name.ends_with("{:X}"sv))
|
if (display_name.ends_with("{:X}"sv))
|
||||||
return DeprecatedString::formatted(display_name, code_point);
|
return ByteString::formatted(display_name, code_point);
|
||||||
|
|
||||||
return display_name;
|
return display_name;
|
||||||
}
|
}
|
||||||
|
@ -1409,7 +1409,7 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
|
||||||
ValueFromStringOptions options {};
|
ValueFromStringOptions options {};
|
||||||
|
|
||||||
for (auto const& prop : prop_list) {
|
for (auto const& prop : prop_list) {
|
||||||
if constexpr (IsSame<RemoveCVReference<decltype(prop)>, DeprecatedString>) {
|
if constexpr (IsSame<RemoveCVReference<decltype(prop)>, ByteString>) {
|
||||||
hashes.set(CaseInsensitiveASCIIStringViewTraits::hash(prop), prop);
|
hashes.set(CaseInsensitiveASCIIStringViewTraits::hash(prop), prop);
|
||||||
options.sensitivity = CaseSensitivity::CaseInsensitive;
|
options.sensitivity = CaseSensitivity::CaseInsensitive;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/HashFunctions.h>
|
#include <AK/HashFunctions.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
@ -101,7 +101,7 @@ public:
|
||||||
{
|
{
|
||||||
generator.set("type"sv, type);
|
generator.set("type"sv, type);
|
||||||
generator.set("name"sv, name);
|
generator.set("name"sv, name);
|
||||||
generator.set("size"sv, DeprecatedString::number(m_storage.size()));
|
generator.set("size"sv, ByteString::number(m_storage.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@ + 1> @name@ { {
|
static constexpr Array<@type@, @size@ + 1> @name@ { {
|
||||||
|
@ -113,10 +113,10 @@ static constexpr Array<@type@, @size@ + 1> @name@ { {
|
||||||
if (values_in_current_row++ > 0)
|
if (values_in_current_row++ > 0)
|
||||||
generator.append(", ");
|
generator.append(", ");
|
||||||
|
|
||||||
if constexpr (IsSame<StorageType, DeprecatedString>)
|
if constexpr (IsSame<StorageType, ByteString>)
|
||||||
generator.append(DeprecatedString::formatted("\"{}\"sv", value));
|
generator.append(ByteString::formatted("\"{}\"sv", value));
|
||||||
else
|
else
|
||||||
generator.append(DeprecatedString::formatted("{}", value));
|
generator.append(ByteString::formatted("{}", value));
|
||||||
|
|
||||||
if (values_in_current_row == max_values_per_row) {
|
if (values_in_current_row == max_values_per_row) {
|
||||||
values_in_current_row = 0;
|
values_in_current_row = 0;
|
||||||
|
@ -138,8 +138,8 @@ static constexpr Array<@type@, @size@ + 1> @name@ { {
|
||||||
for (size_t i = 0; i < m_storage.size(); ++i) {
|
for (size_t i = 0; i < m_storage.size(); ++i) {
|
||||||
auto const& list = m_storage[i];
|
auto const& list = m_storage[i];
|
||||||
|
|
||||||
generator.set("index"sv, DeprecatedString::number(i));
|
generator.set("index"sv, ByteString::number(i));
|
||||||
generator.set("size"sv, DeprecatedString::number(list.size()));
|
generator.set("size"sv, ByteString::number(list.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<@type@, @size@> @name@@index@ { {)~~~");
|
static constexpr Array<@type@, @size@> @name@@index@ { {)~~~");
|
||||||
|
@ -147,14 +147,14 @@ static constexpr Array<@type@, @size@> @name@@index@ { {)~~~");
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto const& value : list) {
|
for (auto const& value : list) {
|
||||||
generator.append(first ? " "sv : ", "sv);
|
generator.append(first ? " "sv : ", "sv);
|
||||||
generator.append(DeprecatedString::formatted("{}", value));
|
generator.append(ByteString::formatted("{}", value));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.append(" } };");
|
generator.append(" } };");
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.set("size"sv, DeprecatedString::number(m_storage.size()));
|
generator.set("size"sv, ByteString::number(m_storage.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ static constexpr Array<ReadonlySpan<@type@>, @size@ + 1> @name@ { {
|
||||||
if (values_in_current_row++ > 0)
|
if (values_in_current_row++ > 0)
|
||||||
generator.append(", ");
|
generator.append(", ");
|
||||||
|
|
||||||
generator.set("index"sv, DeprecatedString::number(i));
|
generator.set("index"sv, ByteString::number(i));
|
||||||
generator.append("@name@@index@.span()");
|
generator.append("@name@@index@.span()");
|
||||||
|
|
||||||
if (values_in_current_row == max_values_per_row) {
|
if (values_in_current_row == max_values_per_row) {
|
||||||
|
@ -187,8 +187,8 @@ protected:
|
||||||
HashMap<StorageType, size_t> m_storage_indices;
|
HashMap<StorageType, size_t> m_storage_indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UniqueStringStorage : public UniqueStorage<DeprecatedString> {
|
class UniqueStringStorage : public UniqueStorage<ByteString> {
|
||||||
using Base = UniqueStorage<DeprecatedString>;
|
using Base = UniqueStorage<ByteString>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// The goal of the string table generator is to ensure the table is located within the read-only
|
// The goal of the string table generator is to ensure the table is located within the read-only
|
||||||
|
@ -204,7 +204,7 @@ public:
|
||||||
if (values_in_current_row++ > 0)
|
if (values_in_current_row++ > 0)
|
||||||
generator.append(", ");
|
generator.append(", ");
|
||||||
|
|
||||||
generator.append(DeprecatedString::formatted("{:#x}", value));
|
generator.append(ByteString::formatted("{:#x}", value));
|
||||||
|
|
||||||
if (values_in_current_row == max_values_per_row) {
|
if (values_in_current_row == max_values_per_row) {
|
||||||
values_in_current_row = 0;
|
values_in_current_row = 0;
|
||||||
|
@ -224,7 +224,7 @@ public:
|
||||||
next_index += string.length() + 2;
|
next_index += string.length() + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.set("size", DeprecatedString::number(next_index));
|
generator.set("size", ByteString::number(next_index));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<u8, @size@> s_encoded_strings { {
|
static constexpr Array<u8, @size@> s_encoded_strings { {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -242,7 +242,7 @@ static constexpr Array<u8, @size@> s_encoded_strings { {
|
||||||
} };
|
} };
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
generator.set("size", DeprecatedString::number(string_indices.size()));
|
generator.set("size", ByteString::number(string_indices.size()));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<u32, @size@> s_encoded_string_indices { {
|
static constexpr Array<u32, @size@> s_encoded_string_indices { {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -276,8 +276,8 @@ static constexpr StringView decode_string(size_t index)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Alias {
|
struct Alias {
|
||||||
DeprecatedString name;
|
ByteString name;
|
||||||
DeprecatedString alias;
|
ByteString alias;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CanonicalLanguageID {
|
struct CanonicalLanguageID {
|
||||||
|
@ -385,11 +385,11 @@ void generate_value_from_string(SourceGenerator& generator, StringView method_na
|
||||||
{
|
{
|
||||||
ensure_from_string_types_are_generated(generator);
|
ensure_from_string_types_are_generated(generator);
|
||||||
|
|
||||||
generator.set("method_name", DeprecatedString::formatted(method_name_format, value_name));
|
generator.set("method_name", ByteString::formatted(method_name_format, value_name));
|
||||||
generator.set("value_type", value_type);
|
generator.set("value_type", value_type);
|
||||||
generator.set("value_name", value_name);
|
generator.set("value_name", value_name);
|
||||||
generator.set("return_type", options.return_type.has_value() ? *options.return_type : value_type);
|
generator.set("return_type", options.return_type.has_value() ? *options.return_type : value_type);
|
||||||
generator.set("size", DeprecatedString::number(hashes.size()));
|
generator.set("size", ByteString::number(hashes.size()));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
Optional<@return_type@> @method_name@(StringView key)
|
Optional<@return_type@> @method_name@(StringView key)
|
||||||
|
@ -408,11 +408,11 @@ Optional<@return_type@> @method_name@(StringView key)
|
||||||
generator.append(" ");
|
generator.append(" ");
|
||||||
|
|
||||||
if constexpr (IsIntegral<ValueType>)
|
if constexpr (IsIntegral<ValueType>)
|
||||||
generator.set("value"sv, DeprecatedString::number(hashes.get(hash_key).value()));
|
generator.set("value"sv, ByteString::number(hashes.get(hash_key).value()));
|
||||||
else
|
else
|
||||||
generator.set("value"sv, DeprecatedString::formatted("{}::{}", value_type, hashes.get(hash_key).value()));
|
generator.set("value"sv, ByteString::formatted("{}::{}", value_type, hashes.get(hash_key).value()));
|
||||||
|
|
||||||
generator.set("hash"sv, DeprecatedString::number(hash_key));
|
generator.set("hash"sv, ByteString::number(hash_key));
|
||||||
generator.append("{ @hash@U, @value@ },"sv);
|
generator.append("{ @hash@U, @value@ },"sv);
|
||||||
|
|
||||||
if (values_in_current_row == max_values_per_row) {
|
if (values_in_current_row == max_values_per_row) {
|
||||||
|
@ -421,7 +421,7 @@ Optional<@return_type@> @method_name@(StringView key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.set("return_statement", DeprecatedString::formatted(options.return_format, "value->value"sv));
|
generator.set("return_statement", ByteString::formatted(options.return_format, "value->value"sv));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
} };
|
} };
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -445,9 +445,9 @@ Optional<@return_type@> @method_name@(StringView key)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IdentifierFormatter>
|
template<typename IdentifierFormatter>
|
||||||
void generate_value_to_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, IdentifierFormatter&& format_identifier, ReadonlySpan<DeprecatedString> values)
|
void generate_value_to_string(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, IdentifierFormatter&& format_identifier, ReadonlySpan<ByteString> values)
|
||||||
{
|
{
|
||||||
generator.set("method_name", DeprecatedString::formatted(method_name_format, value_name));
|
generator.set("method_name", ByteString::formatted(method_name_format, value_name));
|
||||||
generator.set("value_type", value_type);
|
generator.set("value_type", value_type);
|
||||||
generator.set("value_name", value_name);
|
generator.set("value_name", value_name);
|
||||||
|
|
||||||
|
@ -475,7 +475,7 @@ StringView @method_name@(@value_type@ @value_name@)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IdentifierFormatter>
|
template<typename IdentifierFormatter>
|
||||||
void generate_enum(SourceGenerator& generator, IdentifierFormatter&& format_identifier, StringView name, StringView default_, Vector<DeprecatedString>& values, Vector<Alias> aliases = {})
|
void generate_enum(SourceGenerator& generator, IdentifierFormatter&& format_identifier, StringView name, StringView default_, Vector<ByteString>& values, Vector<Alias> aliases = {})
|
||||||
{
|
{
|
||||||
quick_sort(values, [](auto const& value1, auto const& value2) { return value1.to_lowercase() < value2.to_lowercase(); });
|
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(); });
|
quick_sort(aliases, [](auto const& alias1, auto const& alias2) { return alias1.alias.to_lowercase() < alias2.alias.to_lowercase(); });
|
||||||
|
@ -514,20 +514,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)
|
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) {
|
auto format_mapping_name = [&](StringView format, StringView name) {
|
||||||
DeprecatedString mapping_name;
|
ByteString mapping_name;
|
||||||
|
|
||||||
if constexpr (IsNullPointer<IdentifierFormatter>)
|
if constexpr (IsNullPointer<IdentifierFormatter>)
|
||||||
mapping_name = name.replace("-"sv, "_"sv, ReplaceMode::All);
|
mapping_name = name.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||||
else
|
else
|
||||||
mapping_name = format_identifier(type, name);
|
mapping_name = format_identifier(type, name);
|
||||||
|
|
||||||
return DeprecatedString::formatted(format, mapping_name.to_lowercase());
|
return ByteString::formatted(format, mapping_name.to_lowercase());
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<DeprecatedString> mapping_names;
|
Vector<ByteString> mapping_names;
|
||||||
|
|
||||||
for (auto const& locale : locales) {
|
for (auto const& locale : locales) {
|
||||||
DeprecatedString mapping_name;
|
ByteString mapping_name;
|
||||||
|
|
||||||
if constexpr (requires { locale.key; }) {
|
if constexpr (requires { locale.key; }) {
|
||||||
mapping_name = format_mapping_name(format, locale.key);
|
mapping_name = format_mapping_name(format, locale.key);
|
||||||
|
@ -544,7 +544,7 @@ void generate_mapping(SourceGenerator& generator, LocalesType const& locales, St
|
||||||
|
|
||||||
generator.set("type", type);
|
generator.set("type", type);
|
||||||
generator.set("name", name);
|
generator.set("name", name);
|
||||||
generator.set("size", DeprecatedString::number(locales.size()));
|
generator.set("size", ByteString::number(locales.size()));
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
static constexpr Array<ReadonlySpan<@type@>, @size@> @name@ { {
|
static constexpr Array<ReadonlySpan<@type@>, @size@> @name@ { {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -589,9 +589,9 @@ ReadonlySpan<StringView> @name@()
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
if (auto it = aliases.find_if([&](auto const& alias) { return alias.alias == value; }); it != aliases.end())
|
if (auto it = aliases.find_if([&](auto const& alias) { return alias.alias == value; }); it != aliases.end())
|
||||||
generator.append(DeprecatedString::formatted("\"{}\"sv", it->name));
|
generator.append(ByteString::formatted("\"{}\"sv", it->name));
|
||||||
else
|
else
|
||||||
generator.append(DeprecatedString::formatted("\"{}\"sv", value));
|
generator.append(ByteString::formatted("\"{}\"sv", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.append(R"~~~( };
|
generator.append(R"~~~( };
|
||||||
|
|
|
@ -112,7 +112,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);
|
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface);
|
||||||
|
|
||||||
static DeprecatedString union_type_to_variant(UnionType const& union_type, Interface const& interface)
|
static ByteString union_type_to_variant(UnionType const& union_type, Interface const& interface)
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append("Variant<"sv);
|
builder.append("Variant<"sv);
|
||||||
|
@ -132,16 +132,16 @@ static DeprecatedString union_type_to_variant(UnionType const& union_type, Inter
|
||||||
builder.append(", Empty"sv);
|
builder.append(", Empty"sv);
|
||||||
|
|
||||||
builder.append('>');
|
builder.append('>');
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
|
CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
|
||||||
{
|
{
|
||||||
if (is_platform_object(type) || type.name() == "WindowProxy"sv)
|
if (is_platform_object(type) || type.name() == "WindowProxy"sv)
|
||||||
return { .name = DeprecatedString::formatted("JS::Handle<{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
|
return { .name = ByteString::formatted("JS::Handle<{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
|
||||||
|
|
||||||
if (is_javascript_builtin(type))
|
if (is_javascript_builtin(type))
|
||||||
return { .name = DeprecatedString::formatted("JS::Handle<JS::{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
|
return { .name = ByteString::formatted("JS::Handle<JS::{}>", type.name()), .sequence_storage_type = SequenceStorageType::MarkedVector };
|
||||||
|
|
||||||
if (interface.callback_functions.contains(type.name()))
|
if (interface.callback_functions.contains(type.name()))
|
||||||
return { .name = "JS::Handle<WebIDL::CallbackType>", .sequence_storage_type = SequenceStorageType::MarkedVector };
|
return { .name = "JS::Handle<WebIDL::CallbackType>", .sequence_storage_type = SequenceStorageType::MarkedVector };
|
||||||
|
@ -200,7 +200,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
|
||||||
if (sequence_cpp_type.sequence_storage_type == SequenceStorageType::MarkedVector)
|
if (sequence_cpp_type.sequence_storage_type == SequenceStorageType::MarkedVector)
|
||||||
return { .name = storage_type_name, .sequence_storage_type = SequenceStorageType::Vector };
|
return { .name = storage_type_name, .sequence_storage_type = SequenceStorageType::Vector };
|
||||||
|
|
||||||
return { .name = DeprecatedString::formatted("{}<{}>", storage_type_name, sequence_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
|
return { .name = ByteString::formatted("{}<{}>", storage_type_name, sequence_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.name() == "record") {
|
if (type.name() == "record") {
|
||||||
|
@ -210,7 +210,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_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);
|
auto record_value_cpp_type = idl_type_name_to_cpp_type(record_value_type, interface);
|
||||||
|
|
||||||
return { .name = DeprecatedString::formatted("OrderedHashMap<{}, {}>", record_key_cpp_type.name, record_value_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
|
return { .name = ByteString::formatted("OrderedHashMap<{}, {}>", record_key_cpp_type.name, record_value_cpp_type.name), .sequence_storage_type = SequenceStorageType::Vector };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is<UnionType>(type)) {
|
if (is<UnionType>(type)) {
|
||||||
|
@ -229,13 +229,13 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeprecatedString make_input_acceptable_cpp(DeprecatedString const& input)
|
static ByteString make_input_acceptable_cpp(ByteString const& input)
|
||||||
{
|
{
|
||||||
if (input.is_one_of("class", "template", "for", "default", "char", "namespace", "delete", "inline")) {
|
if (input.is_one_of("class", "template", "for", "default", "char", "namespace", "delete", "inline")) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(input);
|
builder.append(input);
|
||||||
builder.append('_');
|
builder.append('_');
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
return input.replace("-"sv, "_"sv, ReplaceMode::All);
|
return input.replace("-"sv, "_"sv, ReplaceMode::All);
|
||||||
|
@ -266,7 +266,7 @@ static void generate_include_for(auto& generator, auto& path)
|
||||||
}
|
}
|
||||||
|
|
||||||
LexicalPath include_path { path_string };
|
LexicalPath include_path { path_string };
|
||||||
forked_generator.set("include.path", DeprecatedString::formatted("{}/{}.h", include_path.dirname(), include_path.title()));
|
forked_generator.set("include.path", ByteString::formatted("{}/{}.h", include_path.dirname(), include_path.title()));
|
||||||
forked_generator.append(R"~~~(
|
forked_generator.append(R"~~~(
|
||||||
#include <@include.path@>
|
#include <@include.path@>
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -275,7 +275,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)
|
static void emit_includes_for_all_imports(auto& interface, auto& generator, bool is_iterator = false)
|
||||||
{
|
{
|
||||||
Queue<RemoveCVReference<decltype(interface)> const*> interfaces;
|
Queue<RemoveCVReference<decltype(interface)> const*> interfaces;
|
||||||
HashTable<DeprecatedString> paths_imported;
|
HashTable<ByteString> paths_imported;
|
||||||
|
|
||||||
interfaces.enqueue(&interface);
|
interfaces.enqueue(&interface);
|
||||||
|
|
||||||
|
@ -297,13 +297,13 @@ static void emit_includes_for_all_imports(auto& interface, auto& generator, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_iterator) {
|
if (is_iterator) {
|
||||||
auto iterator_path = DeprecatedString::formatted("{}Iterator", interface.fully_qualified_name.replace("::"sv, "/"sv, ReplaceMode::All));
|
auto iterator_path = ByteString::formatted("{}Iterator", interface.fully_qualified_name.replace("::"sv, "/"sv, ReplaceMode::All));
|
||||||
generate_include_for_iterator(generator, iterator_path);
|
generate_include_for_iterator(generator, iterator_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ParameterType>
|
template<typename ParameterType>
|
||||||
static void generate_to_string(SourceGenerator& scoped_generator, ParameterType const& parameter, bool variadic, bool optional, Optional<DeprecatedString> const& optional_default_value)
|
static void generate_to_string(SourceGenerator& scoped_generator, ParameterType const& parameter, bool variadic, bool optional, Optional<ByteString> const& optional_default_value)
|
||||||
{
|
{
|
||||||
if (variadic) {
|
if (variadic) {
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
|
@ -363,7 +363,7 @@ static void generate_to_string(SourceGenerator& scoped_generator, ParameterType
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ParameterType>
|
template<typename ParameterType>
|
||||||
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)
|
static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter, ByteString const& js_name, ByteString const& js_suffix, ByteString const& cpp_name, IDL::Interface const& interface, bool legacy_null_to_empty_string = false, bool optional = false, Optional<ByteString> optional_default_value = {}, bool variadic = false, size_t recursion_depth = 0)
|
||||||
{
|
{
|
||||||
auto scoped_generator = generator.fork();
|
auto scoped_generator = generator.fork();
|
||||||
auto acceptable_cpp_name = make_input_acceptable_cpp(cpp_name);
|
auto acceptable_cpp_name = make_input_acceptable_cpp(cpp_name);
|
||||||
|
@ -698,7 +698,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
auto default_value_cpp_name = enumeration.translated_cpp_names.get(enum_member_name);
|
auto default_value_cpp_name = enumeration.translated_cpp_names.get(enum_member_name);
|
||||||
VERIFY(default_value_cpp_name.has_value());
|
VERIFY(default_value_cpp_name.has_value());
|
||||||
enum_generator.set("enum.default.cpp_value", *default_value_cpp_name);
|
enum_generator.set("enum.default.cpp_value", *default_value_cpp_name);
|
||||||
enum_generator.set("js_name.as_string", DeprecatedString::formatted("{}{}_string", enum_generator.get("js_name"sv), enum_generator.get("js_suffix"sv)));
|
enum_generator.set("js_name.as_string", ByteString::formatted("{}{}_string", enum_generator.get("js_name"sv), enum_generator.get("js_suffix"sv)));
|
||||||
enum_generator.append(R"~~~(
|
enum_generator.append(R"~~~(
|
||||||
@parameter.type.name@ @cpp_name@ { @parameter.type.name@::@enum.default.cpp_value@ };
|
@parameter.type.name@ @cpp_name@ { @parameter.type.name@::@enum.default.cpp_value@ };
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -761,8 +761,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
for (auto& member : current_dictionary->members) {
|
for (auto& member : current_dictionary->members) {
|
||||||
dictionary_generator.set("member_key", member.name);
|
dictionary_generator.set("member_key", member.name);
|
||||||
auto member_js_name = make_input_acceptable_cpp(member.name.to_snakecase());
|
auto member_js_name = make_input_acceptable_cpp(member.name.to_snakecase());
|
||||||
auto member_value_name = DeprecatedString::formatted("{}_value_{}", member_js_name, i);
|
auto member_value_name = ByteString::formatted("{}_value_{}", member_js_name, i);
|
||||||
auto member_property_value_name = DeprecatedString::formatted("{}_property_value_{}", member_js_name, i);
|
auto member_property_value_name = ByteString::formatted("{}_property_value_{}", member_js_name, i);
|
||||||
dictionary_generator.set("member_name", member_js_name);
|
dictionary_generator.set("member_name", member_js_name);
|
||||||
dictionary_generator.set("member_value_name", member_value_name);
|
dictionary_generator.set("member_value_name", member_value_name);
|
||||||
dictionary_generator.set("member_property_value_name", member_property_value_name);
|
dictionary_generator.set("member_property_value_name", member_property_value_name);
|
||||||
|
@ -848,7 +848,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
|
|
||||||
auto sequence_generator = scoped_generator.fork();
|
auto sequence_generator = scoped_generator.fork();
|
||||||
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
|
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
|
||||||
sequence_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
|
sequence_generator.set("recursion_depth", ByteString::number(recursion_depth));
|
||||||
|
|
||||||
// An ECMAScript value V is converted to an IDL sequence<T> value as follows:
|
// An ECMAScript value V is converted to an IDL sequence<T> value as follows:
|
||||||
// 1. If Type(V) is not Object, throw a TypeError.
|
// 1. If Type(V) is not Object, throw a TypeError.
|
||||||
|
@ -900,7 +900,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());
|
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, DeprecatedString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), DeprecatedString::formatted("{}{}", js_name, js_suffix), DeprecatedString::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
|
parameterized_type.generate_sequence_from_iterable(sequence_generator, ByteString::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), ByteString::formatted("{}{}", js_name, js_suffix), ByteString::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
|
||||||
|
|
||||||
if (optional) {
|
if (optional) {
|
||||||
sequence_generator.append(R"~~~(
|
sequence_generator.append(R"~~~(
|
||||||
|
@ -913,7 +913,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
|
|
||||||
auto record_generator = scoped_generator.fork();
|
auto record_generator = scoped_generator.fork();
|
||||||
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
|
auto& parameterized_type = verify_cast<IDL::ParameterizedType>(*parameter.type);
|
||||||
record_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
|
record_generator.set("recursion_depth", ByteString::number(recursion_depth));
|
||||||
|
|
||||||
// A record can only have two types: key type and value type.
|
// A record can only have two types: key type and value type.
|
||||||
VERIFY(parameterized_type.parameters().size() == 2);
|
VERIFY(parameterized_type.parameters().size() == 2);
|
||||||
|
@ -963,7 +963,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 = {} };
|
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", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("typed_key{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
|
generate_to_cpp(record_generator, key_parameter, "key", ByteString::number(recursion_depth), ByteString::formatted("typed_key{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
|
||||||
|
|
||||||
record_generator.append(R"~~~(
|
record_generator.append(R"~~~(
|
||||||
auto value@recursion_depth@ = TRY(@js_name@@js_suffix@_object.get(property_key@recursion_depth@));
|
auto value@recursion_depth@ = TRY(@js_name@@js_suffix@_object.get(property_key@recursion_depth@));
|
||||||
|
@ -971,7 +971,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.
|
// 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 = {} };
|
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", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("typed_value{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
|
generate_to_cpp(record_generator, value_parameter, "value", ByteString::number(recursion_depth), ByteString::formatted("typed_value{}", recursion_depth), interface, false, false, {}, false, recursion_depth + 1);
|
||||||
|
|
||||||
record_generator.append(R"~~~(
|
record_generator.append(R"~~~(
|
||||||
@cpp_name@.set(typed_key@recursion_depth@, typed_value@recursion_depth@);
|
@cpp_name@.set(typed_key@recursion_depth@, typed_value@recursion_depth@);
|
||||||
|
@ -984,7 +984,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
|
|
||||||
auto& union_type = verify_cast<IDL::UnionType>(*parameter.type);
|
auto& union_type = verify_cast<IDL::UnionType>(*parameter.type);
|
||||||
union_generator.set("union_type", union_type_to_variant(union_type, interface));
|
union_generator.set("union_type", union_type_to_variant(union_type, interface));
|
||||||
union_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
|
union_generator.set("recursion_depth", ByteString::number(recursion_depth));
|
||||||
|
|
||||||
// NOTE: This is handled out here as we need the dictionary conversion code for the {} optional default value.
|
// 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.
|
// 3. Let types be the flattened member types of the union type.
|
||||||
|
@ -1036,9 +1036,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
to_variant_captures.append("&vm, &realm"sv);
|
to_variant_captures.append("&vm, &realm"sv);
|
||||||
|
|
||||||
if (dictionary_type)
|
if (dictionary_type)
|
||||||
to_variant_captures.append(DeprecatedString::formatted(", &{}{}_to_dictionary", js_name, js_suffix));
|
to_variant_captures.append(ByteString::formatted(", &{}{}_to_dictionary", js_name, js_suffix));
|
||||||
|
|
||||||
union_generator.set("to_variant_captures", to_variant_captures.to_deprecated_string());
|
union_generator.set("to_variant_captures", to_variant_captures.to_byte_string());
|
||||||
|
|
||||||
union_generator.append(R"~~~(
|
union_generator.append(R"~~~(
|
||||||
auto @js_name@@js_suffix@_to_variant = [@to_variant_captures@](JS::Value @js_name@@js_suffix@) -> JS::ThrowCompletionOr<@union_type@> {
|
auto @js_name@@js_suffix@_to_variant = [@to_variant_captures@](JS::Value @js_name@@js_suffix@) -> JS::ThrowCompletionOr<@union_type@> {
|
||||||
|
@ -1211,7 +1211,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
if (method) {
|
if (method) {
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
sequence_type->generate_sequence_from_iterable(union_generator, acceptable_cpp_name, DeprecatedString::formatted("{}{}", js_name, js_suffix), "method", interface, recursion_depth + 1);
|
sequence_type->generate_sequence_from_iterable(union_generator, acceptable_cpp_name, ByteString::formatted("{}{}", js_name, js_suffix), "method", interface, recursion_depth + 1);
|
||||||
|
|
||||||
union_generator.append(R"~~~(
|
union_generator.append(R"~~~(
|
||||||
|
|
||||||
|
@ -1296,8 +1296,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
)~~~");
|
)~~~");
|
||||||
// NOTE: generate_to_cpp doesn't use the parameter name.
|
// 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.
|
// 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 = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
|
IDL::Parameter parameter { .type = *numeric_type, .name = ByteString::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);
|
generate_to_cpp(union_generator, parameter, js_name, js_suffix, ByteString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
|
||||||
|
|
||||||
union_generator.append(R"~~~(
|
union_generator.append(R"~~~(
|
||||||
return { @js_name@@js_suffix@_number };
|
return { @js_name@@js_suffix@_number };
|
||||||
|
@ -1361,8 +1361,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
|
|
||||||
// NOTE: generate_to_cpp doesn't use the parameter name.
|
// 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.
|
// 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 = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
|
IDL::Parameter parameter { .type = *numeric_type, .name = ByteString::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);
|
generate_to_cpp(union_numeric_type_generator, parameter, "x", ByteString::empty(), "x_number", interface, false, false, {}, false, recursion_depth + 1);
|
||||||
|
|
||||||
union_numeric_type_generator.append(R"~~~(
|
union_numeric_type_generator.append(R"~~~(
|
||||||
return x_number;
|
return x_number;
|
||||||
|
@ -1372,8 +1372,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
|
|
||||||
// NOTE: generate_to_cpp doesn't use the parameter name.
|
// 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.
|
// 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 = DeprecatedString::empty(), .optional_default_value = {}, .extended_attributes = {} };
|
IDL::Parameter parameter { .type = *numeric_type, .name = ByteString::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);
|
generate_to_cpp(union_generator, parameter, js_name, js_suffix, ByteString::formatted("{}{}_number", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1);
|
||||||
|
|
||||||
union_generator.append(R"~~~(
|
union_generator.append(R"~~~(
|
||||||
return { @js_name@@js_suffix@_number };
|
return { @js_name@@js_suffix@_number };
|
||||||
|
@ -1457,21 +1457,21 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void generate_argument_count_check(SourceGenerator& generator, DeprecatedString const& function_name, size_t argument_count)
|
static void generate_argument_count_check(SourceGenerator& generator, ByteString const& function_name, size_t argument_count)
|
||||||
{
|
{
|
||||||
if (argument_count == 0)
|
if (argument_count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto argument_count_check_generator = generator.fork();
|
auto argument_count_check_generator = generator.fork();
|
||||||
argument_count_check_generator.set("function.name", function_name);
|
argument_count_check_generator.set("function.name", function_name);
|
||||||
argument_count_check_generator.set("function.nargs", DeprecatedString::number(argument_count));
|
argument_count_check_generator.set("function.nargs", ByteString::number(argument_count));
|
||||||
|
|
||||||
if (argument_count == 1) {
|
if (argument_count == 1) {
|
||||||
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountOne");
|
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountOne");
|
||||||
argument_count_check_generator.set(".arg_count_suffix", "");
|
argument_count_check_generator.set(".arg_count_suffix", "");
|
||||||
} else {
|
} else {
|
||||||
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountMany");
|
argument_count_check_generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountMany");
|
||||||
argument_count_check_generator.set(".arg_count_suffix", DeprecatedString::formatted(", \"{}\"", argument_count));
|
argument_count_check_generator.set(".arg_count_suffix", ByteString::formatted(", \"{}\"", argument_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
argument_count_check_generator.append(R"~~~(
|
argument_count_check_generator.append(R"~~~(
|
||||||
|
@ -1484,7 +1484,7 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
|
||||||
{
|
{
|
||||||
auto arguments_generator = generator.fork();
|
auto arguments_generator = generator.fork();
|
||||||
|
|
||||||
Vector<DeprecatedString> parameter_names;
|
Vector<ByteString> parameter_names;
|
||||||
size_t argument_index = 0;
|
size_t argument_index = 0;
|
||||||
for (auto& parameter : parameters) {
|
for (auto& parameter : parameters) {
|
||||||
auto parameter_name = make_input_acceptable_cpp(parameter.name.to_snakecase());
|
auto parameter_name = make_input_acceptable_cpp(parameter.name.to_snakecase());
|
||||||
|
@ -1492,18 +1492,18 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
|
||||||
if (parameter.variadic) {
|
if (parameter.variadic) {
|
||||||
// JS::MarkedVector is non-copyable, and the implementations likely want ownership of the
|
// JS::MarkedVector is non-copyable, and the implementations likely want ownership of the
|
||||||
// list, so we move() it into the parameter list.
|
// list, so we move() it into the parameter list.
|
||||||
parameter_names.append(DeprecatedString::formatted("move({})", parameter_name));
|
parameter_names.append(ByteString::formatted("move({})", parameter_name));
|
||||||
} else {
|
} else {
|
||||||
parameter_names.append(move(parameter_name));
|
parameter_names.append(move(parameter_name));
|
||||||
|
|
||||||
arguments_generator.set("argument.index", DeprecatedString::number(argument_index));
|
arguments_generator.set("argument.index", ByteString::number(argument_index));
|
||||||
arguments_generator.append(R"~~~(
|
arguments_generator.append(R"~~~(
|
||||||
auto arg@argument.index@ = vm.argument(@argument.index@);
|
auto arg@argument.index@ = vm.argument(@argument.index@);
|
||||||
)~~~");
|
)~~~");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool legacy_null_to_empty_string = parameter.extended_attributes.contains("LegacyNullToEmptyString");
|
bool legacy_null_to_empty_string = parameter.extended_attributes.contains("LegacyNullToEmptyString");
|
||||||
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);
|
generate_to_cpp(generator, parameter, "arg", ByteString::number(argument_index), parameter.name.to_snakecase(), interface, legacy_null_to_empty_string, parameter.optional, parameter.optional_default_value, parameter.variadic, 0);
|
||||||
++argument_index;
|
++argument_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1511,13 +1511,13 @@ static void generate_arguments(SourceGenerator& generator, Vector<IDL::Parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://webidl.spec.whatwg.org/#create-sequence-from-iterable
|
// https://webidl.spec.whatwg.org/#create-sequence-from-iterable
|
||||||
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
|
void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& generator, ByteString const& cpp_name, ByteString const& iterable_cpp_name, ByteString const& iterator_method_cpp_name, IDL::Interface const& interface, size_t recursion_depth) const
|
||||||
{
|
{
|
||||||
auto sequence_generator = generator.fork();
|
auto sequence_generator = generator.fork();
|
||||||
sequence_generator.set("cpp_name", cpp_name);
|
sequence_generator.set("cpp_name", cpp_name);
|
||||||
sequence_generator.set("iterable_cpp_name", iterable_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("iterator_method_cpp_name", iterator_method_cpp_name);
|
||||||
sequence_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
|
sequence_generator.set("recursion_depth", ByteString::number(recursion_depth));
|
||||||
auto sequence_cpp_type = idl_type_name_to_cpp_type(parameters().first(), interface);
|
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.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));
|
sequence_generator.set("sequence.storage_type", sequence_storage_type_to_cpp_storage_type_name(sequence_cpp_type.sequence_storage_type));
|
||||||
|
@ -1558,7 +1558,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge
|
||||||
|
|
||||||
// FIXME: Sequences types should be TypeWithExtendedAttributes, which would allow us to get [LegacyNullToEmptyString] here.
|
// 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 = {} };
|
IDL::Parameter parameter { .type = parameters().first(), .name = iterable_cpp_name, .optional_default_value = {}, .extended_attributes = {} };
|
||||||
generate_to_cpp(sequence_generator, parameter, "next_item", DeprecatedString::number(recursion_depth), DeprecatedString::formatted("sequence_item{}", recursion_depth), interface, false, false, {}, false, recursion_depth);
|
generate_to_cpp(sequence_generator, parameter, "next_item", ByteString::number(recursion_depth), ByteString::formatted("sequence_item{}", recursion_depth), interface, false, false, {}, false, recursion_depth);
|
||||||
|
|
||||||
sequence_generator.append(R"~~~(
|
sequence_generator.append(R"~~~(
|
||||||
@cpp_name@.append(sequence_item@recursion_depth@);
|
@cpp_name@.append(sequence_item@recursion_depth@);
|
||||||
|
@ -1571,13 +1571,13 @@ enum class WrappingReference {
|
||||||
Yes,
|
Yes,
|
||||||
};
|
};
|
||||||
|
|
||||||
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)
|
static void generate_wrap_statement(SourceGenerator& generator, ByteString 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();
|
auto scoped_generator = generator.fork();
|
||||||
scoped_generator.set("value", value);
|
scoped_generator.set("value", value);
|
||||||
if (!libweb_interface_namespaces.span().contains_slow(type.name())) {
|
if (!libweb_interface_namespaces.span().contains_slow(type.name())) {
|
||||||
if (is_javascript_builtin(type))
|
if (is_javascript_builtin(type))
|
||||||
scoped_generator.set("type", DeprecatedString::formatted("JS::{}", type.name()));
|
scoped_generator.set("type", ByteString::formatted("JS::{}", type.name()));
|
||||||
else
|
else
|
||||||
scoped_generator.set("type", type.name());
|
scoped_generator.set("type", type.name());
|
||||||
} else {
|
} else {
|
||||||
|
@ -1586,10 +1586,10 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
||||||
builder.append(type.name());
|
builder.append(type.name());
|
||||||
builder.append("::"sv);
|
builder.append("::"sv);
|
||||||
builder.append(type.name());
|
builder.append(type.name());
|
||||||
scoped_generator.set("type", builder.to_deprecated_string());
|
scoped_generator.set("type", builder.to_byte_string());
|
||||||
}
|
}
|
||||||
scoped_generator.set("result_expression", result_expression);
|
scoped_generator.set("result_expression", result_expression);
|
||||||
scoped_generator.set("recursion_depth", DeprecatedString::number(recursion_depth));
|
scoped_generator.set("recursion_depth", ByteString::number(recursion_depth));
|
||||||
|
|
||||||
if (type.name() == "undefined") {
|
if (type.name() == "undefined") {
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
|
@ -1665,7 +1665,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
||||||
auto* wrapped_element@recursion_depth@ = &(*element@recursion_depth@);
|
auto* wrapped_element@recursion_depth@ = &(*element@recursion_depth@);
|
||||||
)~~~");
|
)~~~");
|
||||||
} else {
|
} else {
|
||||||
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);
|
generate_wrap_statement(scoped_generator, ByteString::formatted("element{}", recursion_depth), sequence_generic_type.parameters().first(), interface, ByteString::formatted("auto wrapped_element{} =", recursion_depth), WrappingReference::Yes, recursion_depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
|
@ -1730,7 +1730,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
// NOTE: While we are using const&, the underlying type for wrappable types in unions is (Nonnull)RefPtr, which are not references.
|
// 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, DeprecatedString::formatted("visited_union_value{}", recursion_depth), current_union_type, interface, "return"sv, WrappingReference::No, recursion_depth + 1);
|
generate_wrap_statement(union_generator, ByteString::formatted("visited_union_value{}", recursion_depth), current_union_type, interface, "return"sv, WrappingReference::No, recursion_depth + 1);
|
||||||
|
|
||||||
// End of current visit lambda.
|
// 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.
|
// 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.
|
||||||
|
@ -1760,7 +1760,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
||||||
} else if (interface.enumerations.contains(type.name())) {
|
} else if (interface.enumerations.contains(type.name())) {
|
||||||
// Handle Enum? values, which were null-checked above
|
// Handle Enum? values, which were null-checked above
|
||||||
if (type.is_nullable())
|
if (type.is_nullable())
|
||||||
scoped_generator.set("value", DeprecatedString::formatted("{}.value()", value));
|
scoped_generator.set("value", ByteString::formatted("{}.value()", value));
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
@result_expression@ JS::PrimitiveString::create(vm, Bindings::idl_enum_to_string(@value@));
|
@result_expression@ JS::PrimitiveString::create(vm, Bindings::idl_enum_to_string(@value@));
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -1796,18 +1796,18 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
||||||
while (true) {
|
while (true) {
|
||||||
for (auto& member : current_dictionary->members) {
|
for (auto& member : current_dictionary->members) {
|
||||||
dictionary_generator.set("member_key", member.name);
|
dictionary_generator.set("member_key", member.name);
|
||||||
auto member_key_js_name = DeprecatedString::formatted("{}{}", make_input_acceptable_cpp(member.name.to_snakecase()), recursion_depth);
|
auto member_key_js_name = ByteString::formatted("{}{}", make_input_acceptable_cpp(member.name.to_snakecase()), recursion_depth);
|
||||||
dictionary_generator.set("member_name", member_key_js_name);
|
dictionary_generator.set("member_name", member_key_js_name);
|
||||||
auto member_value_js_name = DeprecatedString::formatted("{}_value", member_key_js_name);
|
auto member_value_js_name = ByteString::formatted("{}_value", member_key_js_name);
|
||||||
dictionary_generator.set("member_value", member_value_js_name);
|
dictionary_generator.set("member_value", member_value_js_name);
|
||||||
|
|
||||||
auto wrapped_value_name = DeprecatedString::formatted("wrapped_{}", member_value_js_name);
|
auto wrapped_value_name = ByteString::formatted("wrapped_{}", member_value_js_name);
|
||||||
dictionary_generator.set("wrapped_value_name", wrapped_value_name);
|
dictionary_generator.set("wrapped_value_name", wrapped_value_name);
|
||||||
|
|
||||||
dictionary_generator.append(R"~~~(
|
dictionary_generator.append(R"~~~(
|
||||||
JS::Value @wrapped_value_name@;
|
JS::Value @wrapped_value_name@;
|
||||||
)~~~");
|
)~~~");
|
||||||
generate_wrap_statement(dictionary_generator, DeprecatedString::formatted("{}.{}", value, member.name.to_snakecase()), member.type, interface, DeprecatedString::formatted("{} =", wrapped_value_name), WrappingReference::No, recursion_depth + 1);
|
generate_wrap_statement(dictionary_generator, ByteString::formatted("{}.{}", value, member.name.to_snakecase()), member.type, interface, ByteString::formatted("{} =", wrapped_value_name), WrappingReference::No, recursion_depth + 1);
|
||||||
|
|
||||||
dictionary_generator.append(R"~~~(
|
dictionary_generator.append(R"~~~(
|
||||||
MUST(dictionary_object@recursion_depth@->create_data_property("@member_key@", @wrapped_value_name@));
|
MUST(dictionary_object@recursion_depth@->create_data_property("@member_key@", @wrapped_value_name@));
|
||||||
|
@ -1856,23 +1856,23 @@ static void generate_return_statement(SourceGenerator& generator, IDL::Type cons
|
||||||
return generate_wrap_statement(generator, "retval", return_type, interface, "return"sv);
|
return generate_wrap_statement(generator, "retval", return_type, interface, "return"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void generate_variable_statement(SourceGenerator& generator, DeprecatedString const& variable_name, IDL::Type const& value_type, DeprecatedString const& value_name, IDL::Interface const& interface)
|
static void generate_variable_statement(SourceGenerator& generator, ByteString const& variable_name, IDL::Type const& value_type, ByteString const& value_name, IDL::Interface const& interface)
|
||||||
{
|
{
|
||||||
auto variable_generator = generator.fork();
|
auto variable_generator = generator.fork();
|
||||||
variable_generator.set("variable_name", variable_name);
|
variable_generator.set("variable_name", variable_name);
|
||||||
variable_generator.append(R"~~~(
|
variable_generator.append(R"~~~(
|
||||||
JS::Value @variable_name@;
|
JS::Value @variable_name@;
|
||||||
)~~~");
|
)~~~");
|
||||||
return generate_wrap_statement(generator, value_name, value_type, interface, DeprecatedString::formatted("{} = ", variable_name));
|
return generate_wrap_statement(generator, value_name, value_type, interface, ByteString::formatted("{} = ", variable_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
static void generate_function(SourceGenerator& generator, IDL::Function const& function, StaticFunction is_static_function, ByteString const& class_name, ByteString const& interface_fully_qualified_name, IDL::Interface const& interface)
|
||||||
{
|
{
|
||||||
auto function_generator = generator.fork();
|
auto function_generator = generator.fork();
|
||||||
function_generator.set("class_name", class_name);
|
function_generator.set("class_name", class_name);
|
||||||
function_generator.set("interface_fully_qualified_name", interface_fully_qualified_name);
|
function_generator.set("interface_fully_qualified_name", interface_fully_qualified_name);
|
||||||
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(function.name.to_snakecase()));
|
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(function.name.to_snakecase()));
|
||||||
function_generator.set("overload_suffix", function.is_overloaded ? DeprecatedString::number(function.overload_index) : DeprecatedString::empty());
|
function_generator.set("overload_suffix", function.is_overloaded ? ByteString::number(function.overload_index) : ByteString::empty());
|
||||||
|
|
||||||
if (function.extended_attributes.contains("ImplementedAs")) {
|
if (function.extended_attributes.contains("ImplementedAs")) {
|
||||||
auto implemented_as = function.extended_attributes.get("ImplementedAs").value();
|
auto implemented_as = function.extended_attributes.get("ImplementedAs").value();
|
||||||
|
@ -1941,7 +1941,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@@overload_suffi
|
||||||
if (arguments_builder.is_empty())
|
if (arguments_builder.is_empty())
|
||||||
function_generator.set(".arguments", "vm");
|
function_generator.set(".arguments", "vm");
|
||||||
else
|
else
|
||||||
function_generator.set(".arguments", DeprecatedString::formatted("vm, {}", arguments_builder.string_view()));
|
function_generator.set(".arguments", ByteString::formatted("vm, {}", arguments_builder.string_view()));
|
||||||
|
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
[[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return @interface_fully_qualified_name@::@function.cpp_name@(@.arguments@); }));
|
[[maybe_unused]] auto retval = TRY(throw_dom_exception_if_needed(vm, [&] { return @interface_fully_qualified_name@::@function.cpp_name@(@.arguments@); }));
|
||||||
|
@ -2082,7 +2082,7 @@ static Vector<EffectiveOverloadSet::Item> compute_the_effective_overload_set(aut
|
||||||
return overloads;
|
return overloads;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeprecatedString generate_constructor_for_idl_type(Type const& type)
|
static ByteString generate_constructor_for_idl_type(Type const& type)
|
||||||
{
|
{
|
||||||
auto append_type_list = [](auto& builder, auto const& type_list) {
|
auto append_type_list = [](auto& builder, auto const& type_list) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
@ -2099,14 +2099,14 @@ static DeprecatedString generate_constructor_for_idl_type(Type const& type)
|
||||||
|
|
||||||
switch (type.kind()) {
|
switch (type.kind()) {
|
||||||
case Type::Kind::Plain:
|
case Type::Kind::Plain:
|
||||||
return DeprecatedString::formatted("make_ref_counted<IDL::Type>(\"{}\", {})", type.name(), type.is_nullable());
|
return ByteString::formatted("make_ref_counted<IDL::Type>(\"{}\", {})", type.name(), type.is_nullable());
|
||||||
case Type::Kind::Parameterized: {
|
case Type::Kind::Parameterized: {
|
||||||
auto const& parameterized_type = type.as_parameterized();
|
auto const& parameterized_type = type.as_parameterized();
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.appendff("make_ref_counted<IDL::ParameterizedType>(\"{}\", {}, Vector<NonnullRefPtr<IDL::Type const>> {{", type.name(), type.is_nullable());
|
builder.appendff("make_ref_counted<IDL::ParameterizedType>(\"{}\", {}, Vector<NonnullRefPtr<IDL::Type const>> {{", type.name(), type.is_nullable());
|
||||||
append_type_list(builder, parameterized_type.parameters());
|
append_type_list(builder, parameterized_type.parameters());
|
||||||
builder.append("})"sv);
|
builder.append("})"sv);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
case Type::Kind::Union: {
|
case Type::Kind::Union: {
|
||||||
auto const& union_type = type.as_union();
|
auto const& union_type = type.as_union();
|
||||||
|
@ -2114,7 +2114,7 @@ static DeprecatedString generate_constructor_for_idl_type(Type const& type)
|
||||||
builder.appendff("make_ref_counted<IDL::UnionType>(\"{}\", {}, Vector<NonnullRefPtr<IDL::Type const>> {{", type.name(), type.is_nullable());
|
builder.appendff("make_ref_counted<IDL::UnionType>(\"{}\", {}, Vector<NonnullRefPtr<IDL::Type const>> {{", type.name(), type.is_nullable());
|
||||||
append_type_list(builder, union_type.member_types());
|
append_type_list(builder, union_type.member_types());
|
||||||
builder.append("})"sv);
|
builder.append("})"sv);
|
||||||
return builder.to_deprecated_string();
|
return builder.to_byte_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2145,7 +2145,7 @@ static size_t resolve_distinguishing_argument_index(Interface const& interface,
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, IDL::Interface const& interface, DeprecatedString const& class_name)
|
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, IDL::Interface const& interface, ByteString const& class_name)
|
||||||
{
|
{
|
||||||
auto function_generator = generator.fork();
|
auto function_generator = generator.fork();
|
||||||
function_generator.set("class_name", class_name);
|
function_generator.set("class_name", class_name);
|
||||||
|
@ -2161,7 +2161,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
|
||||||
auto maximum_argument_count = 0u;
|
auto maximum_argument_count = 0u;
|
||||||
for (auto const& overload : overloads_set)
|
for (auto const& overload : overloads_set)
|
||||||
maximum_argument_count = max(maximum_argument_count, overload.types.size());
|
maximum_argument_count = max(maximum_argument_count, overload.types.size());
|
||||||
function_generator.set("max_argument_count", DeprecatedString::number(maximum_argument_count));
|
function_generator.set("max_argument_count", ByteString::number(maximum_argument_count));
|
||||||
function_generator.appendln(" switch (min(@max_argument_count@, vm.argument_count())) {");
|
function_generator.appendln(" switch (min(@max_argument_count@, vm.argument_count())) {");
|
||||||
|
|
||||||
// Generate the effective overload set for each argument count.
|
// Generate the effective overload set for each argument count.
|
||||||
|
@ -2182,8 +2182,8 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
|
||||||
if (effective_overload_set.size() > 1)
|
if (effective_overload_set.size() > 1)
|
||||||
distinguishing_argument_index = resolve_distinguishing_argument_index(interface, effective_overload_set, argument_count);
|
distinguishing_argument_index = resolve_distinguishing_argument_index(interface, effective_overload_set, argument_count);
|
||||||
|
|
||||||
function_generator.set("current_argument_count", DeprecatedString::number(argument_count));
|
function_generator.set("current_argument_count", ByteString::number(argument_count));
|
||||||
function_generator.set("overload_count", DeprecatedString::number(effective_overload_set.size()));
|
function_generator.set("overload_count", ByteString::number(effective_overload_set.size()));
|
||||||
function_generator.appendln(R"~~~(
|
function_generator.appendln(R"~~~(
|
||||||
case @current_argument_count@: {
|
case @current_argument_count@: {
|
||||||
Vector<IDL::EffectiveOverloadSet::Item> overloads;
|
Vector<IDL::EffectiveOverloadSet::Item> overloads;
|
||||||
|
@ -2221,14 +2221,14 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
|
||||||
types_builder.append("}"sv);
|
types_builder.append("}"sv);
|
||||||
optionality_builder.append("}"sv);
|
optionality_builder.append("}"sv);
|
||||||
|
|
||||||
function_generator.set("overload.callable_id", DeprecatedString::number(overload.callable_id));
|
function_generator.set("overload.callable_id", ByteString::number(overload.callable_id));
|
||||||
function_generator.set("overload.types", types_builder.to_deprecated_string());
|
function_generator.set("overload.types", types_builder.to_byte_string());
|
||||||
function_generator.set("overload.optionality_values", optionality_builder.to_deprecated_string());
|
function_generator.set("overload.optionality_values", optionality_builder.to_byte_string());
|
||||||
|
|
||||||
function_generator.appendln(" overloads.empend(@overload.callable_id@, @overload.types@, @overload.optionality_values@);");
|
function_generator.appendln(" overloads.empend(@overload.callable_id@, @overload.types@, @overload.optionality_values@);");
|
||||||
}
|
}
|
||||||
|
|
||||||
function_generator.set("overload_set.distinguishing_argument_index", DeprecatedString::number(distinguishing_argument_index));
|
function_generator.set("overload_set.distinguishing_argument_index", ByteString::number(distinguishing_argument_index));
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
effective_overload_set.emplace(move(overloads), @overload_set.distinguishing_argument_index@);
|
effective_overload_set.emplace(move(overloads), @overload_set.distinguishing_argument_index@);
|
||||||
break;
|
break;
|
||||||
|
@ -2247,7 +2247,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
||||||
function_generator.set("overload_id", DeprecatedString::number(i));
|
function_generator.set("overload_id", ByteString::number(i));
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
case @overload_id@:
|
case @overload_id@:
|
||||||
return @function.name:snakecase@@overload_id@(vm);
|
return @function.name:snakecase@@overload_id@(vm);
|
||||||
|
@ -2274,7 +2274,7 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const
|
||||||
)~~~");
|
)~~~");
|
||||||
if (overload_set.value.size() > 1) {
|
if (overload_set.value.size() > 1) {
|
||||||
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
||||||
function_generator.set("overload_suffix", DeprecatedString::number(i));
|
function_generator.set("overload_suffix", ByteString::number(i));
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
|
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -2420,7 +2420,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto attribute_generator = function_generator.fork();
|
auto attribute_generator = function_generator.fork();
|
||||||
auto return_value_name = DeprecatedString::formatted("{}_retval", attribute.name.to_snakecase());
|
auto return_value_name = ByteString::formatted("{}_retval", attribute.name.to_snakecase());
|
||||||
|
|
||||||
attribute_generator.set("attribute.name", attribute.name);
|
attribute_generator.set("attribute.name", attribute.name);
|
||||||
attribute_generator.set("attribute.return_value_name", return_value_name);
|
attribute_generator.set("attribute.return_value_name", return_value_name);
|
||||||
|
@ -2466,7 +2466,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
|
||||||
)~~~");
|
)~~~");
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_wrap_statement(attribute_generator, return_value_name, attribute.type, interface_in_chain, DeprecatedString::formatted("auto {}_wrapped =", return_value_name));
|
generate_wrap_statement(attribute_generator, return_value_name, attribute.type, interface_in_chain, ByteString::formatted("auto {}_wrapped =", return_value_name));
|
||||||
|
|
||||||
attribute_generator.append(R"~~~(
|
attribute_generator.append(R"~~~(
|
||||||
MUST(result->create_data_property("@attribute.name@", @attribute.return_value_name@_wrapped));
|
MUST(result->create_data_property("@attribute.name@", @attribute.return_value_name@_wrapped));
|
||||||
|
@ -2477,7 +2477,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
|
||||||
auto constant_generator = function_generator.fork();
|
auto constant_generator = function_generator.fork();
|
||||||
constant_generator.set("constant.name", constant.name);
|
constant_generator.set("constant.name", constant.name);
|
||||||
|
|
||||||
generate_wrap_statement(constant_generator, constant.value, constant.type, interface_in_chain, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
|
generate_wrap_statement(constant_generator, constant.value, constant.type, interface_in_chain, ByteString::formatted("auto constant_{}_value =", constant.name));
|
||||||
|
|
||||||
constant_generator.append(R"~~~(
|
constant_generator.append(R"~~~(
|
||||||
MUST(result->create_data_property("@constant.name@", constant_@constant.name@_value));
|
MUST(result->create_data_property("@constant.name@", constant_@constant.name@_value));
|
||||||
|
@ -2487,7 +2487,7 @@ static void collect_attribute_values_of_an_inheritance_stack(SourceGenerator& fu
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://webidl.spec.whatwg.org/#default-tojson-steps
|
// https://webidl.spec.whatwg.org/#default-tojson-steps
|
||||||
static void generate_default_to_json_function(SourceGenerator& generator, DeprecatedString const& class_name, IDL::Interface const& start_interface)
|
static void generate_default_to_json_function(SourceGenerator& generator, ByteString const& class_name, IDL::Interface const& start_interface)
|
||||||
{
|
{
|
||||||
// NOTE: This is done heavily out of order since the spec mixes parse time and run time type information together.
|
// NOTE: This is done heavily out of order since the spec mixes parse time and run time type information together.
|
||||||
|
|
||||||
|
@ -2526,7 +2526,7 @@ static void generate_named_properties_object_declarations(IDL::Interface const&
|
||||||
{
|
{
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
|
|
||||||
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
|
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
class @named_properties_class@ : public JS::Object {
|
class @named_properties_class@ : public JS::Object {
|
||||||
|
@ -2557,7 +2557,7 @@ static void generate_named_properties_object_definitions(IDL::Interface const& i
|
||||||
generator.set("name", interface.name);
|
generator.set("name", interface.name);
|
||||||
generator.set("parent_name", interface.parent_name);
|
generator.set("parent_name", interface.parent_name);
|
||||||
generator.set("prototype_base_class", interface.prototype_base_class);
|
generator.set("prototype_base_class", interface.prototype_base_class);
|
||||||
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
|
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
|
||||||
|
|
||||||
// https://webidl.spec.whatwg.org/#create-a-named-properties-object
|
// https://webidl.spec.whatwg.org/#create-a-named-properties-object
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
|
@ -2701,11 +2701,11 @@ static void generate_prototype_or_global_mixin_definitions(IDL::Interface const&
|
||||||
generator.set("prototype_name", interface.prototype_class); // Used for Global Mixin
|
generator.set("prototype_name", interface.prototype_class); // Used for Global Mixin
|
||||||
|
|
||||||
if (interface.pair_iterator_types.has_value()) {
|
if (interface.pair_iterator_types.has_value()) {
|
||||||
generator.set("iterator_name", DeprecatedString::formatted("{}Iterator", interface.name));
|
generator.set("iterator_name", ByteString::formatted("{}Iterator", interface.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_global_interface) {
|
if (is_global_interface) {
|
||||||
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
|
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
|
||||||
// Doing this with macros is not super nice, but simplifies codegen a lot.
|
// Doing this with macros is not super nice, but simplifies codegen a lot.
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#define define_direct_property (object.define_direct_property)
|
#define define_direct_property (object.define_direct_property)
|
||||||
|
@ -2785,7 +2785,7 @@ void @class_name@::initialize(JS::Realm& realm)
|
||||||
auto constant_generator = generator.fork();
|
auto constant_generator = generator.fork();
|
||||||
constant_generator.set("constant.name", constant.name);
|
constant_generator.set("constant.name", constant.name);
|
||||||
|
|
||||||
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
|
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, ByteString::formatted("auto constant_{}_value =", constant.name));
|
||||||
|
|
||||||
constant_generator.append(R"~~~(
|
constant_generator.append(R"~~~(
|
||||||
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
|
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
|
||||||
|
@ -2797,7 +2797,7 @@ void @class_name@::initialize(JS::Realm& realm)
|
||||||
auto function_generator = generator.fork();
|
auto function_generator = generator.fork();
|
||||||
function_generator.set("function.name", overload_set.key);
|
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.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
|
||||||
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
|
function_generator.set("function.length", ByteString::number(get_shortest_function_length(overload_set.value)));
|
||||||
|
|
||||||
// FIXME: What if only some of the overloads are Unscopable?
|
// 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"); })) {
|
if (any_of(overload_set.value, [](auto const& function) { return function.extended_attributes.contains("Unscopable"); })) {
|
||||||
|
@ -3351,7 +3351,7 @@ private:
|
||||||
)~~~");
|
)~~~");
|
||||||
if (overload_set.value.size() > 1) {
|
if (overload_set.value.size() > 1) {
|
||||||
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
||||||
function_generator.set("overload_suffix", DeprecatedString::number(i));
|
function_generator.set("overload_suffix", ByteString::number(i));
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
|
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -3451,7 +3451,7 @@ void @namespace_class@::initialize(JS::Realm& realm)
|
||||||
auto function_generator = generator.fork();
|
auto function_generator = generator.fork();
|
||||||
function_generator.set("function.name", overload_set.key);
|
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.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
|
||||||
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
|
function_generator.set("function.length", ByteString::number(get_shortest_function_length(overload_set.value)));
|
||||||
|
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
|
define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
|
||||||
|
@ -3521,7 +3521,7 @@ private:
|
||||||
)~~~");
|
)~~~");
|
||||||
if (overload_set.value.size() > 1) {
|
if (overload_set.value.size() > 1) {
|
||||||
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
for (auto i = 0u; i < overload_set.value.size(); ++i) {
|
||||||
function_generator.set("overload_suffix", DeprecatedString::number(i));
|
function_generator.set("overload_suffix", ByteString::number(i));
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
|
JS_DECLARE_NATIVE_FUNCTION(@function.name:snakecase@@overload_suffix@);
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -3694,7 +3694,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> @constructor_class@::constru
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.set("constructor.length", DeprecatedString::number(shortest_length));
|
generator.set("constructor.length", ByteString::number(shortest_length));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
|
@ -3778,7 +3778,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> @constructor_class@::constru
|
||||||
generator.set(".arg_count_suffix", "");
|
generator.set(".arg_count_suffix", "");
|
||||||
} else {
|
} else {
|
||||||
generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountMany");
|
generator.set(".bad_arg_count", "JS::ErrorType::BadArgCountMany");
|
||||||
generator.set(".arg_count_suffix", DeprecatedString::formatted(", \"{}\"", shortest_length));
|
generator.set(".arg_count_suffix", ByteString::formatted(", \"{}\"", shortest_length));
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
|
@ -3943,7 +3943,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
|
||||||
auto constant_generator = generator.fork();
|
auto constant_generator = generator.fork();
|
||||||
constant_generator.set("constant.name", constant.name);
|
constant_generator.set("constant.name", constant.name);
|
||||||
|
|
||||||
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, DeprecatedString::formatted("auto constant_{}_value =", constant.name));
|
generate_wrap_statement(constant_generator, constant.value, constant.type, interface, ByteString::formatted("auto constant_{}_value =", constant.name));
|
||||||
|
|
||||||
constant_generator.append(R"~~~(
|
constant_generator.append(R"~~~(
|
||||||
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
|
define_direct_property("@constant.name@", constant_@constant.name@_value, JS::Attribute::Enumerable);
|
||||||
|
@ -3955,7 +3955,7 @@ void @constructor_class@::initialize(JS::Realm& realm)
|
||||||
auto function_generator = generator.fork();
|
auto function_generator = generator.fork();
|
||||||
function_generator.set("function.name", overload_set.key);
|
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.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
|
||||||
function_generator.set("function.length", DeprecatedString::number(get_shortest_function_length(overload_set.value)));
|
function_generator.set("function.length", ByteString::number(get_shortest_function_length(overload_set.value)));
|
||||||
|
|
||||||
function_generator.append(R"~~~(
|
function_generator.append(R"~~~(
|
||||||
define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
|
define_native_function(realm, "@function.name@", @function.name:snakecase@, @function.length@, default_attributes);
|
||||||
|
@ -4172,7 +4172,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
|
||||||
Base::initialize(realm);
|
Base::initialize(realm);
|
||||||
)~~~");
|
)~~~");
|
||||||
if (interface.supports_named_properties()) {
|
if (interface.supports_named_properties()) {
|
||||||
generator.set("named_properties_class", DeprecatedString::formatted("{}Properties", interface.name));
|
generator.set("named_properties_class", ByteString::formatted("{}Properties", interface.name));
|
||||||
generator.set("namespaced_name", interface.namespaced_name);
|
generator.set("namespaced_name", interface.namespaced_name);
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
define_direct_property(vm().well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm(), "@namespaced_name@"_string), JS::Attribute::Configurable);
|
define_direct_property(vm().well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm(), "@namespaced_name@"_string), JS::Attribute::Configurable);
|
||||||
|
@ -4198,7 +4198,7 @@ void generate_iterator_prototype_header(IDL::Interface const& interface, StringB
|
||||||
VERIFY(interface.pair_iterator_types.has_value());
|
VERIFY(interface.pair_iterator_types.has_value());
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
|
|
||||||
generator.set("prototype_class", DeprecatedString::formatted("{}IteratorPrototype", interface.name));
|
generator.set("prototype_class", ByteString::formatted("{}IteratorPrototype", interface.name));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -4228,12 +4228,12 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface,
|
||||||
VERIFY(interface.pair_iterator_types.has_value());
|
VERIFY(interface.pair_iterator_types.has_value());
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
|
|
||||||
generator.set("name", DeprecatedString::formatted("{}Iterator", interface.name));
|
generator.set("name", ByteString::formatted("{}Iterator", interface.name));
|
||||||
generator.set("parent_name", interface.parent_name);
|
generator.set("parent_name", interface.parent_name);
|
||||||
generator.set("prototype_class", DeprecatedString::formatted("{}IteratorPrototype", interface.name));
|
generator.set("prototype_class", ByteString::formatted("{}IteratorPrototype", interface.name));
|
||||||
generator.set("prototype_base_class", interface.prototype_base_class);
|
generator.set("prototype_base_class", interface.prototype_base_class);
|
||||||
generator.set("fully_qualified_name", DeprecatedString::formatted("{}Iterator", interface.fully_qualified_name));
|
generator.set("fully_qualified_name", ByteString::formatted("{}Iterator", interface.fully_qualified_name));
|
||||||
generator.set("possible_include_path", DeprecatedString::formatted("{}Iterator", interface.name.replace("::"sv, "/"sv, ReplaceMode::All)));
|
generator.set("possible_include_path", ByteString::formatted("{}Iterator", interface.name.replace("::"sv, "/"sv, ReplaceMode::All)));
|
||||||
|
|
||||||
generator.append(R"~~~(
|
generator.append(R"~~~(
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue