[Commits] SDL: stdlib: added SDL_utf8strlen().

libsdl.org revision control commits-owner at libsdl.org
Mon May 29 00:05:49 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/6e24dc7c67c6
changeset: 11049:6e24dc7c67c6
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Mon May 29 03:01:05 2017 -0400
description:
stdlib: added SDL_utf8strlen().

diffstat:

 include/SDL_stdinc.h              |   1 +
 src/dynapi/SDL_dynapi_overrides.h |   1 +
 src/dynapi/SDL_dynapi_procs.h     |   1 +
 src/stdlib/SDL_string.c           |  17 +++++++++++++++++
 4 files changed, 20 insertions(+), 0 deletions(-)

diffs (54 lines):

diff -r 0ebcca15e978 -r 6e24dc7c67c6 include/SDL_stdinc.h
--- a/include/SDL_stdinc.h	Sun May 28 21:50:47 2017 +0200
+++ b/include/SDL_stdinc.h	Mon May 29 03:01:05 2017 -0400
@@ -416,6 +416,7 @@
 extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
 extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
 extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
+extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
 
 extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
 extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
diff -r 0ebcca15e978 -r 6e24dc7c67c6 src/dynapi/SDL_dynapi_overrides.h
--- a/src/dynapi/SDL_dynapi_overrides.h	Sun May 28 21:50:47 2017 +0200
+++ b/src/dynapi/SDL_dynapi_overrides.h	Mon May 29 03:01:05 2017 -0400
@@ -624,3 +624,4 @@
 #define SDL_MemoryBarrierReleaseFunction SDL_MemoryBarrierReleaseFunction_REAL
 #define SDL_MemoryBarrierAcquireFunction SDL_MemoryBarrierAcquireFunction_REAL
 #define SDL_JoystickGetDeviceInstanceID SDL_JoystickGetDeviceInstanceID_REAL
+#define SDL_utf8strlen SDL_utf8strlen_REAL
diff -r 0ebcca15e978 -r 6e24dc7c67c6 src/dynapi/SDL_dynapi_procs.h
--- a/src/dynapi/SDL_dynapi_procs.h	Sun May 28 21:50:47 2017 +0200
+++ b/src/dynapi/SDL_dynapi_procs.h	Mon May 29 03:01:05 2017 -0400
@@ -656,3 +656,4 @@
 SDL_DYNAPI_PROC(void,SDL_MemoryBarrierReleaseFunction,(void),(),)
 SDL_DYNAPI_PROC(void,SDL_MemoryBarrierAcquireFunction,(void),(),)
 SDL_DYNAPI_PROC(SDL_JoystickID,SDL_JoystickGetDeviceInstanceID,(int a),(a),return)
+SDL_DYNAPI_PROC(size_t,SDL_utf8strlen,(const char *a),(a),return)
diff -r 0ebcca15e978 -r 6e24dc7c67c6 src/stdlib/SDL_string.c
--- a/src/stdlib/SDL_string.c	Sun May 28 21:50:47 2017 +0200
+++ b/src/stdlib/SDL_string.c	Mon May 29 03:01:05 2017 -0400
@@ -510,6 +510,23 @@
 }
 
 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)
 {
 #if defined(HAVE_STRLCAT)


More information about the commits mailing list