mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-26 01:29:18 +02:00
* PChar -> PAnsiChar
This commit is contained in:
parent
54292a28aa
commit
2bca50e10a
@ -23,15 +23,16 @@ uses
|
||||
iconvenc;
|
||||
|
||||
// some random Hebrew string for testing in CP1255
|
||||
Const InputString : array[0..21] of char =
|
||||
Const InputString : array[0..21] of AnsiChar =
|
||||
(#$e0,#$e1,#$e2,#$e3,#$e4,#$e5,#$e6,#$e7,
|
||||
#$e8,#$e9,#$eb,#$ec,#$ee,#$f0,#$f1,#$f2,
|
||||
#$f4,#$f6,#$f7,#$f8,#$f9,#$fa);
|
||||
InputEncoding = 'CP1255';
|
||||
|
||||
procedure DoOneConversion(TargetEncoding:string);
|
||||
procedure DoOneConversion(TargetEncoding:AnsiString);
|
||||
var
|
||||
fn,res: string;
|
||||
fn : String;
|
||||
res: Ansistring;
|
||||
f1:text;
|
||||
convres: integer;
|
||||
begin
|
||||
|
@ -35,8 +35,8 @@ type
|
||||
piconv_t = ^iconv_t;
|
||||
iconv_t = pointer;
|
||||
|
||||
Ticonv_open = function(__tocode: pchar; __fromcode: pchar): iconv_t; cdecl;
|
||||
Ticonv = function(__cd: iconv_t; __inbuf: ppchar; __inbytesleft: psize_t; __outbuf: ppchar; __outbytesleft: psize_t): size_t; cdecl;
|
||||
Ticonv_open = function(__tocode: PAnsiChar; __fromcode: PAnsiChar): iconv_t; cdecl;
|
||||
Ticonv = function(__cd: iconv_t; __inbuf: PPAnsiChar; __inbytesleft: psize_t; __outbuf: PPAnsiChar; __outbytesleft: psize_t): size_t; cdecl;
|
||||
Ticonv_close = function(__cd: iconv_t): cint; cdecl;
|
||||
|
||||
{$if not defined(linux) and not defined(solaris)} // Linux (and maybe glibc pl
|
||||
@ -65,19 +65,19 @@ Const
|
||||
iconvprefix='';
|
||||
{$endif}
|
||||
|
||||
function iconv_open(__tocode: pchar; __fromcode: pchar): iconv_t; cdecl; external libiconvname name iconvprefix+'iconv_open';
|
||||
function iconv (__cd: iconv_t; __inbuf: ppchar; __inbytesleft: psize_t; __outbuf: ppchar; __outbytesleft: psize_t): size_t; cdecl; external libiconvname name iconvprefix+'iconv';
|
||||
function iconv_open(__tocode: PAnsiChar; __fromcode: PAnsiChar): iconv_t; cdecl; external libiconvname name iconvprefix+'iconv_open';
|
||||
function iconv (__cd: iconv_t; __inbuf: PPAnsiChar; __inbytesleft: psize_t; __outbuf: PPAnsiChar; __outbytesleft: psize_t): size_t; cdecl; external libiconvname name iconvprefix+'iconv';
|
||||
function iconv_close (__cd: iconv_t): cint; cdecl; external libiconvname name iconvprefix+'iconv_close';
|
||||
|
||||
var
|
||||
IconvLibFound: boolean = False;
|
||||
|
||||
function Iconvert(s: string; var res: string; const FromEncoding, ToEncoding: string): cint;
|
||||
function InitIconv(var error: string): boolean;
|
||||
function Iconvert(s: AnsiString; var res: AnsiString; const FromEncoding, ToEncoding: AnsiString): cint;
|
||||
function InitIconv(var error: String): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function InitIconv(var error: string): boolean;
|
||||
function InitIconv(var error:String ): boolean;
|
||||
begin
|
||||
result := true;
|
||||
iconvlibfound := iconvlibfound or result;
|
||||
|
@ -35,8 +35,8 @@ type
|
||||
piconv_t = ^iconv_t;
|
||||
iconv_t = pointer;
|
||||
|
||||
Ticonv_open = function(__tocode: pchar; __fromcode: pchar): iconv_t; cdecl;
|
||||
Ticonv = function(__cd: iconv_t; __inbuf: ppchar; __inbytesleft: psize_t; __outbuf: ppchar; __outbytesleft: psize_t): size_t; cdecl;
|
||||
Ticonv_open = function(__tocode: PAnsiChar; __fromcode: PAnsiChar): iconv_t; cdecl;
|
||||
Ticonv = function(__cd: iconv_t; __inbuf: PPAnsiChar; __inbytesleft: psize_t; __outbuf: PPAnsiChar; __outbytesleft: psize_t): size_t; cdecl;
|
||||
Ticonv_close = function(__cd: iconv_t): cint; cdecl;
|
||||
|
||||
var
|
||||
@ -46,17 +46,17 @@ var
|
||||
iconv_close: Ticonv_close;
|
||||
IconvLibFound: boolean = False;
|
||||
|
||||
function TryLoadLib(LibName: string; var error: string): boolean; // can be used to load non standard libname
|
||||
function Iconvert(s: string; var res: string; const FromEncoding, ToEncoding: string): cint;
|
||||
function InitIconv(var error: string): boolean;
|
||||
function TryLoadLib(LibName: string; var error: String): boolean; // can be used to load non standard libname
|
||||
function Iconvert(s: AnsiString; var res: AnsiString; const FromEncoding, ToEncoding: AnsiString): cint;
|
||||
function InitIconv(var error: AnsiString): boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function TryLoadLib(LibName: string; var error: string): boolean;
|
||||
function TryLoadLib(LibName: string; var error: String): boolean;
|
||||
|
||||
function resolvesymbol (var funcptr; symbol: string): Boolean;
|
||||
begin
|
||||
pointer(funcptr) := pointer(dlsym(iconv_lib, pchar(symbol)));
|
||||
pointer(funcptr) := pointer(dlsym(iconv_lib, PAnsiChar(symbol)));
|
||||
result := assigned(pointer(funcptr));
|
||||
if not result then
|
||||
error := error+#13#10+dlerror();
|
||||
@ -67,7 +67,7 @@ var
|
||||
begin
|
||||
result := false;
|
||||
Error := Error+#13#10'Trying '+LibName;
|
||||
iconv_lib := dlopen(pchar(libname), RTLD_NOW);
|
||||
iconv_lib := dlopen(PAnsiChar(libname), RTLD_NOW);
|
||||
if Assigned(iconv_lib) then
|
||||
begin
|
||||
result := true;
|
||||
@ -88,7 +88,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function InitIconv(var error: string): boolean;
|
||||
function InitIconv(var error: ): boolean;
|
||||
begin
|
||||
result := true;
|
||||
error := '';
|
||||
|
@ -3,17 +3,17 @@
|
||||
{$define noerrnoiconv}
|
||||
{$endif}
|
||||
|
||||
function Iconvert(S: string; var Res: string; const FromEncoding, ToEncoding: string): cint;
|
||||
function Iconvert(S: AnsiString; var Res: AnsiString; const FromEncoding, ToEncoding: AnsiString): cint;
|
||||
var
|
||||
InLen, OutLen, Offset: size_t;
|
||||
Src, Dst: pchar;
|
||||
Src, Dst: PAnsiChar;
|
||||
H: iconv_t;
|
||||
{$ifndef noerrnoiconv}
|
||||
lerr: cint;
|
||||
{$endif}
|
||||
iconvres: size_t;
|
||||
begin
|
||||
H := iconv_open(PChar(ToEncoding), PChar(FromEncoding));
|
||||
H := iconv_open(PAnsiChar(ToEncoding), PAnsiChar(FromEncoding));
|
||||
if h=Iconv_t(-1) then
|
||||
begin
|
||||
Res := S;
|
||||
@ -30,8 +30,8 @@ begin
|
||||
{$endif}
|
||||
setlength(res,outlen);
|
||||
|
||||
Src := PChar(S);
|
||||
Dst := PChar(Res);
|
||||
Src := PAnsiChar(S);
|
||||
Dst := PAnsiChar(Res);
|
||||
|
||||
|
||||
{$ifdef noerrnoiconv}
|
||||
@ -43,9 +43,9 @@ begin
|
||||
end;
|
||||
if outlen<8 then // From PHP, URL above, see also PHP bug 55042 (they didn't recalc their "dest")
|
||||
begin
|
||||
Offset:=Dst-PChar(Res);
|
||||
SetLength(Res, Length(Res)+8); // 5 is minimally one utf-8 char
|
||||
Dst:=PChar(Res)+Offset;
|
||||
Offset:=Dst-PAnsiChar(Res);
|
||||
SetLength(Res, Length(Res)+8); // 5 is minimally one utf-8 AnsiChar
|
||||
Dst:=PAnsiChar(Res)+Offset;
|
||||
OutLen:=Length(Res)-Offset;
|
||||
end;
|
||||
InLen=0;
|
||||
@ -62,7 +62,7 @@ begin
|
||||
if iconvres = size_t(-1) then
|
||||
begin
|
||||
lerr := cerrno;
|
||||
if lerr = ESysEILSEQ then // unknown char, skip
|
||||
if lerr = ESysEILSEQ then // unknown AnsiChar, skip
|
||||
begin
|
||||
Dst^ := Src^;
|
||||
Inc(Src);
|
||||
@ -73,9 +73,9 @@ begin
|
||||
else
|
||||
if lerr = ESysE2BIG then
|
||||
begin
|
||||
Offset := Dst - PChar(Res);
|
||||
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char
|
||||
Dst := PChar(Res) + Offset;
|
||||
Offset := Dst - PAnsiChar(Res);
|
||||
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 AnsiChar
|
||||
Dst := PAnsiChar(Res) + Offset;
|
||||
OutLen := Length(Res) - Offset;
|
||||
end
|
||||
else
|
||||
@ -83,14 +83,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// iconv has a buffer that needs flushing, specially if the last char is not #0
|
||||
// iconv has a buffer that needs flushing, specially if the last AnsiChar is not #0
|
||||
iconvres:=iconv(H, nil, nil, @Dst, @Outlen);
|
||||
lerr:=cerrno;
|
||||
if (iconvres=size_t(-1)) and (lerr=ESysE2BIG) then
|
||||
begin
|
||||
Offset:=Dst-PChar(Res);
|
||||
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char
|
||||
Dst:=PChar(Res)+Offset;
|
||||
Offset:=Dst-PAnsiChar(Res);
|
||||
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 AnsiChar
|
||||
Dst:=PAnsiChar(Res)+Offset;
|
||||
OutLen:=Length(Res)-Offset;
|
||||
InLen:=0;
|
||||
iconv(H, nil, @InLen, @Dst, @Outlen);
|
||||
@ -99,9 +99,9 @@ begin
|
||||
// trim output buffer
|
||||
SetLength(Res, Length(Res) - Outlen);
|
||||
finally
|
||||
Offset:=Dst-PChar(Res);
|
||||
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char
|
||||
Dst:=PChar(Res)+Offset;
|
||||
Offset:=Dst-PAnsiChar(Res);
|
||||
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 AnsiChar
|
||||
Dst:=PAnsiChar(Res)+Offset;
|
||||
OutLen:=Length(Res)-Offset;
|
||||
InLen:=0;
|
||||
iconvres:=iconv(H, nil, @InLen, @Dst, @Outlen);
|
||||
|
Loading…
Reference in New Issue
Block a user