[fpc-devel] simple UTF tests

Sven Barth pascaldragon at googlemail.com
Thu Jan 5 14:40:07 CET 2012


Am 05.01.2012 14:30, schrieb Sven Barth:
> Am 05.01.2012 12:32, schrieb Marco van de Voort:
>> In our previous episode, Michael Schnell said:
>>> With Lazarus on Linux, I did some simple tests with UTF strings.
>>>
>>> I found that the length of an "AnsiString(CP_UTF16)" is given in terms
>>> of bytes and not of Words. Is this like it should ?
>>
>> Yes. Afaik that is not a sane combination, but Delphi compatible.
>>
>
> AFAIK (I'd need to start Delphi for this) AnsiString(CP_UTF16) is not
> allowed in Delphi.

Ok... one can use the UTF16 code page, but Delphi does NOT define 
CP_UTF16 (I needed to use 1200, which is the code page ID used by 
Microsoft).

And the following code:

type
   TestString = type AnsiString(1200);

var
   s: TestString;
begin
   s := #$3428#$3828;
   Writeln(Length(s));
   Readln;
end;

Writes "0" while the same code with AnsiString(CP_UTF8) writes "6".

Regards,
Sven



More information about the fpc-devel mailing list