- added some character counting utilities to FString.

This commit is contained in:
Christoph Oelckers 2019-02-15 08:51:41 +01:00 committed by drfrag
parent 8626dd665c
commit 18253b5203
2 changed files with 22 additions and 0 deletions

View file

@ -38,6 +38,7 @@
#include <new> // 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)

View file

@ -299,6 +299,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; }