Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-12

StringList encoding question

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

Consider this code:

{$codepage utf8}
{$mode objfpc}
{$H+}
uses
  SysUtils, Classes;
var
  SL: TSTringList;
  S: String;
begin
  writeln('DefaultSystemCodePage = ',DefaultSystemCodePage);
  SL := TStringList.Create;
  {$if fpc_fullversion > 30200}
  SL.WriteBom := False;
  {$endif}
  SL.SkipLastLineBreak := True;
  S := 'ä';  //S has CodePage CP_UTF8
  SL.Add(S);
  SL.SaveToFile('slU.txt'{$if fpc_fullversion > 30200}, TEncoding.UTF8{$endif});
  SL.SaveToFile('slA.txt'{$if fpc_fullversion > 30200}, TEncoding.ANSI{$endif});
  SL.Free;
end.

Tested with fpc trunk (form a few days ago).
It outputs:
DefaultSystemCodePage = 1252 (I'm on Windows as you might have guessed) The file slA.txt contains the bytes C3 A4 (which is ä in UTF8 encoding) The file slU.txt contains the bytes C3 83 C2 A4

I struggle to understand why.
What is the codepage of the stringlist's internal list of strings (array of TStringItem's)?
It seems that the stringlist considers it's internal TStringItem.FString that has #$C3A#$A4 to have a codepage of CP_ACP (always)?

Bart

Bart