Browse Source

stdlib: Export some Unicode functions to other SDL internals.

Ryan C. Gordon 1 year ago
parent
commit
810656962c
2 changed files with 40 additions and 4 deletions
  1. 6 4
      src/stdlib/SDL_string.c
  2. 34 0
      src/stdlib/SDL_sysstdlib.h

+ 6 - 4
src/stdlib/SDL_string.c

@@ -28,6 +28,8 @@
 #include <psp2/kernel/clib.h>
 #endif
 
+#include "SDL_sysstdlib.h"
+
 #include "SDL_casefolding.h"
 
 // this is the Unicode REPLACEMENT CHARACTER, used for invalid codepoint values.
@@ -44,7 +46,7 @@ SDL_COMPILE_TIME_ASSERT(sizeof_wchar_t, sizeof(wchar_t) == SDL_SIZEOF_WCHAR_T);
 
 
 // this expects `from` and `to` to be UTF-32 encoding!
-static int SDL_UnicodeCaseFold(const Uint32 from, Uint32 *to)
+int SDL_CaseFoldUnicode(const Uint32 from, Uint32 *to)
 {
     // !!! FIXME: since the hashtable is static, maybe we should binary
     // !!! FIXME: search it instead of walking the whole bucket.
@@ -127,7 +129,7 @@ static int SDL_UnicodeCaseFold(const Uint32 from, Uint32 *to)
             cp1 = folded1[tail1++]; \
         } else { \
             const Uint##bits *str1start = (const Uint##bits *) str1; \
-            head1 = SDL_UnicodeCaseFold(SDL_StepUTF##bits(&str1, slen1), folded1); \
+            head1 = SDL_CaseFoldUnicode(SDL_StepUTF##bits(&str1, slen1), folded1); \
             update_slen1; \
             cp1 = folded1[0]; \
             tail1 = 1; \
@@ -136,7 +138,7 @@ static int SDL_UnicodeCaseFold(const Uint32 from, Uint32 *to)
             cp2 = folded2[tail2++]; \
         } else { \
             const Uint##bits *str2start = (const Uint##bits *) str2; \
-            head2 = SDL_UnicodeCaseFold(SDL_StepUTF##bits(&str2, slen2), folded2); \
+            head2 = SDL_CaseFoldUnicode(SDL_StepUTF##bits(&str2, slen2), folded2); \
             update_slen2; \
             cp2 = folded2[0]; \
             tail2 = 1; \
@@ -152,7 +154,7 @@ static int SDL_UnicodeCaseFold(const Uint32 from, Uint32 *to)
     return 0
 
 
-static Uint32 SDL_StepUTF8(const char **_str, const size_t slen)
+Uint32 SDL_StepUTF8(const char **_str, const size_t slen)
 {
     const char *str = *_str;
     const Uint32 octet = (Uint32) (slen ? ((Uint8) *str) : 0);

+ 34 - 0
src/stdlib/SDL_sysstdlib.h

@@ -0,0 +1,34 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_sysstdlib_h_
+#define SDL_sysstdlib_h_
+
+// most things you might need internally in here are public APIs, this is
+// just a few special pieces right now.
+
+Uint32 SDL_StepUTF8(const char **_str, const size_t slen);
+
+// this expects `from` to be a Unicode codepoint, and `to` to point to AT LEAST THREE Uint32s.
+int SDL_CaseFoldUnicode(const Uint32 from, Uint32 *to);
+
+#endif
+