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

Sven Barth pascaldragon at googlemail.com
Wed Jan 8 20:56:09 CET 2014


On 08.01.2014 19:57, Hans-Peter Diettrich wrote:
> 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 :-(

I'm inclined to say "of course", because in your "test" function you are 
concatenating two RawByteStrings which - by definition - don't do any 
conversion.

Regards,
Sven



More information about the fpc-devel mailing list