WideString consts and encodings
Original Reporter info from Mantis: zolotov-alex@mail.ru
-
Reporter name: Alex Zolotov
Original Reporter info from Mantis: zolotov-alex@mail.ru
- Reporter name: Alex Zolotov
Description:
Then I define WideString const with russian chars compiler do not translate it to Unicode, but just produce string with char-codes in 0..255 range. Then I convert WideString to AnsiString and obtain wrong string with char-codes in 0..128 range, i.e. english chars.
I think that FPC should convert WideStrings constans to Unicode, using current locale or compiler directive, say {$ENCODING &LtPos;encoding name>}
example:
{$ENCODING utf-8} - say that compiler should treat all strings as defined in UTF-8 encoding
{$ENCODING native} - default, compiler should treat all strings as defined in current system encoding (locale)
If compiler cannot convert string from specified encoding to Unicode, then it should emit warning and process strings in old way.
If it will use {$ENCODING} directive, then FPC can once emit warning when meet directive with no supporting encoding, and do not emit warnings on every string
my environment:
Windows XP,
language: russian
Default encoding: windows-1251 (cp1251)
This example produce two different strings, but should produce same strings.
I tried it in today's SVN trunc and in FPC 2.0.4 - result the same
program test;
procedure test_ansi(S: AnsiString);
begin
writeln(S);
end;
procedure test_wide(S: WideString);
begin
test_ansi(s);
end;
const
// 'Hello world' in russian language (cp1251)
S: WideString = 'Ïðèâåò ìèð';
begin
test_wide(S);
// 'Hello world' in russian language (cp1251)
writeln('Ïðèâåò ìèð');
end.
Mantis conversion info:
- Mantis ID: 8896
- Fixed in version: 2.4.0
- Fixed in revision: 7420 (#9f56a896)
- Monitored by: » zolotov-alex@mail.ru (Alex Zolotov), » @marcoonthegit (Marco van de Voort)