From b4aedef848822649d3f7a045504eb2a9870b4b7e Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Sat, 29 May 2021 16:02:53 +0200 Subject: Codechange: add std::string variant of Utf8StringLength --- src/string.cpp | 10 ++++++++++ src/string_func.h | 1 + 2 files changed, 11 insertions(+) (limited to 'src') diff --git a/src/string.cpp b/src/string.cpp index 1cf61e8b4..e9a619c40 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -395,6 +395,16 @@ size_t Utf8StringLength(const char *s) return len; } +/** + * 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 std::string &str) +{ + return Utf8StringLength(str.c_str()); +} /** * Convert a given ASCII string to lowercase. diff --git a/src/string_func.h b/src/string_func.h index 0988f01b3..2e258fbd2 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -166,6 +166,7 @@ static inline const char *Utf8PrevChar(const char *s) } size_t Utf8StringLength(const char *s); +size_t Utf8StringLength(const std::string &str); /** * Is the given character a lead surrogate code point? -- cgit v1.2.3-54-g00ecf