mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 06:15:04 +00:00
(svn r21404) -Add: method for getting the length of an Utf8 string in characters
This commit is contained in:
parent
7e9b132d04
commit
440a529701
@ -215,6 +215,21 @@ void str_strip_colours(char *str)
|
|||||||
*dst = '\0';
|
*dst = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Convert a given ASCII string to lowercase.
|
||||||
* NOTE: only support ASCII characters, no UTF8 fancy. As currently
|
* NOTE: only support ASCII characters, no UTF8 fancy. As currently
|
||||||
|
@ -233,6 +233,8 @@ static inline char *Utf8PrevChar(char *s)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Utf8StringLength(const char *s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the given character a text direction character.
|
* Is the given character a text direction character.
|
||||||
* @param c The character to test.
|
* @param c The character to test.
|
||||||
|
Loading…
Reference in New Issue
Block a user