From 6cde7e4d20be4f244da16ab9f354628588964d1c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 17 May 2020 13:02:27 +0200 Subject: [PATCH] AK: Add Utf8View::length_in_codepoints() --- AK/Utf8View.cpp | 10 ++++++++++ AK/Utf8View.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/AK/Utf8View.cpp b/AK/Utf8View.cpp index 90b56be2a5..b7bdbd43bc 100644 --- a/AK/Utf8View.cpp +++ b/AK/Utf8View.cpp @@ -132,6 +132,16 @@ bool Utf8View::validate() const return true; } +size_t Utf8View::length_in_codepoints() const +{ + size_t length = 0; + for (auto codepoint : *this) { + (void)codepoint; + ++length; + } + return length; +} + Utf8CodepointIterator::Utf8CodepointIterator(const unsigned char* ptr, int length) : m_ptr(ptr) , m_length(length) diff --git a/AK/Utf8View.h b/AK/Utf8View.h index 1a4a26ae09..5946a6f5e5 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -72,6 +72,8 @@ public: bool validate() const; + size_t length_in_codepoints() const; + private: const unsigned char* begin_ptr() const; const unsigned char* end_ptr() const;