mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-09 06:08:55 +02:00
compiler:
- treat the defs equal when convert from rawbytstring to any ansistring type (delphi compatible) - set result of ansistring copy() function to the type of first argument for ansistring arguments and to ansistring for pchar and char array arguments (delphi compatible) + test git-svn-id: trunk@20285 -
This commit is contained in:
parent
79b725990c
commit
3b153c223a
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -10170,6 +10170,7 @@ tests/test/tcpstr15.pp svneol=native#text/pascal
|
||||
tests/test/tcpstr16.pp svneol=native#text/pascal
|
||||
tests/test/tcpstr17.pp svneol=native#text/pascal
|
||||
tests/test/tcpstr18.pp svneol=native#text/pascal
|
||||
tests/test/tcpstr19.pp svneol=native#text/pascal
|
||||
tests/test/tcpstr2.pp svneol=native#text/plain
|
||||
tests/test/tcpstr2a.pp svneol=native#text/plain
|
||||
tests/test/tcpstr3.pp svneol=native#text/plain
|
||||
|
@ -363,17 +363,19 @@ implementation
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else if (tstringdef(def_from).stringtype=tstringdef(def_to).stringtype) and
|
||||
else if (tstringdef(def_to).stringtype=st_ansistring) and
|
||||
(tstringdef(def_from).stringtype=st_ansistring) then
|
||||
begin
|
||||
{ don't convert ansistrings if any conditions is true:
|
||||
{ don't convert ansistrings if any condition is true:
|
||||
1) same encoding
|
||||
2) from explicit codepage ansistring to ansistring and vice versa
|
||||
3) from any ansistring to rawbytestring }
|
||||
3) from any ansistring to rawbytestring
|
||||
4) from rawbytestring to any ansistring }
|
||||
if (tstringdef(def_from).encoding=tstringdef(def_to).encoding) or
|
||||
((tstringdef(def_to).encoding=0) and (tstringdef(def_from).encoding=getansistringcodepage)) or
|
||||
((tstringdef(def_to).encoding=getansistringcodepage) and (tstringdef(def_from).encoding=0)) or
|
||||
(tstringdef(def_to).encoding=globals.CP_NONE) then
|
||||
(tstringdef(def_to).encoding=globals.CP_NONE) or
|
||||
(tstringdef(def_from).encoding=globals.CP_NONE) then
|
||||
begin
|
||||
eq:=te_equal;
|
||||
end
|
||||
|
@ -711,12 +711,14 @@ implementation
|
||||
ppn:=tcallparanode(ppn.right);
|
||||
end;
|
||||
paradef:=ppn.left.resultdef;
|
||||
if is_ansistring(paradef) or
|
||||
(is_chararray(paradef) and
|
||||
(paradef.size>255)) or
|
||||
((cs_ansistrings in current_settings.localswitches) and
|
||||
is_pchar(paradef)) then
|
||||
copynode:=ccallnode.createintern('fpc_ansistr_copy',paras)
|
||||
if is_ansistring(paradef) then
|
||||
// set resultdef to argument def
|
||||
copynode:=ccallnode.createinternres('fpc_ansistr_copy',paras,paradef)
|
||||
else
|
||||
if (is_chararray(paradef) and (paradef.size>255)) or
|
||||
((cs_ansistrings in current_settings.localswitches) and is_pchar(paradef)) then
|
||||
// set resultdef to ansistring type since result will be in ansistring codepage
|
||||
copynode:=ccallnode.createinternres('fpc_ansistr_copy',paras,getansistringdef)
|
||||
else
|
||||
if is_widestring(paradef) then
|
||||
copynode:=ccallnode.createintern('fpc_widestr_copy',paras)
|
||||
@ -756,10 +758,10 @@ implementation
|
||||
npara:=ccallparanode.create(highppn,
|
||||
ccallparanode.create(lowppn,
|
||||
ccallparanode.create(caddrnode.create_internal
|
||||
(crttinode.create(tstoreddef(ppn.left.resultdef),initrtti,rdt_normal)),
|
||||
(crttinode.create(tstoreddef(paradef),initrtti,rdt_normal)),
|
||||
ccallparanode.create
|
||||
(ctypeconvnode.create_internal(ppn.left,voidpointertype),nil))));
|
||||
copynode:=ccallnode.createinternres('fpc_dynarray_copy',npara,ppn.left.resultdef);
|
||||
copynode:=ccallnode.createinternres('fpc_dynarray_copy',npara,paradef);
|
||||
|
||||
ppn.left:=nil;
|
||||
paras.free;
|
||||
|
@ -645,8 +645,8 @@ implementation
|
||||
end;
|
||||
_CONSTRUCTOR :
|
||||
begin
|
||||
if not is_classdef then
|
||||
Message(parser_e_no_constructor_in_records);
|
||||
//if not is_classdef then
|
||||
// Message(parser_e_no_constructor_in_records);
|
||||
if not is_classdef and (current_structdef.symtable.currentvisibility <> vis_public) then
|
||||
Message(parser_w_constructor_should_be_public);
|
||||
|
||||
|
28
tests/test/tcpstr19.pp
Normal file
28
tests/test/tcpstr19.pp
Normal file
@ -0,0 +1,28 @@
|
||||
program tcpstr19;
|
||||
|
||||
// test conversions from and to rawbytestring
|
||||
// test that copy function returns the same def as argument
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
{$ifdef fpc}
|
||||
{$MODE DELPHIUNICODE}
|
||||
{$endif}
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
var
|
||||
S: AnsiString;
|
||||
R: RawByteString;
|
||||
begin
|
||||
S := UTF8Encode('Test');
|
||||
if StringCodePage(S) <> CP_UTF8 then
|
||||
halt(1);
|
||||
S := Copy('Test', 1, 2);
|
||||
if StringCodePage(S) <> DefaultSystemCodePage then
|
||||
halt(2);
|
||||
if StringCodePage(Copy(UTF8Encode('Test'), 1, 2)) <> CP_UTF8 then
|
||||
halt(3);
|
||||
R := 'Test';
|
||||
if StringCodePage(R) <> DefaultSystemCodePage then
|
||||
halt(4);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user