Selaa lähdekoodia

* finer grained convert levels for strings, prefers widestring<->unicodestring over other conversions, resolves #18075

git-svn-id: trunk@16460 -
florian 14 vuotta sitten
vanhempi
commit
e4ecee317e
3 muutettua tiedostoa jossa 50 lisäystä ja 5 poistoa
  1. 1 0
      .gitattributes
  2. 12 5
      compiler/defcmp.pas
  3. 37 0
      tests/webtbs/tw18075.pp

+ 1 - 0
.gitattributes

@@ -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

+ 12 - 5
compiler/defcmp.pas

@@ -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 - 0
tests/webtbs/tw18075.pp

@@ -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.