diff options
author | rubidium <rubidium@openttd.org> | 2010-12-05 22:17:25 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-12-05 22:17:25 +0000 |
commit | 440a529701a8a838cab57d41d97b9c0bfad0d43d (patch) | |
tree | 9bb955aaf0c7e64f419a66f4b0b8064fb6260158 /src/string.cpp | |
parent | 7e9b132d0498c63cec0686071b8339523b7643c4 (diff) | |
download | openttd-440a529701a8a838cab57d41d97b9c0bfad0d43d.tar.xz |
(svn r21404) -Add: method for getting the length of an Utf8 string in characters
Diffstat (limited to 'src/string.cpp')
-rw-r--r-- | src/string.cpp | 15 |
1 files changed, 15 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 |