diff --git a/src/utility/zstring.cpp b/src/utility/zstring.cpp index 0eb8fe67d..0e2720da2 100644 --- a/src/utility/zstring.cpp +++ b/src/utility/zstring.cpp @@ -38,6 +38,7 @@ #include // for bad_alloc #include "zstring.h" +#include "v_text.h" FNullStringData FString::NullString = { @@ -379,6 +380,25 @@ FString &FString::CopyCStrPart(const char *tail, size_t tailLen) return *this; } +size_t FString::CharacterCount() const +{ + // Counts string length in Unicode code points. + size_t len = 0; + const uint8_t *cp = (const uint8_t*)Chars; + while (GetCharFromString(cp)) len++; + return len; +} + + +int FString::GetNextCharacter(int &position) const +{ + const uint8_t *cp = (const uint8_t*)Chars; + const uint8_t *cpread = cp + position; + int chr = GetCharFromString(cpread); + position += int(cpread - cp); + return chr; +} + void FString::Truncate(size_t newlen) { if (newlen == 0) diff --git a/src/utility/zstring.h b/src/utility/zstring.h index 2924de96d..2ef4ff196 100644 --- a/src/utility/zstring.h +++ b/src/utility/zstring.h @@ -304,6 +304,8 @@ public: double ToDouble () const; size_t Len() const { return Data()->Len; } + size_t CharacterCount() const; + int GetNextCharacter(int &position) const; bool IsEmpty() const { return Len() == 0; } bool IsNotEmpty() const { return Len() != 0; }