mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-16 01:21:17 +00:00
- added some character counting utilities to FString.
This commit is contained in:
parent
8626dd665c
commit
18253b5203
2 changed files with 22 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue