compiler: convert unicode constants which are > 127 to AnsiString (except UTF8String) in runtime to prevent conversion to wrong codepage (read issue #0021195)

git-svn-id: trunk@23613 -
This commit is contained in:
paul 2013-02-14 09:01:07 +00:00
parent f103808e09
commit fe4b5ea82d

View File

@ -1118,8 +1118,22 @@ implementation
if (current_settings.sourcecodepage<>CP_UTF8) then
begin
if tordconstnode(left).value.uvalue>127 then
Message(type_w_unicode_data_loss);
hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue)));
begin
Message(type_w_unicode_data_loss);
// compiler has different codepage than a system running an application
// to prevent wrong codepage and data loss we are converting unicode char
// using a helper routine. This is not delphi compatible behavior.
// Delphi converts UniocodeChar to ansistring at the compile time
// old behavior:
// hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue)));
result:=ccallnode.createinternres('fpc_uchar_to_'+tstringdef(resultdef).stringtypname,
ccallparanode.create(cordconstnode.create(getparaencoding(resultdef),u16inttype,true),
ccallparanode.create(left,nil)),resultdef);
left:=nil;
exit;
end
else
hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue)));
end
else
begin