From 728d592f4075ae78b67dab6911ada05875a470a3 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 17 Oct 2025 21:50:24 +0800 Subject: Fix macOS build. --- src/base/StringUtil.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/base/StringUtil.cpp') diff --git a/src/base/StringUtil.cpp b/src/base/StringUtil.cpp index 581ebcab..4cd662d1 100644 --- a/src/base/StringUtil.cpp +++ b/src/base/StringUtil.cpp @@ -357,4 +357,51 @@ Index Utf16NextWord(const Utf16CodeUnit* ptr, Index size, Index position, ptr, size, position, is_space); } +template NextCodePointFunction> +static Index IndexCodeUnitToCodePoint(const CharType* ptr, Index size, + Index position) { + CodePointIterator iter(ptr, size); + Index result = 0; + while (!iter.IsPastEnd() && iter.GetPosition() < position) { + ++iter; + ++result; + } + return result; +} + +template NextCodePointFunction> +static Index IndexCodePointToCodeUnit(const CharType* ptr, Index size, + Index position) { + CodePointIterator iter(ptr, size); + for (Index i = 0; i < position; i++) { + ++iter; + } + return iter.GetPosition(); +} + +Index Utf8IndexCodeUnitToCodePoint(const Utf8CodeUnit* ptr, Index size, + Index position) { + return IndexCodeUnitToCodePoint(ptr, size, + position); +} + +Index Utf8IndexCodePointToCodeUnit(const Utf8CodeUnit* ptr, Index size, + Index position) { + return IndexCodePointToCodeUnit(ptr, size, + position); +} + +Index Utf16IndexCodeUnitToCodePoint(const Utf16CodeUnit* ptr, Index size, + Index position) { + return IndexCodeUnitToCodePoint(ptr, size, + position); +} +Index Utf16IndexCodePointToCodeUnit(const Utf16CodeUnit* ptr, Index size, + Index position) { + return IndexCodePointToCodeUnit(ptr, size, + position); +} + } // namespace cru::string -- cgit v1.2.3