[fpc-devel] Encoded AnsiString

Hans-Peter Diettrich DrDiettrich1 at aol.com
Mon Dec 30 02:07:41 CET 2013


Sven Barth schrieb:

[...]
> This was tested using Delphi XE (it might not compile though as I've 
> just rewritten the code from memory as the original is on a different 
> computer)

Thanks, the code is okay, and it produces the expected results. The 
compiler also warns about a downcast from 'string' to 'RawByteString'.

Then I tested some adds:

When s1+s2 is assigned to an UTF-8 variable, the compiler also warns 
about an downcast from 'string' to 'UTF8String', and that's ridiculous. 
Either the conversion from UTF-16 to UTF-8 is flawed, or the warning is 
wrong.

When I write a
   function conc(s1,s2: RawByteString): RawByteString;
   begin Result := s1+s2; end;
then
   test(conc(s1,s2));
detects CP 65001 (UTF-8)!

The same when conc is redeclared as
   function conca(s1,s2: RawByteString): AnsiString;
   begin Result := s1+s2; end;
also detects CP 65001 (UTF-8), where the function should return a CP_ACP 
(1251) result.

BTW both conc and conca do not produce compiler warnings.


Do you think that FPC should really reproduce all this inconsistent 
behaviour? Who would test or even specify the compatible behaviour, when 
every new variation will result in more unexpected results? IMO it's 
much easier to do it right, and fix the Delphi flaws in FPC.

DoDi




More information about the fpc-devel mailing list