* implemented recommendations from mantis #038510 for better bionic

compatibility.

git-svn-id: trunk@49167 -
This commit is contained in:
marco 2021-04-10 14:58:53 +00:00
parent 763d287af4
commit b2afecdae5

View File

@ -14,7 +14,7 @@ var
iconvres: size_t; iconvres: size_t;
begin begin
H := iconv_open(PChar(ToEncoding), PChar(FromEncoding)); H := iconv_open(PChar(ToEncoding), PChar(FromEncoding));
if not assigned(H) then if h=Iconv_t(-1) then
begin begin
Res := S; Res := S;
exit(-1); exit(-1);
@ -48,7 +48,8 @@ begin
Dst:=PChar(Res)+Offset; Dst:=PChar(Res)+Offset;
OutLen:=Length(Res)-Offset; OutLen:=Length(Res)-Offset;
end; end;
iconvres:=iconv(H, nil, nil, @Dst, @Outlen); InLen=0;
iconvres:=iconv(H, nil, @InLen, @Dst, @Outlen);
if iconvres = size_t(-1) then if iconvres = size_t(-1) then
begin begin
res:=s; res:=s;
@ -91,7 +92,8 @@ begin
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char
Dst:=PChar(Res)+Offset; Dst:=PChar(Res)+Offset;
OutLen:=Length(Res)-Offset; OutLen:=Length(Res)-Offset;
iconv(H, nil, nil, @Dst, @Outlen); InLen:=0;
iconv(H, nil, @InLen, @Dst, @Outlen);
end; end;
{$endif} {$endif}
// trim output buffer // trim output buffer
@ -101,7 +103,8 @@ begin
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char
Dst:=PChar(Res)+Offset; Dst:=PChar(Res)+Offset;
OutLen:=Length(Res)-Offset; OutLen:=Length(Res)-Offset;
iconvres:=iconv(H, nil, nil, @Dst, @Outlen); InLen:=0;
iconvres:=iconv(H, nil, @InLen, @Dst, @Outlen);
setlength(Res,Length(Res) - Outlen); setlength(Res,Length(Res) - Outlen);
iconv_close(H); iconv_close(H);
end; end;