mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-30 12:11:04 +02:00
* Correct ReadString to be delphi compatible: count is number of characters, not bytes
This commit is contained in:
parent
82a0b7328e
commit
eaf7f8b282
@ -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
|
if BytesLeft<ByteCount then
|
||||||
Count:=BytesLeft;
|
ByteCount:=BytesLeft;
|
||||||
SetLength(B,Count);
|
SetLength(B,ByteCount);
|
||||||
ReadBuffer(B,0,Count);
|
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);
|
||||||
|
@ -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('2 characters','AB',Stream.ReadString(2));
|
||||||
AssertEquals('Top off characters','CDEFGH',Stream.ReadString(22));
|
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;
|
||||||
|
@ -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"/>
|
||||||
|
@ -26,7 +26,7 @@ program testrtl;
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
browserconsole, consoletestrunner, frmrtlrun, simplelinkedlist,
|
browserconsole, consoletestrunner, frmrtlrun, simplelinkedlist,
|
||||||
// tcstream,
|
tcstream,
|
||||||
// tccompstreaming,
|
// tccompstreaming,
|
||||||
// tcsyshelpers,
|
// tcsyshelpers,
|
||||||
// tcgenarrayhelper,
|
// tcgenarrayhelper,
|
||||||
|
Loading…
Reference in New Issue
Block a user