Skip to content

Commit c089bb2

Browse files
committed
Add functions resembling SDL_iconv_utf8_* macros
1 parent 6c51ec4 commit c089bb2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

units/sdl2.pas

+20
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ interface
203203

204204
implementation
205205

206+
uses Strings;
207+
206208
// Macros from "sdl_version.h"
207209
procedure SDL_VERSION(out x: TSDL_Version);
208210
begin
@@ -427,6 +429,24 @@ function SDL_SHAPEMODEALPHA(mode: TWindowShapeMode): Boolean;
427429
Result := (mode = ShapeModeDefault) or (mode = ShapeModeBinarizeAlpha) or (mode = ShapeModeReverseBinarizeAlpha);
428430
end;
429431

432+
// from "sdl_stdinc.h"
433+
434+
// Note: We're using FPC's Strings.strlen() here, not SDL_strlen().
435+
function SDL_iconv_utf8_locale(str: PAnsiChar): PAnsiChar; cdecl;
436+
begin
437+
Result := SDL_iconv_string('', 'UTF-8', str, Strings.strlen(str)+1)
438+
end;
439+
440+
function SDL_iconv_utf8_ucs2(str: PAnsiChar): pcUint16; cdecl;
441+
begin
442+
Result := pcUint16(SDL_iconv_string('UCS-2-INTERNAL', 'UTF-8', str, Strings.strlen(str)+1))
443+
end;
444+
445+
function SDL_iconv_utf8_ucs4(str: PAnsiChar): pcUint32; cdecl;
446+
begin
447+
Result := pcUint32(SDL_iconv_string('UCS-4-INTERNAL', 'UTF-8', str, Strings.strlen(str)+1))
448+
end;
449+
430450
//from "sdl_video.h"
431451

432452
function SDL_WINDOWPOS_UNDEFINED_DISPLAY(X: Variant): Variant;

units/sdlstdinc.inc

+5
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,8 @@ procedure SDL_free(mem: Pointer); cdecl;
114114
*)
115115
function SDL_iconv_string(tocode, fromcode, inbuf: PAnsiChar; inbytesleft: csize_t): PAnsiChar; cdecl
116116
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_iconv_string' {$ENDIF} {$ENDIF};
117+
118+
// These are macros in the original C headers, we will reimplement them as simple Pascal functions.
119+
function SDL_iconv_utf8_locale(str: PAnsiChar): PAnsiChar; cdecl;
120+
function SDL_iconv_utf8_ucs2(str: PAnsiChar): pcUint16; cdecl;
121+
function SDL_iconv_utf8_ucs4(str: PAnsiChar): pcUint32; cdecl;

0 commit comments

Comments
 (0)