Add 'V_ComparePath'

Add function to compare paths for equality, while ignoring case and path separators.
This commit is contained in:
Kawe Mazidjatari 2023-07-10 19:16:12 +02:00
parent 6f441292d0
commit dbb18e586d
2 changed files with 36 additions and 0 deletions

View File

@ -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.

View File

@ -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 -