mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-19 09:48:14 +00:00
stdlib: Add SDL_utf8strnlen
This commit is contained in:
@@ -675,6 +675,23 @@ SDL_utf8strlen(const char *str)
|
||||
return retval;
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_utf8strnlen(const char *str, size_t bytes)
|
||||
{
|
||||
size_t retval = 0;
|
||||
const char *p = str;
|
||||
unsigned char ch;
|
||||
|
||||
while ((ch = *(p++)) != 0 && bytes-- > 0) {
|
||||
/* if top two bits are 1 and 0, it's a continuation byte. */
|
||||
if ((ch & 0xc0) != 0x80) {
|
||||
retval++;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
Reference in New Issue
Block a user