* translate placeholder code page numbers into actual code pages in

fpc_ansistr_to_widechararray(), so that CP_ACP/CP_OEM etc are properly
    handled (fixes assign/assignfile with non-ansi characters in source files
    that don't explicitly specify the code page)

git-svn-id: trunk@29218 -
This commit is contained in:
Jonas Maebe 2014-12-08 12:11:33 +00:00
parent 3e24a9ebfd
commit cec82a1540
3 changed files with 33 additions and 1 deletions

1
.gitattributes vendored
View File

@ -11414,6 +11414,7 @@ tests/test/tcpstr8.pp svneol=native#text/pascal
tests/test/tcpstr9.pp svneol=native#text/pascal
tests/test/tcpstransistr2shortstring.pp svneol=native#text/plain
tests/test/tcpstransistr2widechararray.pp svneol=native#text/plain
tests/test/tcpstransistr2widechararray2.pp svneol=native#text/plain
tests/test/tcpstransistrcompare.pp svneol=native#text/plain
tests/test/tcpstransistrcompareequal.pp svneol=native#text/plain
tests/test/tcpstransistrcopy.pp svneol=native#text/plain

View File

@ -817,7 +817,7 @@ begin
len := length(src);
{ make sure we don't dereference src if it can be nil (JM) }
if len > 0 then
widestringmanager.ansi2widemoveproc(pchar(@src[1]),StringCodePage(src),temp,len);
widestringmanager.ansi2widemoveproc(pchar(@src[1]),TranslatePlaceholderCP(StringCodePage(src)),temp,len);
len := length(temp);
if len > length(res) then
len := length(res);

View File

@ -0,0 +1,31 @@
{ this file is stored in utf8, but we don't tell the compiler so that the string
constant gets code page 0/CP_ACP; this test is to make sure that
fpc_ansistr_to_widechararray() translates CP_ACP to the actual value of
DefaultSystemCodePage before calling widestringmanager.ansi2widemoveproc
}
{$ifdef unix}
uses
cwstring;
{$endif}
{$r+}
var
u8: ansistring;
a: array[0..10] of unicodechar;
u16: unicodestring;
i: longint;
begin
DefaultSystemCodePage:=CP_UTF8;
u8:='èà';
a:=u8;
u16:=unicodestring(u8);
for i:=0 to 1 do
begin
writeln('u16[',i-low(a)+low(u16),'] = $',hexstr(ord(u16[i-low(a)+low(u16)]),2));
writeln('a[',i,'] = $',hexstr(ord(a[i]),2));
if u16[i-low(a)+low(u16)]<>a[i] then
halt(i+1);
end;
if a[2]<>#0 then
halt(3);
end.