From 3b5d5a7da473d3358f4c5ecb894a699e25793494 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 26 Jul 2024 21:09:51 +0200 Subject: [PATCH] Added a StringUtil function to return the string length in Unicode characters --- es-core/src/utils/StringUtil.cpp | 13 +++++++++++++ es-core/src/utils/StringUtil.h | 1 + 2 files changed, 14 insertions(+) diff --git a/es-core/src/utils/StringUtil.cpp b/es-core/src/utils/StringUtil.cpp index 4a122c579..af8144508 100644 --- a/es-core/src/utils/StringUtil.cpp +++ b/es-core/src/utils/StringUtil.cpp @@ -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; diff --git a/es-core/src/utils/StringUtil.h b/es-core/src/utils/StringUtil.h index 7835f0c39..330b09e27 100644 --- a/es-core/src/utils/StringUtil.h +++ b/es-core/src/utils/StringUtil.h @@ -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);