Browse Source

* don't create temporary ansistrings with codepage DefaultSystemCodePage
when concatenating or comparing CP_ACP strings, because the ansistring
conversion helpers also check for CP_ACP and do the right thing in
that case
* don't convert code pages when comparing CP_ACP strings with
DefaultSystemCodePage strings (mantis #22906)

git-svn-id: trunk@22415 -

Jonas Maebe 13 years ago
parent
commit
8799d9d204
1 changed files with 14 additions and 22 deletions
  1. 14 22
      rtl/inc/astrings.inc

+ 14 - 22
rtl/inc/astrings.inc

@@ -279,7 +279,6 @@ Var
   DestCP      : TSystemCodePage;
   DestCP      : TSystemCodePage;
   U           : UnicodeString;
   U           : UnicodeString;
   sameCP      : Boolean;
   sameCP      : Boolean;
-  tmpStr      : RawByteString;
   tmpCP       : TSystemCodePage;
   tmpCP       : TSystemCodePage;
 begin
 begin
   if high(sarr)=0 then
   if high(sarr)=0 then
@@ -315,14 +314,7 @@ begin
       U:='';
       U:='';
       for i:=lowstart to high(sarr) do begin
       for i:=lowstart to high(sarr) do begin
         tmpCP:=StringCodePage(sarr[i]);
         tmpCP:=StringCodePage(sarr[i]);
-        if (tmpCP=CP_ACP) then
-          begin
-            tmpStr:=sarr[i];
-            SetCodePage(tmpStr,DefaultSystemCodePage,False);
-            U:=U+UnicodeString(tmpStr);
-          end
-        else
-          U:=U+UnicodeString(sarr[i]);
+        U:=U+UnicodeString(sarr[i]);
       end;
       end;
 
 
       DestS:='';
       DestS:='';
@@ -635,8 +627,12 @@ begin
       exit;
       exit;
     end;
     end;
   cp1:=StringCodePage(S1);
   cp1:=StringCodePage(S1);
+  if cp1=CP_ACP then
+    cp1:=DefaultSystemCodePage;
   cp2:=StringCodePage(S2);
   cp2:=StringCodePage(S2);
-  if (cp1=cp2) then
+  if cp2=CP_ACP then
+    cp2:=DefaultSystemCodePage;
+  if cp1=cp2 then
     begin
     begin
       Maxi:=Length(S1);
       Maxi:=Length(S1);
       temp:=Length(S2);
       temp:=Length(S2);
@@ -654,15 +650,11 @@ begin
   else
   else
     begin
     begin
       r1:=S1;
       r1:=S1;
-      if (cp1=CP_ACP) then
-        SetCodePage(r1,DefaultSystemCodePage,false);
       r2:=S2;
       r2:=S2;
-      if (cp2=CP_ACP) then
-        SetCodePage(r2,DefaultSystemCodePage,false);
       //convert them to utf8 then compare
       //convert them to utf8 then compare
       SetCodePage(r1,65001);
       SetCodePage(r1,65001);
       SetCodePage(r2,65001);
       SetCodePage(r2,65001);
-      Result := fpc_AnsiStr_Compare(r1,r2);
+      Result:=fpc_AnsiStr_Compare(r1,r2);
     end;
     end;
 end;
 end;
 {$endif FPC_HAS_ANSISTR_COMPARE}
 {$endif FPC_HAS_ANSISTR_COMPARE}
@@ -690,17 +682,21 @@ begin
   { don't compare strings if one of them is empty }
   { don't compare strings if one of them is empty }
   if (pointer(S1)=nil) then
   if (pointer(S1)=nil) then
     begin
     begin
-      result:=-Length(S2);
+      result:=-1;
       exit;
       exit;
     end;
     end;
   if (pointer(S2)=nil) then
   if (pointer(S2)=nil) then
     begin
     begin
-      result:=Length(S1);
+      result:=1;
       exit;
       exit;
     end;
     end;
   cp1:=StringCodePage(S1);
   cp1:=StringCodePage(S1);
+  if cp1=CP_ACP then
+    cp1:=DefaultSystemCodePage;
   cp2:=StringCodePage(S2);
   cp2:=StringCodePage(S2);
-  if (cp1=cp2) then
+  if cp2=CP_ACP then
+    cp2:=DefaultSystemCodePage;
+  if cp1=cp2 then
     begin
     begin
       Maxi:=Length(S1);
       Maxi:=Length(S1);
       temp:=Length(S2);
       temp:=Length(S2);
@@ -712,11 +708,7 @@ begin
   else
   else
     begin
     begin
       r1:=S1;
       r1:=S1;
-      if (cp1=CP_ACP) then
-        SetCodePage(r1,DefaultSystemCodePage,false);
       r2:=S2;
       r2:=S2;
-      if (cp2=CP_ACP) then
-        SetCodePage(r2,DefaultSystemCodePage,false);
       //convert them to utf8 then compare
       //convert them to utf8 then compare
       SetCodePage(r1,65001);
       SetCodePage(r1,65001);
       SetCodePage(r2,65001);
       SetCodePage(r2,65001);