Added a StringUtil function to return the string length in Unicode characters

This commit is contained in:
Leon Styhre 2024-07-26 21:09:51 +02:00
parent 428bbc1416
commit 3b5d5a7da4
2 changed files with 14 additions and 0 deletions

View file

@ -470,6 +470,19 @@ namespace Utils
return result;
}
size_t unicodeLength(const std::string& stringArg)
{
size_t length {0};
size_t charLength {0};
for (size_t i {0}; i < stringArg.length(); i += charLength) {
charLength = moveCursor(stringArg, i, 1) - i;
++length;
}
return length;
}
std::string toLower(const std::string& stringArg)
{
std::string stringLower;

View file

@ -27,6 +27,7 @@ namespace Utils
size_t nextCursor(const std::string& stringArg, const size_t cursor);
size_t prevCursor(const std::string& stringArg, const size_t cursor);
size_t moveCursor(const std::string& stringArg, const size_t cursor, const int amount);
size_t unicodeLength(const std::string& stringArg);
std::string toLower(const std::string& stringArg);
std::string toUpper(const std::string& stringArg);
std::string toCapitalized(const std::string& stringArg);