mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 16:49:07 +02:00
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:
parent
f103808e09
commit
fe4b5ea82d
@ -1118,8 +1118,22 @@ implementation
|
|||||||
if (current_settings.sourcecodepage<>CP_UTF8) then
|
if (current_settings.sourcecodepage<>CP_UTF8) then
|
||||||
begin
|
begin
|
||||||
if tordconstnode(left).value.uvalue>127 then
|
if tordconstnode(left).value.uvalue>127 then
|
||||||
Message(type_w_unicode_data_loss);
|
begin
|
||||||
hp:=cstringconstnode.createstr(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value.uvalue)));
|
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
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user