mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
cmAlgorithms: Make cmHasLiteral{Prefix,Suffix} cm::string_view based
This commit is contained in:
@@ -19,44 +19,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
inline bool cmHasLiteralPrefixImpl(const std::string& str1, const char* str2,
|
||||
size_t N)
|
||||
{
|
||||
return strncmp(str1.c_str(), str2, N) == 0;
|
||||
}
|
||||
|
||||
inline bool cmHasLiteralPrefixImpl(const char* str1, const char* str2,
|
||||
size_t N)
|
||||
{
|
||||
return strncmp(str1, str2, N) == 0;
|
||||
}
|
||||
|
||||
inline bool cmHasLiteralSuffixImpl(const std::string& str1, const char* str2,
|
||||
size_t N)
|
||||
{
|
||||
size_t len = str1.size();
|
||||
return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
|
||||
}
|
||||
|
||||
inline bool cmHasLiteralSuffixImpl(const char* str1, const char* str2,
|
||||
size_t N)
|
||||
{
|
||||
size_t len = strlen(str1);
|
||||
return len >= N && strcmp(str1 + len - N, str2) == 0;
|
||||
}
|
||||
|
||||
template <typename T, size_t N>
|
||||
bool cmHasLiteralPrefix(const T& str1, const char (&str2)[N])
|
||||
{
|
||||
return cmHasLiteralPrefixImpl(str1, str2, N - 1);
|
||||
}
|
||||
|
||||
template <typename T, size_t N>
|
||||
bool cmHasLiteralSuffix(const T& str1, const char (&str2)[N])
|
||||
{
|
||||
return cmHasLiteralSuffixImpl(str1, str2, N - 1);
|
||||
}
|
||||
|
||||
struct cmStrCmp
|
||||
{
|
||||
cmStrCmp(const char* test)
|
||||
@@ -327,6 +289,13 @@ inline bool cmHasPrefix(cm::string_view str, cm::string_view prefix)
|
||||
return str.compare(0, prefix.size(), prefix) == 0;
|
||||
}
|
||||
|
||||
/** Returns true if string @a str starts with string @a prefix. **/
|
||||
template <size_t N>
|
||||
inline bool cmHasLiteralPrefix(cm::string_view str, const char (&prefix)[N])
|
||||
{
|
||||
return cmHasPrefix(str, cm::string_view(prefix, N - 1));
|
||||
}
|
||||
|
||||
/** Returns true if string @a str ends with the character @a suffix. **/
|
||||
inline bool cmHasSuffix(cm::string_view str, char suffix)
|
||||
{
|
||||
@@ -340,6 +309,13 @@ inline bool cmHasSuffix(cm::string_view str, cm::string_view suffix)
|
||||
str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
|
||||
}
|
||||
|
||||
/** Returns true if string @a str ends with string @a suffix. **/
|
||||
template <size_t N>
|
||||
inline bool cmHasLiteralSuffix(cm::string_view str, const char (&suffix)[N])
|
||||
{
|
||||
return cmHasSuffix(str, cm::string_view(suffix, N - 1));
|
||||
}
|
||||
|
||||
/** Removes an existing suffix character of from the string @a str. **/
|
||||
inline void cmStripSuffixIfExists(std::string& str, char suffix)
|
||||
{
|
||||
|
||||
@@ -146,8 +146,7 @@ bool cmSourceFileLocation::MatchesAmbiguousExtension(
|
||||
// adding an extension.
|
||||
if (!(this->Name.size() > loc.Name.size() &&
|
||||
this->Name[loc.Name.size()] == '.' &&
|
||||
cmHasLiteralPrefixImpl(this->Name.c_str(), loc.Name.c_str(),
|
||||
loc.Name.size()))) {
|
||||
cmHasPrefix(this->Name, loc.Name))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user