1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 08:52:40 +01:00

Codechange: Use Utf8View in Utf8StringLength.

This commit is contained in:
frosch
2025-04-01 18:21:03 +02:00
committed by frosch
parent 83401ad5e2
commit f19e75b606
4 changed files with 17 additions and 19 deletions

View File

@@ -389,23 +389,10 @@ bool StrContainsIgnoreCase(const std::string_view str, const std::string_view va
* @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 Utf8StringLength(std::string_view str)
{
size_t len = 0;
const char *t = s;
while (Utf8Consume(&t) != 0) len++;
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());
Utf8View view(str);
return std::distance(view.begin(), view.end());
}
bool strtolower(std::string &str, std::string::size_type offs)