From 7a998aec3a85cc61503f3d036344f3e5b5ae7bac Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 24 Sep 2011 17:43:30 +0000 Subject: [PATCH] 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 - --- compiler/ninl.pas | 10 +++++++--- rtl/inc/compproc.inc | 2 +- rtl/inc/text.inc | 17 ++++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/compiler/ninl.pas b/compiler/ninl.pas index 431b12f4ad..1c69039db0 100644 --- a/compiler/ninl.pas +++ b/compiler/ninl.pas @@ -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)); diff --git a/rtl/inc/compproc.inc b/rtl/inc/compproc.inc index 82524fe615..c82cf74808 100644 --- a/rtl/inc/compproc.inc +++ b/rtl/inc/compproc.inc @@ -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; diff --git a/rtl/inc/text.inc b/rtl/inc/text.inc index be268bca31..6675403595 100644 --- a/rtl/inc/text.inc +++ b/rtl/inc/text.inc @@ -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;