[fpc-devel] Explanation about code page-aware AnsiStrings

Hans-Peter Diettrich DrDiettrich1 at aol.com
Wed Jan 8 19:57:48 CET 2014


Sven Barth schrieb:
> Am 08.01.2014 15:58 schrieb "Hans-Peter Diettrich" <DrDiettrich1 at aol.com 
> <mailto:DrDiettrich1 at aol.com>>:
>  > Delphi concatenates RawByteStrings to the dynamic encoding of the 
> *first* string, the appended strings eventually are converted before 
> concatenation. Special handling of strings with the same encoding is not 
> required.
>  > I.e. the result is *not* always a CP_ACP string, as documented in the 
> wiki.
> 
> Would you be so kind to provide a simple test case for this? :)

function test(a,b: RawByteString): RawByteString;
begin
   Result := a+b;
   WriteLn(StringCodePage(Result));
end;

var
   u: UTF8String;
   a: AnsiString;
begin
   a := 'äöü';
   u := 'üöä';
   test(a,u);  //CP_ACP
   test(u,a);  //UTF-8
end;

It looks to me, however, that no conversion occurs at all!
The strings are only concatenated as they are.
Same for a concatenation of (global) RawByteString variables.

This of course were not a desireable implementation :-(

DoDi




More information about the fpc-devel mailing list