mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 20:49:49 +02:00
* finer grained convert levels for strings, prefers widestring<->unicodestring over other conversions, resolves #18075
git-svn-id: trunk@16460 -
This commit is contained in:
parent
b1a6ec532d
commit
e4ecee317e
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -10767,6 +10767,7 @@ tests/webtbs/tw1798.pp svneol=native#text/plain
|
||||
tests/webtbs/tw17986.pp svneol=native#text/pascal
|
||||
tests/webtbs/tw17998.pp svneol=native#text/plain
|
||||
tests/webtbs/tw18013.pp svneol=native#text/plain
|
||||
tests/webtbs/tw18075.pp svneol=native#text/pascal
|
||||
tests/webtbs/tw1820.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1825.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1850.pp svneol=native#text/plain
|
||||
|
@ -338,7 +338,8 @@ implementation
|
||||
doconv:=tc_string_2_string;
|
||||
{ Don't prefer conversions from widestring to a
|
||||
normal string as we can loose information }
|
||||
if tstringdef(def_from).stringtype in [st_widestring,st_unicodestring] then
|
||||
if (tstringdef(def_from).stringtype in [st_widestring,st_unicodestring]) and
|
||||
not (tstringdef(def_to).stringtype in [st_widestring,st_unicodestring]) then
|
||||
eq:=te_convert_l3
|
||||
else if tstringdef(def_to).stringtype in [st_widestring,st_unicodestring] then
|
||||
eq:=te_convert_l2
|
||||
@ -358,16 +359,22 @@ implementation
|
||||
case tstringdef(def_from).stringtype of
|
||||
st_widestring :
|
||||
begin
|
||||
{ Prefer conversions to ansistring }
|
||||
if tstringdef(def_to).stringtype=st_ansistring then
|
||||
{ Prefer conversions to unicodestring }
|
||||
if tstringdef(def_to).stringtype=st_unicodestring then
|
||||
eq:=te_convert_l1
|
||||
{ else prefer conversions to ansistring }
|
||||
else if tstringdef(def_to).stringtype=st_ansistring then
|
||||
eq:=te_convert_l2
|
||||
else
|
||||
eq:=te_convert_l3;
|
||||
end;
|
||||
st_unicodestring :
|
||||
begin
|
||||
{ Prefer conversions to ansistring }
|
||||
if tstringdef(def_to).stringtype=st_ansistring then
|
||||
{ Prefer conversions to widestring }
|
||||
if tstringdef(def_to).stringtype=st_widestring then
|
||||
eq:=te_convert_l1
|
||||
{ else prefer conversions to ansistring }
|
||||
else if tstringdef(def_to).stringtype=st_ansistring then
|
||||
eq:=te_convert_l2
|
||||
else
|
||||
eq:=te_convert_l3;
|
||||
|
37
tests/webtbs/tw18075.pp
Normal file
37
tests/webtbs/tw18075.pp
Normal file
@ -0,0 +1,37 @@
|
||||
{$codepage UTf8}
|
||||
Var cad1:unicodeString;
|
||||
cad2:Widestring;
|
||||
n:integer;
|
||||
Begin
|
||||
cad1:='犮犯狃狄狪独';
|
||||
cad2:=cad1;
|
||||
|
||||
//Unicodestring, 1 character is ok
|
||||
Writeln('unicodestring');
|
||||
n:=pos('犮',cad1);
|
||||
Writeln(n);
|
||||
if n<>1 then
|
||||
halt(1);
|
||||
|
||||
Writeln('widestring');
|
||||
n:=pos('犮',cad2);
|
||||
Writeln(n);
|
||||
if n<>1 then
|
||||
halt(1);
|
||||
|
||||
//Unicodestring, more charactere wrong
|
||||
Writeln('unicodestring');
|
||||
n:=pos('狃狄',cad1);
|
||||
Writeln(n); //show position 0
|
||||
if n<>3 then
|
||||
halt(1);
|
||||
|
||||
Writeln('widestring');
|
||||
n:=pos('狃狄',cad2); //Is correct position 3
|
||||
|
||||
Writeln(n);
|
||||
if n<>3 then
|
||||
halt(1);
|
||||
|
||||
Writeln('ok');
|
||||
End.
|
Loading…
Reference in New Issue
Block a user