From b1fe816336f06bc9e30f069b0b5481846340458d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 19 Aug 2025 19:40:18 -0400 Subject: [PATCH] AK: Provide a `length_in_code_units` API for UTF-8 strings This is just to afford API symmetry with UTF-16 strings to help in templated methods. --- AK/StringBase.h | 1 + AK/Utf8View.h | 1 + 2 files changed, 2 insertions(+) diff --git a/AK/StringBase.h b/AK/StringBase.h index 37c699a120b..55b8f8860e8 100644 --- a/AK/StringBase.h +++ b/AK/StringBase.h @@ -74,6 +74,7 @@ public: [[nodiscard]] ReadonlyBytes bytes() const; [[nodiscard]] u32 hash() const; [[nodiscard]] size_t byte_count() const; + [[nodiscard]] ALWAYS_INLINE size_t length_in_code_units() const { return byte_count(); } [[nodiscard]] bool operator==(StringBase const&) const; diff --git a/AK/Utf8View.h b/AK/Utf8View.h index 3b8d0cd63a9..cd7442804c0 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -90,6 +90,7 @@ public: unsigned char const* bytes() const { return begin_ptr(); } size_t byte_length() const { return m_string.length(); } + [[nodiscard]] ALWAYS_INLINE size_t length_in_code_units() const { return byte_length(); } size_t code_point_offset_of(size_t code_unit_offset) const;