[fpc-devel] simple UTF tests

Hans-Peter Diettrich DrDiettrich1 at aol.com
Fri Jan 6 11:42:16 CET 2012


Michael Schnell schrieb:
> On 01/05/2012 12:32 PM, Marco van de Voort wrote:
>> In our previous episode, Michael Schnell said:
>>> 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.
> 
> This really is absolutely insane, as in Delphi (I only have "Turbo"), 
> the length of a WideString is given in terms of word and not of bytes.

This is absolutely sane, because Length() does and always did reflect 
the number of *elements* of an array, and strings are treated like arrays.

> So why introducing major differences in the handling of 16 bit encoded 
> Strings such as
>  - AnsiString(CP_UTF16)  (provided CP_UTF16 is previously defined to be 
> 1200)
This one is not supported by Delphi (XE).

>  - WideString
This one is required for WinAPI compatibility.

>  - UnicodeString (I can't test this)
That's the new generic string type.

- UCS4String
For people who like it ;-)


> I feel that much of the Delphi way of handling the "new string"s is 
> hazardous and not worth mimicking  and better ways can be found - there 
> have been long discussions on this - (while of course for compatibility, 
> it is important to provide the Delphi-way behavior forced by a compiler 
> option).

The Delphi devlopers have learned what's a good and what's a bad 
stringhandling model, based on their experience with the Delphi 
implementation and use. You instead argue based on half-baked ideas, so 
please stay away from calling other models "insane" :-]


> -Michael
> (BTW.: I still don't know whether Delphi even introduces the insanity 
> that when assigning, the auto-conversion is decided regarding the actual 
> internal dynamical encoding of the target or if the target's statically 
> given Type name is always used.)

You should understand the difference between (temporary) strings, used 
in string expression evaluation, and the assignment of an string to a 
strictly typed variable.

DoDi




More information about the fpc-devel mailing list