compiler, rtl: add a codepage argument fpc_Read_Text_AnsiStr to create new AnsiString with the codepage of passed AnsiString argument

git-svn-id: trunk@19210 -
This commit is contained in:
paul 2011-09-24 17:43:30 +00:00
parent 00396da30c
commit 7a998aec3a
3 changed files with 18 additions and 11 deletions

View File

@ -746,11 +746,15 @@ implementation
end;
{ indexpara.right:=lenpara;}
end;
{ in case of writing a chararray, add whether it's }
{ zero-based }
{ in case of writing a chararray, add whether it's zero-based }
if para.left.resultdef.typ=arraydef then
para := ccallparanode.create(cordconstnode.create(
ord(tarraydef(para.left.resultdef).lowrange=0),pasbool8type,false),para);
ord(tarraydef(para.left.resultdef).lowrange=0),pasbool8type,false),para)
else
{ in case of reading an ansistring pass a codepage argument }
if do_read and is_ansistring(para.left.resultdef) then
para:=ccallparanode.create(cordconstnode.create(
tstringdef(para.left.resultdef).encoding,u16inttype,true),para);
{ create the call statement }
addstatement(Tstatementnode(newstatement),
ccallnode.createintern(name,para));

View File

@ -571,7 +571,7 @@ Procedure fpc_Read_Text_ShortStr(var f : Text;out s : String); compilerproc;
Procedure fpc_Read_Text_PChar_As_Pointer(var f : Text; const s : PChar); compilerproc;
Procedure fpc_Read_Text_PChar_As_Array(var f : Text;out s : array of char; zerobased: boolean = false); compilerproc;
{$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
Procedure fpc_Read_Text_AnsiStr(var f : Text;out s : AnsiString); compilerproc;
Procedure fpc_Read_Text_AnsiStr(var f : Text;out s : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}); compilerproc;
{$endif FPC_HAS_FEATURE_ANSISTRINGS}
{$ifdef FPC_HAS_FEATURE_WIDESTRINGS}
Procedure fpc_Read_Text_UnicodeStr(var f : Text;out us : UnicodeString); compilerproc;

View File

@ -1288,22 +1288,25 @@ End;
{$ifdef FPC_HAS_FEATURE_ANSISTRINGS}
Procedure fpc_Read_Text_AnsiStr(var f : Text;out s : AnsiString); [public, alias: 'FPC_READ_TEXT_ANSISTR']; iocheck; compilerproc;
Procedure fpc_Read_Text_AnsiStr(var f : Text;out s : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}); [public, alias: 'FPC_READ_TEXT_ANSISTR']; iocheck; compilerproc;
var
slen,len : SizeInt;
Begin
slen:=0;
Repeat
// SetLength will reallocate the length.
SetLength(S,slen+255);
len:=ReadPCharLen(f,pchar(Pointer(S)+slen),255);
SetLength(s,slen+255);
len:=ReadPCharLen(f,pchar(Pointer(s)+slen),255);
inc(slen,len);
Until len<255;
// Set actual length
SetLength(S,Slen);
SetLength(s,Slen);
{$ifdef FPC_HAS_CPSTRING}
SetCodePage(s,cp,false);
{$endif FPC_HAS_CPSTRING}
End;
Procedure fpc_Read_Text_AnsiStr_Intern(var f : Text;out s : AnsiString); [external name 'FPC_READ_TEXT_ANSISTR'];
Procedure fpc_Read_Text_AnsiStr_Intern(var f : Text;out s : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}); [external name 'FPC_READ_TEXT_ANSISTR'];
{$endif FPC_HAS_FEATURE_ANSISTRINGS}
@ -1313,7 +1316,7 @@ var
s: AnsiString;
Begin
// all standard input is assumed to be ansi-encoded
fpc_Read_Text_AnsiStr_Intern(f,s);
fpc_Read_Text_AnsiStr_Intern(f,RawByteString(s){$ifdef FPC_HAS_CPSTRING},DefaultSystemCodePage{$endif FPC_HAS_CPSTRING});
// Convert to unicodestring
us:=s;
End;
@ -1325,7 +1328,7 @@ var
s: AnsiString;
Begin
// all standard input is assumed to be ansi-encoded
fpc_Read_Text_AnsiStr_Intern(f,s);
fpc_Read_Text_AnsiStr_Intern(f,RawByteString(s){$ifdef FPC_HAS_CPSTRING},DefaultSystemCodePage{$endif FPC_HAS_CPSTRING});
// Convert to widestring
ws:=s;
End;