Merge topic 'update-kwsys'

c029b4a098 Merge branch 'upstream-KWSys' into update-kwsys
fd4084d93e KWSys 2026-06-23 (aa992d52)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12208
This commit is contained in:
Brad King
2026-06-23 13:49:40 +00:00
committed by Kitware Robot
3 changed files with 63 additions and 1 deletions

View File

@@ -2728,6 +2728,22 @@ int SystemTools::Strucmp(char const* l, char const* r)
return lc - rc;
}
int SystemTools::Strnucmp(char const* l, char const* r, size_t n)
{
int lc;
int rc;
size_t count = 0;
do {
lc = kwsysString_tolower(*l++);
rc = kwsysString_tolower(*r++);
count++;
if (count >= n) {
return lc - rc;
}
} while (lc == rc && lc);
return lc - rc;
}
// return file's modified time
long int SystemTools::ModifiedTime(std::string const& filename)
{

View File

@@ -198,10 +198,17 @@ public:
char separator = '/',
bool isPath = false);
/**
* Perform a case-independent string comparison
* Perform a case-independent string comparison.
* Similar to POSIX's strcasecmp.
*/
static int Strucmp(char const* s1, char const* s2);
/**
* Perform a case-independent string comparison, but compares at most n
* characters. Similar to POSIX's strncasecmp.
*/
static int Strnucmp(char const* s1, char const* s2, size_t n);
/**
* Split a string on its newlines into multiple lines
* Return false only if the last line stored had no newline

View File

@@ -1317,6 +1317,43 @@ static bool CheckSplitString()
return ret;
}
static bool CheckStringComparisons()
{
if (!(kwsys::SystemTools::Strucmp("", "") == 0))
return false;
if (!(kwsys::SystemTools::Strucmp("bob", "bob") == 0))
return false;
if (!(kwsys::SystemTools::Strucmp("bob", "BOB") == 0))
return false;
if (!(kwsys::SystemTools::Strucmp("bob1", "BoB2") < 0))
return false;
if (!(kwsys::SystemTools::Strucmp("bOb4", "Bob3") > 0))
return false;
if (!(kwsys::SystemTools::Strucmp("aaa", "aaaaaaaaa") < 0))
return false;
if (!(kwsys::SystemTools::Strucmp("aaaaaaaaa", "aaa") > 1))
return false;
if (!(kwsys::SystemTools::Strnucmp("", "", 0) == 0))
return false;
if (!(kwsys::SystemTools::Strnucmp("", "", 3000) == 0))
return false;
if (!(kwsys::SystemTools::Strnucmp("bob", "Bobby", 3) == 0))
return false;
if (!(kwsys::SystemTools::Strnucmp("Bob", "boBBy", 3) == 0))
return false;
if (!(kwsys::SystemTools::Strnucmp("bob", "Bobby", 3000) < 0))
return false;
if (!(kwsys::SystemTools::Strnucmp("bobbY", "BOB", 3000) > 0))
return false;
if (!(kwsys::SystemTools::Strnucmp("bobb", "Bobby", 5) < 0))
return false;
if (!(kwsys::SystemTools::Strnucmp("bobbY", "BOBb", 5) > 0))
return false;
return true;
}
int testSystemTools(int, char*[])
{
bool res = true;
@@ -1370,5 +1407,7 @@ int testSystemTools(int, char*[])
res &= CheckSplitString();
res &= CheckStringComparisons();
return res ? 0 : 1;
}