setcodepage to cp_none causes concatenation failure (windows only)
Summary
A simple program below illustrates the problem. Setting an ansistring codepage to cp_none causes concatenation with a string with a different codepage to fail with the cp_none string ignore. This behaviour is observed only under Windows.
System Information
Windows-11 FPC 3.2.2 (as distributed with Lazarus) x86_64 Desktop environment
Steps to reproduce
Compile and run the simple program given below.
Example Project
Program project1;
uses Sysutils;
const
sTest = 'Test';
var s1: RawByteString;
s2, s3: AnsiString;
begin
writeln('Case #1: s1 code page = utf8');
SetString(s1,PAnsiChar(sTest),length(sTest));
SetCodePage(s1,cp_utf8,false);
writeln('s1 Codepage = ',StringCodePage(s1),', Len = ',Length(s1),' Value = ',s1);
s2 := IntToStr(1);
writeln('s2 Codepage = ',StringCodePage(s2),', Len = ',Length(s2),' Value = ',s2);
s3 := s1 + s2;
writeln('s3 Codepage = ',StringCodePage(s3),', Len = ',Length(s3),' Value = ',s3);
writeln;
writeln('Case #2: s1 code page = none');
SetString(s1,PAnsiChar(sTest),length(sTest));
SetCodePage(s1,cp_none,false);
writeln('s1 Codepage = ',StringCodePage(s1),', Len = ',Length(s1),' Value = ',s1);
s2 := IntToStr(1);
writeln('s2 Codepage = ',StringCodePage(s2),', Len = ',Length(s2),' Value = ',s2);
s3 := s1 + s2;
writeln('s3 Codepage = ',StringCodePage(s3),', Len = ',Length(s3),' Value = ',s3);
writeln;
write('Press any key to continue');
readln;
end.
What is the current bug behavior?
Under Linux, the result is:
Case #1: s1 code page = utf8
s1 Codepage = 65001, Len = 4 Value = Test
s2 Codepage = 0, Len = 1 Value = 1
s3 Codepage = 0, Len = 5 Value = Test1
Case #2: s1 code page = none
s1 Codepage = 65535, Len = 4 Value = Test
s2 Codepage = 0, Len = 1 Value = 1
s3 Codepage = 0, Len = 5 Value = Test1
Under Windows, the result is:
Case #1: s1 code page = utf8
s1 Codepage = 65001, Len = 4 Value = Test
s2 Codepage = 0, Len = 1 Value = 1
s3 Codepage = 1252, Len = 5 Value = Test1
Case #2: s1 code page = none
s1 Codepage = 65535, Len = 4 Value = Test
s2 Codepage = 0, Len = 1 Value = 1
s3 Codepage = 1252, Len = 1 Value = 1
What is the expected (correct) behavior?
In Case #2, the line beginning s3... shows the correct result for Linux, while under Windows an incorrect result is observed.
Relevant logs and/or screenshots
n/a
Possible fixes
?
Edited by Tony Whyman