Browse Source

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 -
paul 14 years ago
parent
commit
7a998aec3a
3 changed files with 18 additions and 11 deletions
  1. 7 3
      compiler/ninl.pas
  2. 1 1
      rtl/inc/compproc.inc
  3. 10 7
      rtl/inc/text.inc

+ 7 - 3
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));

+ 1 - 1
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;

+ 10 - 7
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;