Browse Source

compiler: convert string constants from and to codepage 0. use compiler codepage during the conversion + test

git-svn-id: trunk@19473 -
paul 13 years ago
parent
commit
85c2f195d6
3 changed files with 30 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 8 2
      compiler/ncon.pas
  3. 21 0
      tests/test/tcpstr16.pp

+ 1 - 0
.gitattributes

@@ -9975,6 +9975,7 @@ tests/test/tcpstr12.pp svneol=native#text/pascal
 tests/test/tcpstr13.pp svneol=native#text/pascal
 tests/test/tcpstr14.pp svneol=native#text/pascal
 tests/test/tcpstr15.pp svneol=native#text/pascal
+tests/test/tcpstr16.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

+ 8 - 2
compiler/ncon.pas

@@ -1029,8 +1029,14 @@ implementation
              not(cst_type in [cst_widestring,cst_unicodestring]) then
             begin
               cp1:=tstringdef(def).encoding;
+              if cp1=0 then
+                cp1:=current_settings.sourcecodepage;
               if (cst_type = cst_ansistring) then
-                cp2:=tstringdef(resultdef).encoding
+                begin
+                  cp2:=tstringdef(resultdef).encoding;
+                  if cp2=0 then
+                    cp2:=current_settings.sourcecodepage;
+                end
               else if (cst_type in [cst_shortstring,cst_conststring,cst_longstring]) then
                 cp2:=current_settings.sourcecodepage;
               { don't change string if codepages are equal or string length is 0 }  
@@ -1038,7 +1044,7 @@ implementation
                 begin
                   if cpavailable(cp1) and cpavailable(cp2) then
                     changecodepage(value_str,len,cp2,value_str,cp1)
-                  else if (cp1 <> CP_NONE) and (cp2 <> CP_NONE) and (cp1 <> 0) and (cp2 <> 0) then
+                  else if (cp1 <> CP_NONE) and (cp2 <> CP_NONE) then
                     begin
                       { if source encoding is UTF8 convert using UTF8->UTF16->destination encoding }
                       if (cp2=CP_UTF8) then

+ 21 - 0
tests/test/tcpstr16.pp

@@ -0,0 +1,21 @@
+program tcpstr16;
+{$mode delphi}
+{$codepage cp1251}
+{$apptype console}
+type
+  T866String = type AnsiString(866);
+  T1251String = type AnsiString(1251);
+
+function Compare(const S1, S2: RawByteString): Boolean;
+begin
+  Result :=
+    (Length(S1) = Length(S2)) and
+    (CompareByte(S1[1],S2[1],Length(S1))=0);
+end;
+
+begin
+  if Compare(T866String('ïðèâåò'), 'ïðèâåò') then
+    halt(1);
+  if not Compare(AnsiString(T866String('ïðèâåò')), 'ïðèâåò') then
+    halt(2);
+end.