View Issue Details

IDProjectCategoryView StatusLast Update
0006708JEDI Code LibraryJclStringConversionspublic2023-11-11 23:49
ReportermarkjonesnzAssigned ToAHUser 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionVersion 2.5 (Subversion repository/Daily zips) 
Target VersionFixed in VersionVersion 2.5 (Subversion repository/Daily zips) 
Summary0006708: AnsiGetNextCharFromStream gives incorrect results for characters in extended range ($80 - $FF)
DescriptionThe various AnsiGetNextChar* function give different results with FromStream giving a result that is not part of the current ansi code page. With a system code page of 1252 the following gives wrong result
AnsiGetNextCharFromStream(Stream, Ch)

The following however gives the correct result
AnsiGetNextCharFromStream(Stream, 1252, Ch)
Steps To Reproducetype
  String1252 = type AnsiString(1252);
var
  S1, S2, S3, S4 : String1252;
  Ch: UCS4;
  ChArray: TUCS4Array;
  Bytes: TBytes;
  BytesStream: TBytesStream;
  Start: SizeInt;
begin
  DefaultSystemCodePage := 1252;
  S1 := AnsiChar(WideChar($20AC)); //Euro
  assert(PByte(S1)^ = $80, 'Expected $80 for CP1252 Euro character');
  SetLength(Bytes, 1);
  Bytes[0] := PByte(S1)^;
  BytesStream := TBytesStream.Create(Bytes);
  try
    assert(AnsiGetNextCharFromStream(BytesStream, Ch), 'AnsiGetNextCharFromStream failed');
    S2 := UCS4ToAnsiChar(Ch);
    assert(S1 = S2, 'S1 <> S2');

    BytesStream.Position := 0;
    assert(AnsiGetNextCharFromStream(BytesStream, 1252, Ch), 'AnsiGetNextCharFromStream (with CodePage) failed');
    S3 := UCS4ToAnsiChar(Ch);
    assert(S1 = S3, 'S1 <> S3');

    BytesStream.Position := 0;
    SetLength(ChArray, 1);
    Start := 0;
    assert(AnsiGetNextBufferFromStream(BytesStream, ChArray, Start, 1) = 1, 'AnsiGetNextBufferFromStream failed');
    S4 := UCS4ToAnsiChar(ChArray[0]);
    assert(S1 = S4, 'S1 <> S4');
  finally
    BytesStream.Free;
  end;
end;
TagsNo tags attached.
Fixed in GIT commited6f57c303499628c6b43369de6186b21eb57dce
Fixed in SVN revision
IDE versionAll

Activities

markjonesnz

2022-06-01 04:55

reporter   ~0022031

We have finally got application running on a new version of this is giving us some problems. I have gone through the code and found the following line in JclStringConversions is what is causing the problem (line 2649)

UTF16Buffer := WideString(AnsiString(Chr(B)));

And the following seems to fix it

UTF16Buffer := WideString(AnsiString(AnsiChar(B)));

AHUser

2023-11-11 23:49

developer   ~0022061

Already fixed in git main branch.

Issue History

Date Modified Username Field Change
2020-12-21 17:21 markjonesnz New Issue
2022-06-01 04:55 markjonesnz Note Added: 0022031
2023-11-11 23:49 AHUser Assigned To => AHUser
2023-11-11 23:49 AHUser Status new => resolved
2023-11-11 23:49 AHUser Resolution open => fixed
2023-11-11 23:49 AHUser Fixed in Version => Version 2.5 (Subversion repository/Daily zips)
2023-11-11 23:49 AHUser Fixed in GIT commit => ed6f57c303499628c6b43369de6186b21eb57dce
2023-11-11 23:49 AHUser Note Added: 0022061