mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:58:14 +00:00
AK: Make Utf8View and Utf32View more consistent
This enables use of these classes in templated code.
This commit is contained in:
parent
15642874f3
commit
6413acd78c
5 changed files with 89 additions and 4 deletions
|
@ -45,6 +45,11 @@ public:
|
|||
Utf8CodepointIterator& operator++();
|
||||
u32 operator*() const;
|
||||
|
||||
ssize_t operator-(const Utf8CodepointIterator& other) const
|
||||
{
|
||||
return m_ptr - other.m_ptr;
|
||||
}
|
||||
|
||||
int code_point_length_in_bytes() const;
|
||||
bool done() const { return !m_length; }
|
||||
|
||||
|
@ -56,6 +61,8 @@ private:
|
|||
|
||||
class Utf8View {
|
||||
public:
|
||||
typedef Utf8CodepointIterator Iterator;
|
||||
|
||||
Utf8View() { }
|
||||
explicit Utf8View(const String&);
|
||||
explicit Utf8View(const StringView&);
|
||||
|
@ -80,13 +87,23 @@ public:
|
|||
return validate(valid_bytes);
|
||||
}
|
||||
|
||||
size_t length_in_code_points() const;
|
||||
size_t length() const
|
||||
{
|
||||
if (!m_have_length) {
|
||||
m_length = calculate_length();
|
||||
m_have_length = true;
|
||||
}
|
||||
return m_length;
|
||||
}
|
||||
|
||||
private:
|
||||
const unsigned char* begin_ptr() const;
|
||||
const unsigned char* end_ptr() const;
|
||||
size_t calculate_length() const;
|
||||
|
||||
StringView m_string;
|
||||
mutable size_t m_length { 0 };
|
||||
mutable bool m_have_length { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue