Constant strings are not automatically converted
Original Reporter info from Mantis: Simon Ameis @SAmeis
-
Reporter name: Simon Ameis
Original Reporter info from Mantis: Simon Ameis @SAmeis
- Reporter name: Simon Ameis
Description:
Constant strings are not converted to the code page required by the variable which is used to access them.
According to http://www.freepascal.org/docs-html/ref/refsu10.html there is no exception for constant strings.
Steps to reproduce:
Save code in UTF-8 encoding, compile and run.
program Project1; {$Codepage UTF-8} var r: RawByteString; s1: AnsiString; s2: UTF8String; begin r := 'Größe'; Writeln('RawByteString: ', StringCodePage(r),' ', StringRefCount(r)); s1 := r; Writeln('AnsiString: ', StringCodePage(s1),' ', StringRefCount(s1)); s2 := r; Writeln('UTF8String: ', StringCodePage(s2),' ', StringRefCount(s2)); readln; end.
Current output
RawByteString: 65001 -1 AnsiString: 65001 -1 UTF8String: 65001 -1
Expected
RawByteString: 65001 -1 AnsiString: 0 -1 UTF8String: 65001 -1
Additional information:
There is a similar issue with dynamic strings.
Save following code as UTF-8 encoded file, compile and run. Enter "Größe" when prompted.
program Project1; uses Interfaces, Forms, Dialogs; var r: RawByteString; s1: AnsiString; s2: UTF8String; begin Application.Initialize; r := InputBox('', '', ''); Writeln('RawByteString: ', StringCodePage(r),' ', StringRefCount(r)); s1 := r; Writeln('AnsiString: ', StringCodePage(s1),' ', StringRefCount(s1)); s2 := r; Writeln('UTF8String: ', StringCodePage(s2),' ', StringRefCount(s2)); readln; end.
Current output
RawByteString: 65001 2 AnsiString: 65001 3 UTF8String: 65001 4
AnsiString is expected to use system code page and to do automatic conversion.
Mantis conversion info:
- Mantis ID: 29622
- OS: Windows
- OS Build: 8.1 64-bit
- Build: 33072
- Version: 3.1.1