Charset handling fixes by ACBr

git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@252 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
geby 2022-01-14 15:11:18 +00:00
parent 948daf7b74
commit aa1fdbacc4
2 changed files with 24 additions and 12 deletions

View File

@ -72,6 +72,11 @@ Internal routines knows all major charsets for Europe or America. For East-Asian
{$WARN IMPLICIT_STRING_CAST_LOSS OFF}
{$ENDIF}
{$IFDEF NEXTGEN}
{$LEGACYIFEND ON}
{$ZEROBASEDSTRINGS OFF}
{$ENDIF}
unit synachar;
interface
@ -89,7 +94,7 @@ uses
Windows,
{$ENDIF}
SysUtils,
synautil, synacode, synaicnv;
synautil, synacode, synaicnv, synafpc;
type
{:Type with all supported charsets.}
@ -1380,6 +1385,9 @@ var
NotNeedTransform: Boolean;
FromID, ToID: string;
begin
if not synaicnv.InitIconvInterface then
DisableIconv := True;
NotNeedTransform := (High(TransformTable) = 0);
if (CharFrom = CharTo) and NotNeedTransform then
begin
@ -1508,7 +1516,11 @@ begin
{$IFNDEF POSIX}
Result := GetCPFromID(nl_langinfo(_NL_CTYPE_CODESET_NAME));
{$ELSE}
{$IFNDEF ANDROID}
Result := GetCPFromID(nl_langinfo(CODESET));
{$ELSE}
Result := UTF_8;
{$ENDIF}
{$ENDIF}
{$ELSE}
//How to get system codepage without LIBC?

View File

@ -105,9 +105,9 @@ type
var
iconvLibHandle: TLibHandle = 0;
function SynaIconvOpen(const tocode, fromcode: Ansistring): iconv_t;
function SynaIconvOpenTranslit(const tocode, fromcode: Ansistring): iconv_t;
function SynaIconvOpenIgnore(const tocode, fromcode: Ansistring): iconv_t;
function SynaIconvOpen(const tocode, fromcode: AnsiString): iconv_t;
function SynaIconvOpenTranslit(const tocode, fromcode: AnsiString): iconv_t;
function SynaIconvOpenIgnore(const tocode, fromcode: AnsiString): iconv_t;
function SynaIconv(cd: iconv_t; inbuf: AnsiString; var outbuf: AnsiString): integer;
function SynaIconvClose(var cd: iconv_t): integer;
function SynaIconvCtl(cd: iconv_t; request: integer; argument: argptr): integer;
@ -152,7 +152,7 @@ uses SyncObjs;
{$ELSE}
type
Ticonv_open = function(tocode: pAnsichar; fromcode: pAnsichar): iconv_t; cdecl;
Ticonv_open = function(tocode: PAnsiChar; fromcode: PAnsiChar): iconv_t; cdecl;
Ticonv = function(cd: iconv_t; var inbuf: pointer; var inbytesleft: size_t;
var outbuf: pointer; var outbytesleft: size_t): size_t; cdecl;
Ticonv_close = function(cd: iconv_t): integer; cdecl;
@ -169,7 +169,7 @@ var
IconvCS: TCriticalSection;
Iconvloaded: boolean = false;
function SynaIconvOpen (const tocode, fromcode: Ansistring): iconv_t;
function SynaIconvOpen (const tocode, fromcode: AnsiString): iconv_t;
begin
{$IFDEF CIL}
try
@ -186,12 +186,12 @@ begin
{$ENDIF}
end;
function SynaIconvOpenTranslit (const tocode, fromcode: Ansistring): iconv_t;
function SynaIconvOpenTranslit (const tocode, fromcode: AnsiString): iconv_t;
begin
Result := SynaIconvOpen(tocode + '//IGNORE//TRANSLIT', fromcode);
end;
function SynaIconvOpenIgnore (const tocode, fromcode: Ansistring): iconv_t;
function SynaIconvOpenIgnore (const tocode, fromcode: AnsiString): iconv_t;
begin
Result := SynaIconvOpen(tocode + '//IGNORE', fromcode);
end;
@ -296,10 +296,10 @@ begin
if (IconvLibHandle <> 0) then
begin
{$IFNDEF CIL}
_iconv_open := GetProcAddress(IconvLibHandle, PAnsiChar(AnsiString('libiconv_open')));
_iconv := GetProcAddress(IconvLibHandle, PAnsiChar(AnsiString('libiconv')));
_iconv_close := GetProcAddress(IconvLibHandle, PAnsiChar(AnsiString('libiconv_close')));
_iconvctl := GetProcAddress(IconvLibHandle, PAnsiChar(AnsiString('libiconvctl')));
_iconv_open := GetProcAddress(IconvLibHandle, PChar('libiconv_open'));
_iconv := GetProcAddress(IconvLibHandle, PChar('libiconv'));
_iconv_close := GetProcAddress(IconvLibHandle, PChar('libiconv_close'));
_iconvctl := GetProcAddress(IconvLibHandle, PChar('libiconvctl'));
{$ENDIF}
Result := True;
Iconvloaded := True;