typeless utf8-literal causes bugs
Original Reporter info from Mantis: nanobit @nanobit
-
Reporter name:
Original Reporter info from Mantis: nanobit @nanobit
- Reporter name:
Description:
The typed literal works, the typeless literal is buggy.
const utf8Literal: string = 'src'#$C2#$A9#$C2#$B1; // ok
const utf8Literal = 'src'#$C2#$A9#$C2#$B1; // buggy
Steps to reproduce:
{$mode delphi}
{$codepage utf8}
interface
uses
Classes, SysUtils;
implementation
procedure assertCp( const s: rawByteString; sameCp: word);
var cp: word;
begin
cp := stringCodePage(s);
assert( cp = sameCp);
end;
procedure assertLen( const s: rawByteString; sameL: integer);
var L: integer;
begin
L := length(s);
assert( L = sameL);
end;
begin
const cp256 = 1251;
type tstring256 = type ansistring(cp256);
//const utf8Literal: string = 'src'#C2#
A9#C2#
B1; // ok
const utf8Literal = 'src'#C2#
A9#C2#
B1; // buggy
var
wideStr: unicodeString;
ctm256Str: tstring256;
begin
assertCp( utf8Literal, cp_utf8); // always ok
wideStr := utf8Literal; // conversion to shorter string
assertLen( utf8Literal, length( wideStr)+2); // always ok (7,7)
assertLen( utf8Literal, length( unicodeString(utf8Literal))+2); // ok (7,7), bug (7,9)
ctm256Str := utf8Literal; // conversion to shorter string
assertCp( ctm256Str, cp256); // always ok
assertLen( ctm256Str, length( wideStr)); // ok (5,5), bug (7,7)
assertLen( ctm256Str, length( utf8Literal)-2); // ok (5,5), bug( 7,5)
Mantis conversion info:
- Mantis ID: 34674
- OS: Windows
- OS Build: 10
- Platform: win32
- Version: 3.0.4