mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Rename Utf8CodepointIterator => Utf8CodePointIterator
This commit is contained in:
parent
628c7f094f
commit
407d6cd9e4
Notes:
sideshowbarker
2024-07-18 17:03:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/407d6cd9e48
8 changed files with 37 additions and 37 deletions
|
@ -227,7 +227,7 @@ URL URLParser::parse(Badge<URL>, const StringView& raw_input, URL const* base_ur
|
|||
bool password_token_seen = false;
|
||||
|
||||
Utf8View input(processed_input);
|
||||
Utf8CodepointIterator iterator = input.begin();
|
||||
Utf8CodePointIterator iterator = input.begin();
|
||||
|
||||
auto get_remaining = [&input, &iterator] {
|
||||
return input.substring_view(iterator - input.begin() + iterator.code_point_length_in_bytes()).as_string();
|
||||
|
|
|
@ -36,17 +36,17 @@ const unsigned char* Utf8View::end_ptr() const
|
|||
return begin_ptr() + m_string.length();
|
||||
}
|
||||
|
||||
Utf8CodepointIterator Utf8View::begin() const
|
||||
Utf8CodePointIterator Utf8View::begin() const
|
||||
{
|
||||
return { begin_ptr(), m_string.length() };
|
||||
}
|
||||
|
||||
Utf8CodepointIterator Utf8View::end() const
|
||||
Utf8CodePointIterator Utf8View::end() const
|
||||
{
|
||||
return { end_ptr(), 0 };
|
||||
}
|
||||
|
||||
Utf8CodepointIterator Utf8View::iterator_at_byte_offset(size_t byte_offset) const
|
||||
Utf8CodePointIterator Utf8View::iterator_at_byte_offset(size_t byte_offset) const
|
||||
{
|
||||
size_t current_offset = 0;
|
||||
for (auto iterator = begin(); !iterator.done(); ++iterator) {
|
||||
|
@ -57,7 +57,7 @@ Utf8CodepointIterator Utf8View::iterator_at_byte_offset(size_t byte_offset) cons
|
|||
return end();
|
||||
}
|
||||
|
||||
size_t Utf8View::byte_offset_of(const Utf8CodepointIterator& it) const
|
||||
size_t Utf8View::byte_offset_of(const Utf8CodePointIterator& it) const
|
||||
{
|
||||
VERIFY(it.m_ptr >= begin_ptr());
|
||||
VERIFY(it.m_ptr <= end_ptr());
|
||||
|
@ -173,23 +173,23 @@ bool Utf8View::starts_with(const Utf8View& start) const
|
|||
return true;
|
||||
}
|
||||
|
||||
Utf8CodepointIterator::Utf8CodepointIterator(const unsigned char* ptr, size_t length)
|
||||
Utf8CodePointIterator::Utf8CodePointIterator(const unsigned char* ptr, size_t length)
|
||||
: m_ptr(ptr)
|
||||
, m_length(length)
|
||||
{
|
||||
}
|
||||
|
||||
bool Utf8CodepointIterator::operator==(const Utf8CodepointIterator& other) const
|
||||
bool Utf8CodePointIterator::operator==(const Utf8CodePointIterator& other) const
|
||||
{
|
||||
return m_ptr == other.m_ptr && m_length == other.m_length;
|
||||
}
|
||||
|
||||
bool Utf8CodepointIterator::operator!=(const Utf8CodepointIterator& other) const
|
||||
bool Utf8CodePointIterator::operator!=(const Utf8CodePointIterator& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
Utf8CodepointIterator& Utf8CodepointIterator::operator++()
|
||||
Utf8CodePointIterator& Utf8CodePointIterator::operator++()
|
||||
{
|
||||
VERIFY(m_length > 0);
|
||||
|
||||
|
@ -206,7 +206,7 @@ Utf8CodepointIterator& Utf8CodepointIterator::operator++()
|
|||
return *this;
|
||||
}
|
||||
|
||||
size_t Utf8CodepointIterator::code_point_length_in_bytes() const
|
||||
size_t Utf8CodePointIterator::code_point_length_in_bytes() const
|
||||
{
|
||||
VERIFY(m_length > 0);
|
||||
size_t code_point_length_in_bytes = 0;
|
||||
|
@ -216,7 +216,7 @@ size_t Utf8CodepointIterator::code_point_length_in_bytes() const
|
|||
return code_point_length_in_bytes;
|
||||
}
|
||||
|
||||
u32 Utf8CodepointIterator::operator*() const
|
||||
u32 Utf8CodePointIterator::operator*() const
|
||||
{
|
||||
VERIFY(m_length > 0);
|
||||
|
||||
|
@ -240,7 +240,7 @@ u32 Utf8CodepointIterator::operator*() const
|
|||
return code_point_value_so_far;
|
||||
}
|
||||
|
||||
Optional<u32> Utf8CodepointIterator::peek(size_t offset) const
|
||||
Optional<u32> Utf8CodePointIterator::peek(size_t offset) const
|
||||
{
|
||||
if (offset == 0) {
|
||||
if (this->done())
|
||||
|
|
|
@ -14,21 +14,21 @@ namespace AK {
|
|||
|
||||
class Utf8View;
|
||||
|
||||
class Utf8CodepointIterator {
|
||||
class Utf8CodePointIterator {
|
||||
friend class Utf8View;
|
||||
|
||||
public:
|
||||
Utf8CodepointIterator() = default;
|
||||
~Utf8CodepointIterator() = default;
|
||||
Utf8CodePointIterator() = default;
|
||||
~Utf8CodePointIterator() = default;
|
||||
|
||||
bool operator==(const Utf8CodepointIterator&) const;
|
||||
bool operator!=(const Utf8CodepointIterator&) const;
|
||||
Utf8CodepointIterator& operator++();
|
||||
bool operator==(const Utf8CodePointIterator&) const;
|
||||
bool operator!=(const Utf8CodePointIterator&) const;
|
||||
Utf8CodePointIterator& operator++();
|
||||
u32 operator*() const;
|
||||
// NOTE: This returns {} if the peek is at or past EOF.
|
||||
Optional<u32> peek(size_t offset = 0) const;
|
||||
|
||||
ssize_t operator-(const Utf8CodepointIterator& other) const
|
||||
ssize_t operator-(const Utf8CodePointIterator& other) const
|
||||
{
|
||||
return m_ptr - other.m_ptr;
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ public:
|
|||
bool done() const { return m_length == 0; }
|
||||
|
||||
private:
|
||||
Utf8CodepointIterator(const unsigned char*, size_t);
|
||||
Utf8CodePointIterator(const unsigned char*, size_t);
|
||||
const unsigned char* m_ptr { nullptr };
|
||||
size_t m_length;
|
||||
};
|
||||
|
||||
class Utf8View {
|
||||
public:
|
||||
using Iterator = Utf8CodepointIterator;
|
||||
using Iterator = Utf8CodePointIterator;
|
||||
|
||||
Utf8View() = default;
|
||||
explicit Utf8View(const String&);
|
||||
|
@ -54,13 +54,13 @@ public:
|
|||
|
||||
const StringView& as_string() const { return m_string; }
|
||||
|
||||
Utf8CodepointIterator begin() const;
|
||||
Utf8CodepointIterator end() const;
|
||||
Utf8CodepointIterator iterator_at_byte_offset(size_t) const;
|
||||
Utf8CodePointIterator begin() const;
|
||||
Utf8CodePointIterator end() const;
|
||||
Utf8CodePointIterator iterator_at_byte_offset(size_t) const;
|
||||
|
||||
const unsigned char* bytes() const { return begin_ptr(); }
|
||||
size_t byte_length() const { return m_string.length(); }
|
||||
size_t byte_offset_of(const Utf8CodepointIterator&) const;
|
||||
size_t byte_offset_of(const Utf8CodePointIterator&) const;
|
||||
|
||||
Utf8View substring_view(size_t byte_offset, size_t byte_length) const;
|
||||
Utf8View substring_view(size_t byte_offset) const { return substring_view(byte_offset, byte_length() - byte_offset); }
|
||||
|
@ -70,7 +70,7 @@ public:
|
|||
bool is_empty() const { return m_string.is_empty(); }
|
||||
bool starts_with(const Utf8View&) const;
|
||||
|
||||
size_t iterator_offset(const Utf8CodepointIterator& it) const
|
||||
size_t iterator_offset(const Utf8CodePointIterator& it) const
|
||||
{
|
||||
return byte_offset_of(it);
|
||||
}
|
||||
|
@ -103,5 +103,5 @@ private:
|
|||
|
||||
}
|
||||
|
||||
using AK::Utf8CodepointIterator;
|
||||
using AK::Utf8CodePointIterator;
|
||||
using AK::Utf8View;
|
||||
|
|
|
@ -71,7 +71,7 @@ TEST_CASE(validate_invalid_ut8)
|
|||
TEST_CASE(iterate_utf8)
|
||||
{
|
||||
Utf8View view("Some weird characters \u00A9\u266A\uA755");
|
||||
Utf8CodepointIterator iterator = view.begin();
|
||||
Utf8CodePointIterator iterator = view.begin();
|
||||
|
||||
EXPECT(*iterator == 'S');
|
||||
EXPECT(iterator.peek().has_value() && iterator.peek().value() == 'S');
|
||||
|
@ -98,7 +98,7 @@ TEST_CASE(iterate_utf8)
|
|||
|
||||
EXPECT(iterator.done());
|
||||
EXPECT(!iterator.peek(0).has_value());
|
||||
EXPECT_CRASH("Dereferencing Utf8CodepointIterator which is already done.", [&iterator] {
|
||||
EXPECT_CRASH("Dereferencing Utf8CodePointIterator which is already done.", [&iterator] {
|
||||
*iterator;
|
||||
return Test::Crash::Failure::DidNotCrash;
|
||||
});
|
||||
|
|
|
@ -20,14 +20,14 @@ public:
|
|||
explicit StringIterator(Object& prototype, String string);
|
||||
virtual ~StringIterator() override;
|
||||
|
||||
Utf8CodepointIterator& iterator() { return m_iterator; }
|
||||
Utf8CodePointIterator& iterator() { return m_iterator; }
|
||||
bool done() const { return m_done; }
|
||||
|
||||
private:
|
||||
friend class StringIteratorPrototype;
|
||||
|
||||
String m_string;
|
||||
Utf8CodepointIterator m_iterator;
|
||||
Utf8CodePointIterator m_iterator;
|
||||
bool m_done { false };
|
||||
};
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ private:
|
|||
|
||||
String m_decoded_input;
|
||||
Utf8View m_utf8_view;
|
||||
AK::Utf8CodepointIterator m_utf8_iterator;
|
||||
AK::Utf8CodepointIterator m_prev_utf8_iterator;
|
||||
AK::Utf8CodePointIterator m_utf8_iterator;
|
||||
AK::Utf8CodePointIterator m_prev_utf8_iterator;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2675,7 +2675,7 @@ bool HTMLTokenizer::consumed_as_part_of_an_attribute() const
|
|||
return m_return_state == State::AttributeValueUnquoted || m_return_state == State::AttributeValueSingleQuoted || m_return_state == State::AttributeValueDoubleQuoted;
|
||||
}
|
||||
|
||||
void HTMLTokenizer::restore_to(const Utf8CodepointIterator& new_iterator)
|
||||
void HTMLTokenizer::restore_to(const Utf8CodePointIterator& new_iterator)
|
||||
{
|
||||
if (new_iterator != m_prev_utf8_iterator) {
|
||||
auto diff = m_prev_utf8_iterator - new_iterator;
|
||||
|
|
|
@ -146,7 +146,7 @@ private:
|
|||
|
||||
bool consumed_as_part_of_an_attribute() const;
|
||||
|
||||
void restore_to(const Utf8CodepointIterator& new_iterator);
|
||||
void restore_to(const Utf8CodePointIterator& new_iterator);
|
||||
auto& nth_last_position(size_t n = 0) { return m_source_positions.at(m_source_positions.size() - 1 - n); }
|
||||
|
||||
State m_state { State::Data };
|
||||
|
@ -159,8 +159,8 @@ private:
|
|||
StringView m_input;
|
||||
|
||||
Utf8View m_utf8_view;
|
||||
Utf8CodepointIterator m_utf8_iterator;
|
||||
Utf8CodepointIterator m_prev_utf8_iterator;
|
||||
Utf8CodePointIterator m_utf8_iterator;
|
||||
Utf8CodePointIterator m_prev_utf8_iterator;
|
||||
|
||||
HTMLToken m_current_token;
|
||||
|
||||
|
|
Loading…
Reference in a new issue