[fpc-pascal] Weird string behavior
Jonas Maebe
jonas.maebe at elis.ugent.be
Sat Jul 23 12:20:04 CEST 2016
On 23/07/16 12:13, Jonas Maebe wrote:
> On 23/07/16 08:11, Mattias Gaertner wrote:
>> Here is a result of Delphi 10.1:
>
> Thank you (also Petr). Maybe one more, to know what happens if you mix
> rawbytestring and ansistring in the concatenation:
>
> program DTestConcatenate;
>
> {$APPTYPE CONSOLE}
>
> {$R *.res}
>
> uses
> System.SysUtils;
>
> var
> s1,s2,s3: AnsiString;
> r1,r2,r3: RawByteString;
> begin
> s1:='A'; // 1252
> s2:='AƤ'; // 1252
> writeln('s1="',s1,'" cp=',StringCodePage(s1));
> writeln('s2="',s1,'" cp=',StringCodePage(s2));
> r1:=AnsiToUTF8(s1); // 65001
> r2:=AnsiToUTF8(s2); // 65001
> writeln('r1="',r1,'" cp=',StringCodePage(r1));
> writeln('r2="',r2,'" cp=',StringCodePage(r2));
>
> r3:=s1+r2; // ??
> writeln('r3="',r3,'" cp=',StringCodePage(r3));
> r3:=r1+s2; // ??
> writeln('r3="',r3,'" cp=',StringCodePage(r3));
>
>
> s3:=s1+r2; // ??
> writeln('r3="',r3,'" cp=',StringCodePage(r3));
> s3:=r1+s2; // ??
> writeln('r3="',r3,'" cp=',StringCodePage(r3));
Some copy paste errors in the last four lines, that should be
s3:=s1+r2; // ??
writeln('s3="',s3,'" cp=',StringCodePage(s3));
s3:=r1+s2; // ??
writeln('s3="',s3,'" cp=',StringCodePage(s3));
And maybe also (to check whether there is a difference depending on the
actual code page):
setstringcodepage(rawbytestring(s1),65001,true);
r3:=s1+r2; // ??
writeln('r3="',r3,'" cp=',StringCodePage(r3));
r3:=r1+s1; // ??
writeln('r3="',r3,'" cp=',StringCodePage(r3));
s3:=s1+r2; // ??
writeln('s3="',s3,'" cp=',StringCodePage(s3));
s3:=r1+s2; // ??
writeln('s3="',s3,'" cp=',StringCodePage(s3));
Jonas
More information about the fpc-pascal
mailing list