stdlib: added SDL_utf8strlen().
authorRyan C. Gordon <icculus@icculus.org>
Mon, 29 May 2017 03:01:05 -0400
changeset 110496e24dc7c67c6
parent 11048 0ebcca15e978
child 11050 0b19d98c9a9d
stdlib: added SDL_utf8strlen().
include/SDL_stdinc.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/stdlib/SDL_string.c
     1.1 --- a/include/SDL_stdinc.h	Sun May 28 21:50:47 2017 +0200
     1.2 +++ b/include/SDL_stdinc.h	Mon May 29 03:01:05 2017 -0400
     1.3 @@ -416,6 +416,7 @@
     1.4  extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
     1.5  extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
     1.6  extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
     1.7 +extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
     1.8  
     1.9  extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
    1.10  extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Sun May 28 21:50:47 2017 +0200
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Mon May 29 03:01:05 2017 -0400
     2.3 @@ -624,3 +624,4 @@
     2.4  #define SDL_MemoryBarrierReleaseFunction SDL_MemoryBarrierReleaseFunction_REAL
     2.5  #define SDL_MemoryBarrierAcquireFunction SDL_MemoryBarrierAcquireFunction_REAL
     2.6  #define SDL_JoystickGetDeviceInstanceID SDL_JoystickGetDeviceInstanceID_REAL
     2.7 +#define SDL_utf8strlen SDL_utf8strlen_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Sun May 28 21:50:47 2017 +0200
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Mon May 29 03:01:05 2017 -0400
     3.3 @@ -656,3 +656,4 @@
     3.4  SDL_DYNAPI_PROC(void,SDL_MemoryBarrierReleaseFunction,(void),(),)
     3.5  SDL_DYNAPI_PROC(void,SDL_MemoryBarrierAcquireFunction,(void),(),)
     3.6  SDL_DYNAPI_PROC(SDL_JoystickID,SDL_JoystickGetDeviceInstanceID,(int a),(a),return)
     3.7 +SDL_DYNAPI_PROC(size_t,SDL_utf8strlen,(const char *a),(a),return)
     4.1 --- a/src/stdlib/SDL_string.c	Sun May 28 21:50:47 2017 +0200
     4.2 +++ b/src/stdlib/SDL_string.c	Mon May 29 03:01:05 2017 -0400
     4.3 @@ -510,6 +510,23 @@
     4.4  }
     4.5  
     4.6  size_t
     4.7 +SDL_utf8strlen(const char *str)
     4.8 +{
     4.9 +    size_t retval = 0;
    4.10 +    const char *p = str;
    4.11 +    char ch;
    4.12 +
    4.13 +    while ((ch = *(p++))) {
    4.14 +        /* if top two bits are 1 and 0, it's a continuation byte. */
    4.15 +        if ((ch & 0xc0) != 0x80) {
    4.16 +            retval++;
    4.17 +        }
    4.18 +    }
    4.19 +    
    4.20 +    return retval;
    4.21 +}
    4.22 +
    4.23 +size_t
    4.24  SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
    4.25  {
    4.26  #if defined(HAVE_STRLCAT)