* Patch from Bart B to let TPath.HasValueFileNameChars return index of offending char. Fixes issue #40540

(cherry picked from commit 39d2035db2)
This commit is contained in:
Michaël Van Canneyt 2023-11-23 23:18:00 +01:00 committed by marcoonthegit
parent 34c9d60a9b
commit 5d687aa7e1

View File

@ -168,8 +168,10 @@ type
class constructor Create;
class function IsValidPathChar(const AChar: Char): Boolean;
class function IsValidFileNameChar(const AChar: Char): Boolean;
class function HasValidPathChars(const aPath: string; const UseWildcards: Boolean = false): Boolean;
class function HasValidFileNameChars(const FileName: string; const UseWildcards: Boolean = False): Boolean;
class function HasValidPathChars(const aPath: string; const UseWildcards: Boolean = false): Boolean; inline;
class function HasValidPathChars(const aPath: string; out Index: Integer; const UseWildcards: Boolean = false): Boolean;
class function HasValidFileNameChars(const FileName: string; const UseWildcards: Boolean = False): Boolean; inline;
class function HasValidFileNameChars(const FileName: string; out Index: Integer; const UseWildcards: Boolean = False): Boolean;
class function GetExtendedPrefix(const aPath: string): TPathPrefixType;
class function IsDriveRooted(const aPath: string): Boolean;
class function IsExtendedPrefixed(const aPath: string): Boolean;
@ -485,6 +487,14 @@ end;
class function TPath.HasValidPathChars(const aPath: string;
const UseWildcards: Boolean): Boolean;
var
dummy: Integer;
begin
Result:=TPath.HasValidPathChars(aPath, dummy, UseWildcards);
end;
class function TPath.HasValidPathChars(const aPath: string;
out Index: integer; const UseWildcards: Boolean): Boolean;
var
P: PChar;
S,I,Len: Integer;
@ -501,6 +511,7 @@ begin
Inc(P,S-1);
for I:=S to Len do
begin
Index:=i;
C:=P^;
if CheckWC and (CharInSet(C,['?','*'])) then
exit;
@ -513,6 +524,14 @@ end;
class function TPath.HasValidFileNameChars(const FileName: string;
const UseWildcards: Boolean): Boolean;
var
dummy: Integer;
begin
Result:=HasValidFileNameChars(FileName, dummy, UseWildCards);
end;
class function TPath.HasValidFileNameChars(const FileName: string;
out Index: Integer; const UseWildcards: Boolean): Boolean;
var
P: PChar;
S,I,Len: Integer;
@ -529,6 +548,7 @@ begin
Inc(P,S-1);
for I:=S to Len do
begin
Index:=I;
C:=P^;
if CheckWC and (CharInSet(C,['?','*'])) then
exit;