summaryrefslogtreecommitdiff
path: root/AK/Utf8View.h
diff options
context:
space:
mode:
Diffstat (limited to 'AK/Utf8View.h')
-rw-r--r--AK/Utf8View.h25
1 files changed, 15 insertions, 10 deletions
diff --git a/AK/Utf8View.h b/AK/Utf8View.h
index 5c63c79708..18b5a3df4b 100644
--- a/AK/Utf8View.h
+++ b/AK/Utf8View.h
@@ -22,8 +22,8 @@ public:
Utf8CodePointIterator() = default;
~Utf8CodePointIterator() = default;
- bool operator==(const Utf8CodePointIterator&) const;
- bool operator!=(const Utf8CodePointIterator&) const;
+ bool operator==(Utf8CodePointIterator const&) const = default;
+ bool operator!=(Utf8CodePointIterator const&) const = default;
Utf8CodePointIterator& operator++();
u32 operator*() const;
// NOTE: This returns {} if the peek is at or past EOF.
@@ -44,9 +44,14 @@ public:
bool done() const { return m_length == 0; }
private:
- Utf8CodePointIterator(const unsigned char*, size_t);
- const unsigned char* m_ptr { nullptr };
- size_t m_length;
+ Utf8CodePointIterator(u8 const* ptr, size_t length)
+ : m_ptr(ptr)
+ , m_length(length)
+ {
+ }
+
+ u8 const* m_ptr { nullptr };
+ size_t m_length { 0 };
};
class Utf8View {
@@ -71,8 +76,8 @@ public:
const StringView& as_string() const { return m_string; }
- Utf8CodePointIterator begin() const;
- Utf8CodePointIterator end() const;
+ Utf8CodePointIterator begin() const { return { begin_ptr(), m_string.length() }; }
+ Utf8CodePointIterator end() const { return { end_ptr(), 0 }; }
Utf8CodePointIterator iterator_at_byte_offset(size_t) const;
const unsigned char* bytes() const { return begin_ptr(); }
@@ -80,7 +85,7 @@ public:
size_t byte_offset_of(const Utf8CodePointIterator&) const;
size_t byte_offset_of(size_t code_point_offset) const;
- Utf8View substring_view(size_t byte_offset, size_t byte_length) const;
+ Utf8View substring_view(size_t byte_offset, size_t byte_length) const { return Utf8View { m_string.substring_view(byte_offset, byte_length) }; }
Utf8View substring_view(size_t byte_offset) const { return substring_view(byte_offset, byte_length() - byte_offset); }
Utf8View unicode_substring_view(size_t code_point_offset, size_t code_point_length) const;
Utf8View unicode_substring_view(size_t code_point_offset) const { return unicode_substring_view(code_point_offset, length() - code_point_offset); }
@@ -114,8 +119,8 @@ public:
}
private:
- const unsigned char* begin_ptr() const;
- const unsigned char* end_ptr() const;
+ u8 const* begin_ptr() const { return (u8 const*)m_string.characters_without_null_termination(); }
+ u8 const* end_ptr() const { return begin_ptr() + m_string.length(); }
size_t calculate_length() const;
StringView m_string;