AK: Remove Utf32View and surrounding support
It is now unused, so let's just remove it.
This commit is contained in:
parent
4d51499809
commit
d3d96ce399
11 changed files with 0 additions and 346 deletions
|
|
@ -33,7 +33,6 @@ set(SOURCES
|
|||
Utf16String.cpp
|
||||
Utf16StringData.cpp
|
||||
Utf16View.cpp
|
||||
Utf32View.cpp
|
||||
Utf8View.cpp
|
||||
kmalloc.cpp
|
||||
)
|
||||
|
|
|
|||
|
|
@ -59,8 +59,6 @@ class UnixDateTime;
|
|||
class Utf16FlyString;
|
||||
class Utf16String;
|
||||
class Utf16View;
|
||||
class Utf32CodePointIterator;
|
||||
class Utf32View;
|
||||
class Utf8CodePointIterator;
|
||||
class Utf8View;
|
||||
|
||||
|
|
@ -232,8 +230,6 @@ using AK::Utf16FlyString;
|
|||
using AK::Utf16GenericLexer;
|
||||
using AK::Utf16String;
|
||||
using AK::Utf16View;
|
||||
using AK::Utf32CodePointIterator;
|
||||
using AK::Utf32View;
|
||||
using AK::Utf8CodePointIterator;
|
||||
using AK::Utf8View;
|
||||
using AK::ValueComparingNonnullRefPtr;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
#include <AK/Utf16String.h>
|
||||
#include <AK/Utf16StringData.h>
|
||||
#include <AK/Utf16View.h>
|
||||
#include <AK/Utf32View.h>
|
||||
|
||||
#include <simdutf.h>
|
||||
|
||||
|
|
@ -502,20 +501,6 @@ void StringBuilder::append(Utf16View const& utf16_view)
|
|||
MUST(try_append(utf16_view));
|
||||
}
|
||||
|
||||
ErrorOr<void> StringBuilder::try_append(Utf32View const& utf32_view)
|
||||
{
|
||||
for (size_t i = 0; i < utf32_view.length(); ++i) {
|
||||
auto code_point = utf32_view.code_points()[i];
|
||||
TRY(try_append_code_point(code_point));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void StringBuilder::append(Utf32View const& utf32_view)
|
||||
{
|
||||
MUST(try_append(utf32_view));
|
||||
}
|
||||
|
||||
void StringBuilder::append_as_lowercase(char ch)
|
||||
{
|
||||
if (ch >= 'A' && ch <= 'Z')
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ public:
|
|||
|
||||
ErrorOr<void> try_append(StringView);
|
||||
ErrorOr<void> try_append(Utf16View const&);
|
||||
ErrorOr<void> try_append(Utf32View const&);
|
||||
ErrorOr<void> try_append(char);
|
||||
ErrorOr<void> try_append_code_unit(char16_t);
|
||||
ErrorOr<void> try_append_code_point(u32);
|
||||
|
|
@ -56,7 +55,6 @@ public:
|
|||
|
||||
void append(StringView);
|
||||
void append(Utf16View const&);
|
||||
void append(Utf32View const&);
|
||||
void append(char);
|
||||
void append_code_unit(char16_t);
|
||||
void append_code_point(u32);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include <AK/Stream.h>
|
||||
#include <AK/StringNumber.h>
|
||||
#include <AK/Utf16String.h>
|
||||
#include <AK/Utf32View.h>
|
||||
|
||||
#include <simdutf.h>
|
||||
|
||||
|
|
@ -87,21 +86,6 @@ Utf16String Utf16String::from_utf16(Utf16View const& utf16_string)
|
|||
return Utf16String { Detail::Utf16StringData::from_utf16(utf16_string) };
|
||||
}
|
||||
|
||||
Utf16String Utf16String::from_utf32(Utf32View const& utf32_string)
|
||||
{
|
||||
if (utf32_string.length() <= Detail::MAX_SHORT_STRING_BYTE_COUNT && utf32_string.is_ascii()) {
|
||||
Utf16String string;
|
||||
string.m_value.short_ascii_string = Detail::ShortString::create_with_byte_count(utf32_string.length());
|
||||
|
||||
auto result = simdutf::convert_utf32_to_utf8(reinterpret_cast<char32_t const*>(utf32_string.code_points()), utf32_string.length(), reinterpret_cast<char*>(string.m_value.short_ascii_string.storage));
|
||||
VERIFY(result == utf32_string.length());
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
return Utf16String { Detail::Utf16StringData::from_utf32(utf32_string) };
|
||||
}
|
||||
|
||||
Utf16String Utf16String::from_string_builder(Badge<StringBuilder>, StringBuilder& builder)
|
||||
{
|
||||
auto view = builder.utf16_string_view();
|
||||
|
|
|
|||
|
|
@ -73,8 +73,6 @@ public:
|
|||
requires(IsOneOf<RemoveCVReference<T>, Utf16String, Utf16FlyString>)
|
||||
static Utf16String from_utf16(T&&) = delete;
|
||||
|
||||
static Utf16String from_utf32(Utf32View const&);
|
||||
|
||||
ALWAYS_INLINE static constexpr Utf16String from_ascii_character(u8 character)
|
||||
{
|
||||
auto short_string = Detail::ShortString::create_with_byte_count(1);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <AK/Stream.h>
|
||||
#include <AK/TypedTransfer.h>
|
||||
#include <AK/Utf16StringData.h>
|
||||
#include <AK/Utf32View.h>
|
||||
#include <AK/Utf8View.h>
|
||||
|
||||
#include <simdutf.h>
|
||||
|
|
@ -110,36 +109,6 @@ NonnullRefPtr<Utf16StringData> Utf16StringData::from_utf16(Utf16View const& utf1
|
|||
return string.release_nonnull();
|
||||
}
|
||||
|
||||
NonnullRefPtr<Utf16StringData> Utf16StringData::from_utf32(Utf32View const& utf32_string)
|
||||
{
|
||||
RefPtr<Utf16StringData> string;
|
||||
|
||||
auto const* utf32_data = reinterpret_cast<char32_t const*>(utf32_string.code_points());
|
||||
auto utf32_length = utf32_string.length();
|
||||
|
||||
if (utf32_string.is_ascii()) {
|
||||
VERIFY_UTF16_LENGTH(utf32_length);
|
||||
|
||||
string = create_uninitialized(StorageType::ASCII, utf32_length);
|
||||
|
||||
auto result = simdutf::convert_utf32_to_utf8(utf32_data, utf32_length, string->m_ascii_data);
|
||||
VERIFY(result == utf32_length);
|
||||
} else if (simdutf::validate_utf32(utf32_data, utf32_length)) {
|
||||
auto code_unit_length = simdutf::utf16_length_from_utf32(utf32_data, utf32_length);
|
||||
VERIFY_UTF16_LENGTH(code_unit_length);
|
||||
|
||||
string = create_uninitialized(StorageType::UTF16, code_unit_length);
|
||||
string->m_length_in_code_points = utf32_length;
|
||||
|
||||
auto result = simdutf::convert_utf32_to_utf16(utf32_data, utf32_length, string->m_utf16_data);
|
||||
VERIFY(result == code_unit_length);
|
||||
} else {
|
||||
string = create_from_code_point_iterable(utf32_string);
|
||||
}
|
||||
|
||||
return string.release_nonnull();
|
||||
}
|
||||
|
||||
NonnullRefPtr<Utf16StringData> Utf16StringData::from_string_builder(StringBuilder& builder)
|
||||
{
|
||||
auto view = builder.utf16_string_view();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ public:
|
|||
static NonnullRefPtr<Utf16StringData> from_utf8(StringView, AllowASCIIStorage);
|
||||
static NonnullRefPtr<Utf16StringData> from_ascii(ReadonlyBytes);
|
||||
static NonnullRefPtr<Utf16StringData> from_utf16(Utf16View const&);
|
||||
static NonnullRefPtr<Utf16StringData> from_utf32(Utf32View const&);
|
||||
static NonnullRefPtr<Utf16StringData> from_string_builder(StringBuilder&);
|
||||
static ErrorOr<NonnullRefPtr<Utf16StringData>> from_ipc_stream(Stream&, size_t length_in_code_units, bool is_ascii);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Utf32View.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
Optional<u32> Utf32CodePointIterator::peek(size_t offset) const
|
||||
{
|
||||
if (offset == 0) {
|
||||
if (this->done())
|
||||
return {};
|
||||
return this->operator*();
|
||||
}
|
||||
|
||||
auto new_iterator = *this;
|
||||
for (size_t index = 0; index < offset; ++index) {
|
||||
++new_iterator;
|
||||
if (new_iterator.done())
|
||||
return {};
|
||||
}
|
||||
|
||||
return *new_iterator;
|
||||
}
|
||||
|
||||
bool Utf32View::operator==(Utf32View const& other) const
|
||||
{
|
||||
ReadonlySpan<u32> code_points { m_code_points, m_length };
|
||||
ReadonlySpan<u32> other_code_points { other.m_code_points, other.m_length };
|
||||
|
||||
return code_points == other_code_points;
|
||||
}
|
||||
|
||||
ErrorOr<void> Formatter<Utf32View>::format(FormatBuilder& builder, Utf32View const& string)
|
||||
{
|
||||
return builder.builder().try_append(string);
|
||||
}
|
||||
|
||||
}
|
||||
155
AK/Utf32View.h
155
AK/Utf32View.h
|
|
@ -1,155 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/AllOf.h>
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <AK/Checked.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
class Utf32View;
|
||||
|
||||
class Utf32CodePointIterator {
|
||||
friend class Utf32View;
|
||||
|
||||
public:
|
||||
Utf32CodePointIterator() = default;
|
||||
~Utf32CodePointIterator() = default;
|
||||
|
||||
bool operator==(Utf32CodePointIterator const& other) const
|
||||
{
|
||||
return m_ptr == other.m_ptr && m_length == other.m_length;
|
||||
}
|
||||
Utf32CodePointIterator& operator++()
|
||||
{
|
||||
VERIFY(m_length > 0);
|
||||
m_ptr++;
|
||||
m_length--;
|
||||
return *this;
|
||||
}
|
||||
ssize_t operator-(Utf32CodePointIterator const& other) const
|
||||
{
|
||||
return m_ptr - other.m_ptr;
|
||||
}
|
||||
u32 operator*() const
|
||||
{
|
||||
VERIFY(m_length > 0);
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
// NOTE: This returns {} if the peek is at or past EOF.
|
||||
Optional<u32> peek(size_t offset = 0) const;
|
||||
|
||||
constexpr int code_point_length_in_bytes() const { return sizeof(u32); }
|
||||
bool done() const { return !m_length; }
|
||||
|
||||
private:
|
||||
Utf32CodePointIterator(u32 const* ptr, size_t length)
|
||||
: m_ptr(ptr)
|
||||
, m_length((ssize_t)length)
|
||||
{
|
||||
}
|
||||
u32 const* m_ptr { nullptr };
|
||||
ssize_t m_length { -1 };
|
||||
};
|
||||
|
||||
class Utf32View {
|
||||
public:
|
||||
using Iterator = Utf32CodePointIterator;
|
||||
|
||||
Utf32View() = default;
|
||||
Utf32View(u32 const* code_points, size_t length)
|
||||
: m_code_points(code_points)
|
||||
, m_length(length)
|
||||
{
|
||||
VERIFY(code_points || length == 0);
|
||||
}
|
||||
|
||||
Utf32View(ReadonlySpan<u32> code_points)
|
||||
: Utf32View(code_points.data(), code_points.size())
|
||||
{
|
||||
}
|
||||
|
||||
Utf32CodePointIterator begin() const
|
||||
{
|
||||
return { begin_ptr(), m_length };
|
||||
}
|
||||
|
||||
Utf32CodePointIterator end() const
|
||||
{
|
||||
return { end_ptr(), 0 };
|
||||
}
|
||||
|
||||
u32 at(size_t index) const
|
||||
{
|
||||
VERIFY(index < m_length);
|
||||
return m_code_points[index];
|
||||
}
|
||||
|
||||
u32 operator[](size_t index) const { return at(index); }
|
||||
|
||||
u32 const* code_points() const { return m_code_points; }
|
||||
bool is_empty() const { return m_length == 0; }
|
||||
bool is_null() const { return !m_code_points; }
|
||||
size_t length() const { return m_length; }
|
||||
|
||||
bool is_ascii() const
|
||||
{
|
||||
// FIXME: Petition simdutf to implement an ASCII validator for UTF-32.
|
||||
return all_of(*this, AK::is_ascii);
|
||||
}
|
||||
|
||||
size_t iterator_offset(Utf32CodePointIterator const& it) const
|
||||
{
|
||||
VERIFY(it.m_ptr >= m_code_points);
|
||||
VERIFY(it.m_ptr < m_code_points + m_length);
|
||||
return ((ptrdiff_t)it.m_ptr - (ptrdiff_t)m_code_points) / sizeof(u32);
|
||||
}
|
||||
|
||||
Utf32View substring_view(size_t offset, size_t length) const
|
||||
{
|
||||
VERIFY(offset <= m_length);
|
||||
VERIFY(!Checked<size_t>::addition_would_overflow(offset, length));
|
||||
VERIFY((offset + length) <= m_length);
|
||||
return Utf32View(m_code_points + offset, length);
|
||||
}
|
||||
|
||||
Utf32View substring_view(size_t offset) const
|
||||
{
|
||||
return substring_view(offset, length() - offset);
|
||||
}
|
||||
|
||||
bool operator==(Utf32View const& other) const;
|
||||
|
||||
private:
|
||||
u32 const* begin_ptr() const
|
||||
{
|
||||
return m_code_points;
|
||||
}
|
||||
u32 const* end_ptr() const
|
||||
{
|
||||
return m_code_points + m_length;
|
||||
}
|
||||
|
||||
u32 const* m_code_points { nullptr };
|
||||
size_t m_length { 0 };
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<Utf32View> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder&, Utf32View const&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
using AK::Utf32View;
|
||||
#endif
|
||||
|
|
@ -12,7 +12,6 @@
|
|||
#include <AK/MemoryStream.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Utf16String.h>
|
||||
#include <AK/Utf32View.h>
|
||||
|
||||
static_assert(AK::Concepts::HashCompatible<Utf16String, Utf16View>);
|
||||
static_assert(AK::Concepts::HashCompatible<Utf16View, Utf16String>);
|
||||
|
|
@ -197,81 +196,6 @@ TEST_CASE(from_utf16)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE(from_utf32)
|
||||
{
|
||||
auto strlen32 = [](char32_t const* string) {
|
||||
auto const* start = string;
|
||||
while (*start)
|
||||
++start;
|
||||
return static_cast<size_t>(start - string);
|
||||
};
|
||||
|
||||
auto to_utf32_view = [&](char32_t const* string) {
|
||||
return Utf32View { reinterpret_cast<u32 const*>(string), strlen32(string) };
|
||||
};
|
||||
|
||||
{
|
||||
auto string = Utf16String::from_utf32(to_utf32_view(U"hello!"));
|
||||
EXPECT(!string.is_empty());
|
||||
EXPECT(string.is_ascii());
|
||||
EXPECT(!string.has_long_ascii_storage());
|
||||
EXPECT(string.has_short_ascii_storage());
|
||||
EXPECT_EQ(string.length_in_code_units(), 6uz);
|
||||
EXPECT_EQ(string.length_in_code_points(), 6uz);
|
||||
EXPECT_EQ(string.ascii_view(), "hello!"sv);
|
||||
}
|
||||
{
|
||||
auto string = Utf16String::from_utf32(to_utf32_view(U"hello there!"));
|
||||
EXPECT(!string.is_empty());
|
||||
EXPECT(string.is_ascii());
|
||||
EXPECT(string.has_long_ascii_storage());
|
||||
EXPECT(!string.has_short_ascii_storage());
|
||||
EXPECT_EQ(string.length_in_code_units(), 12uz);
|
||||
EXPECT_EQ(string.length_in_code_points(), 12uz);
|
||||
EXPECT_EQ(string.ascii_view(), "hello there!"sv);
|
||||
}
|
||||
{
|
||||
auto string = Utf16String::from_utf32(to_utf32_view(U"😀"));
|
||||
EXPECT(!string.is_empty());
|
||||
EXPECT(!string.is_ascii());
|
||||
EXPECT(!string.has_long_ascii_storage());
|
||||
EXPECT(!string.has_short_ascii_storage());
|
||||
EXPECT_EQ(string.length_in_code_units(), 2uz);
|
||||
EXPECT_EQ(string.length_in_code_points(), 1uz);
|
||||
EXPECT_EQ(string.utf16_view(), u"😀"sv);
|
||||
}
|
||||
{
|
||||
auto string = Utf16String::from_utf32(to_utf32_view(U"hello 😀 there!"));
|
||||
EXPECT(!string.is_empty());
|
||||
EXPECT(!string.is_ascii());
|
||||
EXPECT(!string.has_long_ascii_storage());
|
||||
EXPECT(!string.has_short_ascii_storage());
|
||||
EXPECT_EQ(string.length_in_code_units(), 15uz);
|
||||
EXPECT_EQ(string.length_in_code_points(), 14uz);
|
||||
EXPECT_EQ(string.utf16_view(), u"hello 😀 there!"sv);
|
||||
}
|
||||
{
|
||||
auto string = Utf16String::from_utf32(to_utf32_view(U"hello \xd800!"));
|
||||
EXPECT(!string.is_empty());
|
||||
EXPECT(!string.is_ascii());
|
||||
EXPECT(!string.has_long_ascii_storage());
|
||||
EXPECT(!string.has_short_ascii_storage());
|
||||
EXPECT_EQ(string.length_in_code_units(), 8uz);
|
||||
EXPECT_EQ(string.length_in_code_points(), 8uz);
|
||||
EXPECT_EQ(string.utf16_view(), u"hello \xd800!"sv);
|
||||
}
|
||||
{
|
||||
auto string = Utf16String::from_utf32(to_utf32_view(U"hello \xdc00!"));
|
||||
EXPECT(!string.is_empty());
|
||||
EXPECT(!string.is_ascii());
|
||||
EXPECT(!string.has_long_ascii_storage());
|
||||
EXPECT(!string.has_short_ascii_storage());
|
||||
EXPECT_EQ(string.length_in_code_units(), 8uz);
|
||||
EXPECT_EQ(string.length_in_code_points(), 8uz);
|
||||
EXPECT_EQ(string.utf16_view(), u"hello \xdc00!"sv);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(from_code_point)
|
||||
{
|
||||
u32 code_point = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue