Pārlūkot izejas kodu

* Correct ReadString to be delphi compatible: count is number of characters, not bytes

Michaël Van Canneyt 3 gadi atpakaļ
vecāks
revīzija
eaf7f8b282
5 mainītis faili ar 16 papildinājumiem un 9 dzēšanām
  1. 7 5
      packages/rtl/classes.pas
  2. 0 0
      test/index.html
  3. 7 2
      test/tcstream.pp
  4. 1 1
      test/testrtl.lpi
  5. 1 1
      test/testrtl.lpr

+ 7 - 5
packages/rtl/classes.pas

@@ -1554,16 +1554,18 @@ Var
   B : TBytes;
   B : TBytes;
   Buf : TJSArrayBuffer;
   Buf : TJSArrayBuffer;
   BytesLeft : Integer;
   BytesLeft : Integer;
+  ByteCount : Integer;
 
 
 begin
 begin
   // Top off
   // Top off
+  ByteCount:=Count*2; // UTF-16
   BytesLeft:=(Size-Position);
   BytesLeft:=(Size-Position);
-  if BytesLeft<Count then
-    Count:=BytesLeft;
-  SetLength(B,Count);
-  ReadBuffer(B,0,Count);
+  if BytesLeft<ByteCount then
+    ByteCount:=BytesLeft;
+  SetLength(B,ByteCount);
+  ReadBuffer(B,0,ByteCount);
   Buf:=BytesToMemory(B);
   Buf:=BytesToMemory(B);
-  Result:=BufferToString(Buf,0,Count);
+  Result:=BufferToString(Buf,0,ByteCount);
 end;
 end;
 
 
 procedure TStringStream.WriteString(const AString: string);
 procedure TStringStream.WriteString(const AString: string);

+ 0 - 0
test/testrtl.html → test/index.html


+ 7 - 2
test/tcstream.pp

@@ -167,11 +167,16 @@ procedure TTestStringStream.TestReadString;
 Var
 Var
   S : String;
   S : String;
 
 
+
 begin
 begin
   S:='ABCDEFGH';
   S:='ABCDEFGH';
   DoCreate(S);
   DoCreate(S);
-  AssertEquals('2 characters','AB',Stream.ReadString(4));
-  AssertEquals('Top off characters','CDEFGH',Stream.ReadString(22));
+  AssertEquals('2 characters','AB',Stream.ReadString(2));
+  AssertEquals('Top off characters','CDEFGH',Stream.ReadString(11));
+  S:='Hello World';
+  FreeAndNil(FStream);
+  DoCreate(S);
+  AssertEquals('Correct string',S,Stream.ReadString(Length(S)));
 end;
 end;
 
 
 procedure TTestStringStream.TestWriteString;
 procedure TTestStringStream.TestWriteString;

+ 1 - 1
test/testrtl.lpi

@@ -38,7 +38,7 @@
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
       </Unit>
       </Unit>
       <Unit>
       <Unit>
-        <Filename Value="testrtl.html"/>
+        <Filename Value="index.html"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
         <CustomData Count="1">
         <CustomData Count="1">
           <Item0 Name="PasJSIsProjectHTMLFile" Value="1"/>
           <Item0 Name="PasJSIsProjectHTMLFile" Value="1"/>

+ 1 - 1
test/testrtl.lpr

@@ -26,7 +26,7 @@ program testrtl;
 
 
 uses
 uses
   browserconsole, consoletestrunner, frmrtlrun, simplelinkedlist,
   browserconsole, consoletestrunner, frmrtlrun, simplelinkedlist,
-//  tcstream,
+  tcstream,
 // tccompstreaming,
 // tccompstreaming,
 //  tcsyshelpers,
 //  tcsyshelpers,
 //  tcgenarrayhelper,
 //  tcgenarrayhelper,