Browse Source

* ensure that constant string concatenations don't result in converting
input strings to DefaultSystemCodePage

git-svn-id: branches/cpstrrtl@25303 -

Jonas Maebe 12 years ago
parent
commit
91079d1327
1 changed files with 63 additions and 5 deletions
  1. 63 5
      rtl/objpas/sysutils/fina.inc

+ 63 - 5
rtl/objpas/sysutils/fina.inc

@@ -195,8 +195,13 @@ var
     if (Base = '') or CharInSet(Base[Length (Base)],AllowDirectorySeparators) then
     if (Base = '') or CharInSet(Base[Length (Base)],AllowDirectorySeparators) then
      SearchBase := Base
      SearchBase := Base
     else
     else
+{$ifdef SYSUTILSUNICODE}
      SearchBase := Base + DirectorySeparator;
      SearchBase := Base + DirectorySeparator;
     RC := FindFirst (SearchBase + AllFilesMask, faAnyFile, SR);
     RC := FindFirst (SearchBase + AllFilesMask, faAnyFile, SR);
+{$else SYSUTILSUNICODE}
+     SearchBase := Base + ToSingleByteFileSystemEncodedFileName(DirectorySeparator);
+    RC := FindFirst (SearchBase + ToSingleByteFileSystemEncodedFileName(AllFilesMask), faAnyFile, SR);
+{$endif SYSUTILSUNICODE}
     while (RC = 0) and (ItemsFound < 2) do
     while (RC = 0) and (ItemsFound < 2) do
      begin
      begin
       if UpCase (NextPart) = UpCase (SR.Name) then
       if UpCase (NextPart) = UpCase (SR.Name) then
@@ -208,7 +213,11 @@ var
            FoundPath := SearchBase + SR.Name;
            FoundPath := SearchBase + SR.Name;
          end
          end
         else if SR.Attr and faDirectory = faDirectory then
         else if SR.Attr and faDirectory = faDirectory then
-         TryCase (SearchBase + SR.Name + DirectorySeparator, NextRest);
+{$ifdef SYSUTILSUNICODE}
+          TryCase (SearchBase + SR.Name + DirectorySeparator, NextRest);
+{$else SYSUTILSUNICODE}
+          TryCase (SearchBase + SR.Name + ToSingleByteFileSystemEncodedFileName(DirectorySeparator), NextRest);
+{$endif SYSUTILSUNICODE}
        end;
        end;
       if ItemsFound < 2 then
       if ItemsFound < 2 then
        RC := FindNext (SR);
        RC := FindNext (SR);
@@ -273,9 +282,13 @@ Const
 
 
 function ExtractRelativepath (Const BaseName,DestName : PathStr): PathStr;
 function ExtractRelativepath (Const BaseName,DestName : PathStr): PathStr;
 
 
-Var Source, Dest : PathStr;
-    Sc,Dc,I,J    : Longint;
-    SD,DD        : Array[1..MaxDirs] of PathPChar;
+Var Source, Dest   : PathStr;
+    Sc,Dc,I,J
+{$ifndef SYSUTILSUNICODE}
+    ,Len, NewLen
+{$endif not SYSUTILSUNICODE}
+                   : Longint;
+    SD,DD          : Array[1..MaxDirs] of PathPChar;
 
 
 Const OneLevelBack = '..'+DirectorySeparator;
 Const OneLevelBack = '..'+DirectorySeparator;
 
 
@@ -298,9 +311,39 @@ begin
       Break;
       Break;
     end;
     end;
   Result:='';
   Result:='';
+{$ifdef SYSUTILSUNICODE}
   For J:=I to SC do Result:=Result+OneLevelBack;
   For J:=I to SC do Result:=Result+OneLevelBack;
   For J:=I to DC do Result:=Result+DD[J]+DirectorySeparator;
   For J:=I to DC do Result:=Result+DD[J]+DirectorySeparator;
-  Result:=Result+ExtractFileName(DestNAme);
+{$else SYSUTILSUNICODE}
+  { prevent conversion to DefaultSystemCodePage due to concatenation of
+    constant string -- and optimise a little by reducing the numher of
+    setlength cals }
+  if SC>=I then
+    begin
+      Len:=Length(Result);
+      SetLength(Result,Len+(SC-I+1)*Length(OneLevelBack));
+      For J:=0 to SC-I do
+        move(shortstring(OneLevelBack)[1],Result[Len+1+J*Length(OneLevelBack)],Length(OneLevelBack));
+    end;
+
+  if DC>=I then
+    begin
+      Len:=Length(Result);
+      NewLen:=Len+(DC-I+1)*sizeof(ansichar);
+      For J:=I to DC do
+        Inc(NewLen,Length(DD[J]));
+      SetLength(Result,NewLen);
+      For J:=I to DC do
+        begin
+          NewLen:=Length(DD[J]);
+          Move(DD[J][0],Result[Len+1],NewLen);
+          inc(Len,NewLen);
+          Result[Len+1]:=DirectorySeparator;
+          Inc(Len);
+        end;
+    end;
+{$endif SYSUTILSUNICODE}
+  Result:=Result+ExtractFileName(DestName);
 end;
 end;
 
 
 Procedure DoDirSeparators (Var FileName : PathStr);
 Procedure DoDirSeparators (Var FileName : PathStr);
@@ -359,7 +402,14 @@ begin
   Result:=Path;
   Result:=Path;
   l:=Length(Result);
   l:=Length(Result);
   If (L=0) or not CharInSet(Result[l],AllowDirectorySeparators) then
   If (L=0) or not CharInSet(Result[l],AllowDirectorySeparators) then
+{$ifdef SYSUTILSUNICODE}
     Result:=Result+DirectorySeparator;
     Result:=Result+DirectorySeparator;
+{$else SYSUTILSUNICODE}
+    begin
+      SetLength(Result,l+1);
+      Result[l+1]:=DirectorySeparator;
+    end;
+{$endif SYSUTILSUNICODE}
 end;
 end;
 
 
 function IncludeTrailingBackslash(Const Path : PathStr) : PathStr;
 function IncludeTrailingBackslash(Const Path : PathStr) : PathStr;
@@ -395,7 +445,15 @@ begin
   Result:=Path;
   Result:=Path;
   l:=Length(Result);
   l:=Length(Result);
   If (L=0) or not CharInSet(Result[1],AllowDirectorySeparators) then
   If (L=0) or not CharInSet(Result[1],AllowDirectorySeparators) then
+{$ifdef SYSUTILSUNICODE}
     Result:=DirectorySeparator+Result;
     Result:=DirectorySeparator+Result;
+{$else SYSUTILSUNICODE}
+    begin
+      SetLength(Result,l+1);
+      Move(Result[1],Result[2],l);
+      Result[1]:=DirectorySeparator;
+    end;
+{$endif SYSUTILSUNICODE}
 end;
 end;
 
 
 function ExcludeLeadingPathDelimiter(Const Path: PathStr): PathStr;
 function ExcludeLeadingPathDelimiter(Const Path: PathStr): PathStr;