diff options
-rw-r--r-- | src/string.cpp | 15 | ||||
-rw-r--r-- | src/string_func.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp index c3d6f5bc0..9d75e5c65 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -216,6 +216,21 @@ void str_strip_colours(char *str) } /** + * Get the length of an UTF-8 encoded string in number of characters + * and thus not the number of bytes that the encoded string contains. + * @param s The string to get the length for. + * @return The length of the string in characters. + */ +size_t Utf8StringLength(const char *s) +{ + size_t len = 0; + const char *t = s; + while (Utf8Consume(&t) != 0) len++; + return len; +} + + +/** * Convert a given ASCII string to lowercase. * NOTE: only support ASCII characters, no UTF8 fancy. As currently * the function is only used to lowercase data-filenames if they are diff --git a/src/string_func.h b/src/string_func.h index fd79d6bea..fe3d16971 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -233,6 +233,8 @@ static inline char *Utf8PrevChar(char *s) return ret; } +size_t Utf8StringLength(const char *s); + /** * Is the given character a text direction character. * @param c The character to test. |