diff --git a/components/codetools/directorycacher.pas b/components/codetools/directorycacher.pas index b0a0083a03..8a6d1b4bd8 100644 --- a/components/codetools/directorycacher.pas +++ b/components/codetools/directorycacher.pas @@ -2169,8 +2169,8 @@ var if (CurDir='*') or (CurDir='**') then exit(true); for i:=0 to Excludes.Count-1 do begin ExcludeMask:=Excludes[i]; - if FilenameIsMatching(ExcludeMask,CurSubDir,true) - or FilenameIsMatching(ExcludeMask,CurDir,true) then + if FilenameIsMatching(ExcludeMask,CurSubDir,true,true) + or FilenameIsMatching(ExcludeMask,CurDir,true,true) then exit(true); end; Result:=false; diff --git a/components/codetools/fileprocs.pas b/components/codetools/fileprocs.pas index 0017ab4065..ba984e4a3a 100644 --- a/components/codetools/fileprocs.pas +++ b/components/codetools/fileprocs.pas @@ -86,7 +86,7 @@ type // file operations function FileDateToDateTimeDef(aFileDate: TCTFileAgeTime; const Default: TDateTime = 0): TDateTime; -function FilenameIsMatching(const Mask, Filename: string; MatchExactly: boolean): boolean; +function FilenameIsMatching(const Mask, Filename: string; MatchExactly: boolean; AnyCase: boolean = false): boolean; function FindNextDirectoryInFilename(const Filename: string; var Position: integer): string; function ClearFile(const Filename: string; RaiseOnError: boolean): boolean; @@ -1158,8 +1158,8 @@ begin Result:=''; end; -function FilenameIsMatching(const Mask, Filename: string; MatchExactly: boolean - ): boolean; +function FilenameIsMatching(const Mask, Filename: string; + MatchExactly: boolean; AnyCase: boolean): boolean; (* check if Filename matches Mask if MatchExactly then the complete Filename must match, else only the @@ -1187,6 +1187,19 @@ function FilenameIsMatching(const Mask, Filename: string; MatchExactly: boolean *) {off $DEFINE VerboseFilenameIsMatching} + function CompareUTF8AnyCase(AP: PChar; LenA: integer; BP: PChar; LenB: integer): PtrInt; + var + A, B: string; + begin + SetLength(A,LenA); + if LenA>0 then + Move(AP^,A[1],LenA); + SetLength(B,LenB); + if LenB>0 then + Move(BP^,B[1],LenB); + Result:=UTF8CompareText(A,B); + end; + function Check(MaskP, FileP: PChar): boolean; var Level: Integer; @@ -1356,18 +1369,24 @@ function FilenameIsMatching(const Mask, Filename: string; MatchExactly: boolean inc(MaskP,UTF8CodepointSize(MaskP)); inc(FileP,UTF8CodepointSize(FileP)); end; - if CompareFilenames(MaskStart,MaskP-MaskStart,FileStart,FileP-FileStart)<>0 then - exit; + if Anycase then begin + if CompareUTF8AnyCase(MaskStart,MaskP-MaskStart,FileStart,FileP-FileStart)<>0 then + exit; + end else begin + if CompareFilenames(MaskStart,MaskP-MaskStart,FileStart,FileP-FileStart)<>0 then + exit; + end; end; else // match ASCII characters repeat case MaskP^ of #0,SpecialChar,PathDelim,'?','*','{',',','}': break; - {$IFDEF CaseInsensitiveFilenames} 'a'..'z','A'..'Z': - if FPUpChars[MaskP^]<>FPUpChars[FileP^] then exit; - {$ENDIF} + if AnyCase then begin + if FPUpChars[MaskP^]<>FPUpChars[FileP^] then exit; + end else + if MaskP^<>FileP^ then exit; else if MaskP^<>FileP^ then exit; end;