stdlib: added SDL_utf8strlen().

--HG--
extra : histedit_source : 3ef78f0c18ad1f096882e5e079119fe0b3fef6db%2Cd98e52df919c701f80b47d989028227d060e2ecb
This commit is contained in:
Ryan C. Gordon 2017-05-29 03:01:05 -04:00
parent acf207211f
commit d202066528
4 changed files with 20 additions and 0 deletions

View file

@ -509,6 +509,23 @@ size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size
return bytes;
}
size_t
SDL_utf8strlen(const char *str)
{
size_t retval = 0;
const char *p = str;
char ch;
while ((ch = *(p++))) {
/* 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)
{