[fpc-devel] assign constant text to widestring

Daniël Mantione daniel.mantione at freepascal.org
Thu Oct 23 10:39:54 CEST 2008



Op Thu, 23 Oct 2008, schreef Michael Schnell:

>
>> Then you don't understand it yet, I think. 
> May be....
>> If the compiler knows your source file is UTF-8 (by BOM or directive), the 
>> compiler generates a widestring constant and no conversion function is 
>> called when assigning to a widestring.
> In my test the source code is not UTF8 but UCS2 and does have a correct BOM. 
> The compiler does work correctly with that and (it seems to be designed that 
> way) converts the string constant source UCS2->UTF8, supposedly temporarily 
> assigning a type like UTF8String to the constant. As the compiler is not 
> aware of the type UTDF8String and errineously identifies it with ANSIString, 
> now the resulting code interprets the constant as ANSIString and the 
> conversion to WideString results in a false text.

No no, a string with unicode characters is interpreted by the compiler as 
widestring constant, never as UTF-8 ansistring constant. If it does 
otherwise, the compiler probably does not interpret your source code as 
Unicode.

The issue might be the UCS-2 encoding of your source, perhaps try to feed 
the compiler UTF-8, I didn't even know the compiler accepts UCS-2, it may 
not work correctly.

Daniël


More information about the fpc-devel mailing list