Conversion of a UTF8 String sometimes buggy

Original Reporter info from Mantis: Michl @michl1
  • Reporter name: Michl

Description:

The conversion from WideString to the system string is wrong.

Steps to reproduce:

Make a simple program:

program project1;

uses sysutils;

procedure Output(s: String);
var
  i: Integer;
  sd: String;
begin
  sd := '';
  for i := 1 to Length(s) do
    sd := sd + IntToHex(Byte(s[i]), 2) + ' ';
  writeln(s, ' - ', sd);
end;

var
  ws: WideString;
  s: String;

begin
  s := 'Größe ÄÜÖ';
  ws := UTF8Decode(s);
  Output(s);
  s := UTF8Encode(ws);
  Output(s);
  s := '';
  Insert(UTF8Encode(ws), s, 1);
  Output(s);
end.

The output is:

GröÃYe Ã"ÃoÃ- - 47 72 C3 B6 C3 9F 65 20 C3 84 C3 9C C3 96
Größe ÄÜÖ - 47 72 C3 B6 C3 9F 65 20 C3 84 C3 9C C3 96
GröÃYe Ã"ÃoÃ- - 47 72 C3 B6 C3 9F 65 20 C3 84 C3 9C C3 96

The first and the third output are correct, the second not.

You can also try the added project.

Additional information:

There are some related bug reports on that issue:
#0028815, #0028406, #0026453

Mantis conversion info:

  • Mantis ID: 28850
  • Build: 31957
  • Platform: Windows7
  • Version: 3.1.1
  • Fixed in version: 3.1.1
  • Fixed in revision: 1242 (#f7c418dc)
  • Monitored by: » @zbyna (zbyna), » @flyingsheep (Bart Broersma)
  • Target version: 3.1.1