mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 12:16:40 +08:00
cmStringAlgorithms: Add cmStrLen()
This commit is contained in:
@@ -33,6 +33,13 @@ inline bool cmNonempty(std::string const* str)
|
||||
return str && !str->empty();
|
||||
}
|
||||
|
||||
/** Returns length of a literal string. */
|
||||
template <size_t N>
|
||||
constexpr size_t cmStrLen(const char (&/*str*/)[N])
|
||||
{
|
||||
return N - 1;
|
||||
}
|
||||
|
||||
/** Callable string comparison struct. */
|
||||
struct cmStrCmp
|
||||
{
|
||||
|
@@ -226,5 +226,15 @@ int testStringAlgorithms(int /*unused*/, char* /*unused*/ [])
|
||||
"cmStrToULong rejects trailing content.");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test cmStrLen
|
||||
{
|
||||
constexpr auto len = cmStrLen("Hello world!");
|
||||
assert_ok(len == 12,
|
||||
"cmStrLen returns length of non-empty literal string");
|
||||
assert_ok(cmStrLen("") == 0,
|
||||
"cmStrLen returns length of empty literal string");
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
Reference in New Issue
Block a user