mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Add 'V_ComparePath'
Add function to compare paths for equality, while ignoring case and path separators.
This commit is contained in:
parent
6f441292d0
commit
dbb18e586d
@ -82,6 +82,8 @@ typedef enum
|
||||
// String matching using wildcards (*) for partial matches.
|
||||
bool V_StringMatchesPattern(const char* szString, const char* szPattern, int flags = 0);
|
||||
|
||||
bool V_ComparePath(const char* a, const char* b);
|
||||
|
||||
void V_FixSlashes(char* pname, char separator = CORRECT_PATH_SEPARATOR);
|
||||
|
||||
// Adds a path separator to the end of the string if there isn't one already and the string is not empty.
|
||||
|
@ -395,6 +395,40 @@ bool V_StringMatchesPattern(const char* pszSource, const char* pszPattern, int n
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Compares file paths, ignores case and path separators
|
||||
// Input : *a -
|
||||
// *b -
|
||||
// Output : true if equal, false otherwise
|
||||
//-----------------------------------------------------------------------------
|
||||
bool V_ComparePath(const char* a, const char* b)
|
||||
{
|
||||
if (strlen(a) != strlen(b))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Case and separator invariant
|
||||
for (; *a; a++, b++)
|
||||
{
|
||||
if (*a == *b)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (tolower_fast(*a) == tolower_fast(*b))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ((*a == '/' || *a == '\\') &&
|
||||
(*b == '/' || *b == '\\'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Changes all '/' or '\' characters into separator
|
||||
// Input : *pName -
|
||||
|
Loading…
x
Reference in New Issue
Block a user