Go to file
Ryan C. Gordon a5c892d2c3 stdlib: Improve Unicode support and consistency in string comparison functions.
SDL_strcasecmp (even when calling into a C runtime) does not work with
Unicode chars, and depending on the user's locale, might not work with
even basic ASCII strings.

This implements the function from scratch, using "case-folding,"
which is a more robust method that deals with various languages. It
involves a hashtable of a few hundred codepoints that are "uppercase" and
how to map them to lowercase equivalents (possibly increasing the size of
the string in the process). The vast majority of human languages (and
Unicode) do not have letters with different cases, but still, this static
table takes about 10 kilobytes on a 64-bit machine.

Even this will fail in one known case: the Turkish 'i' folds differently
if you're writing in Turkish vs other languages. Generally this is seen as
unfortunate collateral damage in cases where you can't specify the language
in use.

In addition to case-folding the codepoints, the new functions also know how
to decode the various formats to turn them into codepoints in the first
place, instead of blindly stepping by one byte (or one wchar_t) per
character.

Also included is casefolding.txt from the Unicode Consortium and a perl
script to generate the hashtable from that text file, so we can trivially
update this if new languages are added in the future.

A simple test using the new function:

```c
 #include <SDL3/SDL.h>

 int main(void)
 {
     const char *a = "α ε η";
     const char *b = "Α Ε Η";
     SDL_Log("    strcasecmp(\"%s\", \"%s\") == %d\n", a, b, strcasecmp(a, b));
     SDL_Log("SDL_strcasecmp(\"%s\", \"%s\") == %d\n", a, b, SDL_strcasecmp(a, b));
     return 0;
 }
```

Produces:

```
INFO:     strcasecmp("α ε η", "Α Ε Η") == 32
INFO: SDL_strcasecmp("α ε η", "Α Ε Η") == 0
```

glibc strcasecmp() fails to compare a Greek lowercase string to its uppercase
equivalent, even with a UTF-8 locale, but SDL_strcasecmp() works.

Other SDL_stdinc.h functions are changed to be more consistent, which is to
say they now ignore any C runtime and often dictate that only English-based
low-ASCII works with them.

Fixes Issue #9313.
2024-03-29 15:01:40 -04:00
.github dmg: fix SDL_version.h issue in sdl3-config-version.cmake 2024-03-24 20:15:42 +01:00
VisualC Added SDL_HINT_WINDOWS_RAW_KEYBOARD to control whether raw keyboard is enabled on Windows 2024-03-25 20:41:05 -07:00
VisualC-GDK VisualC-GDK: Add missing dialog sources, fix Xbox builds 2024-03-26 07:28:22 -07:00
VisualC-WinRT visualc: filters also contained 2 wrong include headers 2024-03-25 18:02:05 +01:00
Xcode remove non-existent vulkan.hpp and vulkan_mir.h from Xcode project 2024-03-25 21:23:32 +03:00
android-project Updated to version 3.1.0 for the preview release 2024-03-24 06:16:02 -07:00
build-scripts stdlib: Improve Unicode support and consistency in string comparison functions. 2024-03-29 15:01:40 -04:00
cmake cmake: build tests against installed SDL prefix 2024-03-23 21:41:20 +01:00
docs stdlib: Improve Unicode support and consistency in string comparison functions. 2024-03-29 15:01:40 -04:00
include stdlib: Improve Unicode support and consistency in string comparison functions. 2024-03-29 15:01:40 -04:00
mingw/pkg-support mingw: add pkg-support files (INSTALL.txt and Makefile) 2024-03-23 21:41:20 +01:00
src stdlib: Improve Unicode support and consistency in string comparison functions. 2024-03-29 15:01:40 -04:00
test main: Add an optional `appstate` param to main callback entry points. 2024-03-27 17:22:08 -04:00
wayland-protocols wayland: Add the xdg-foreign-unstable-v2 protocol 2024-03-15 18:30:05 -04:00
.clang-format Add 'wl_list_for_each_safe' to the clang-format macro list 2024-03-14 10:22:23 -04:00
.clang-tidy Fix size of memcpy in SDL_AudioDeviceFormatChangedAlreadyLocked 2023-08-05 14:14:45 -04:00
.editorconfig Fixed formatting for Haiku cc files 2023-01-25 03:03:41 -08:00
.gitignore GDK: Remove old shader sources, unify shader compilation .bats 2024-03-02 10:30:29 -08:00
.wikiheaders-options sdlwiki: SDL3 advises users to include through 'SDL3/SDL.h' 2023-03-21 02:19:19 +01:00
Android.mk Add time and realtime clock functions 2024-03-19 10:57:36 -07:00
BUGS.txt Cleaned up a few more Bugzilla mentions. 2021-02-12 14:46:49 -05:00
CMakeLists.txt stdlib: Improve Unicode support and consistency in string comparison functions. 2024-03-29 15:01:40 -04:00
CREDITS.md docs: Moved CREDITS and INSTALL to markdown format. 2023-11-29 12:31:27 -05:00
INSTALL.md docs: Moved CREDITS and INSTALL to markdown format. 2023-11-29 12:31:27 -05:00
LICENSE.txt Updated copyright for 2024 2024-01-01 13:15:26 -08:00
README-SDL.txt More HTTPS changes in the documentation. 2017-02-16 16:52:03 -05:00
README.md Tweaking documentation for the SDL 3.0 preview release 2024-03-24 06:16:02 -07:00
WhatsNew.txt Tweaking documentation for the SDL 3.0 preview release 2024-03-24 06:16:02 -07:00

README.md

Simple DirectMedia Layer (SDL) Version 3.0

https://www.libsdl.org/

Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware. It is used by video playback software, emulators, and popular games including Valve's award winning catalog and many Humble Bundle games.

More extensive documentation is available in the docs directory, starting with README.md. If you are migrating to SDL 3.0 from SDL 2.0, the changes are extensively documented in README-migration.md.

Enjoy!

Sam Lantinga (slouken@libsdl.org)