diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2021-08-15 15:27:47 +0200 |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2021-08-19 10:49:30 +0200 |
commit | 2984df91002fe3e3db0d38f364e9842024a8ab2e (patch) | |
tree | f7b14050b6beddd7d828e7ed0e90491b6eb17922 /Source | |
parent | 5917b6277fc171fc61d0b277af9bf5950915f863 (diff) | |
download | cmake-2984df91002fe3e3db0d38f364e9842024a8ab2e.tar.gz |
Refactor: cmHasPrefix and cmHasSuffix accept now cmProp
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmStringAlgorithms.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/cmStringAlgorithms.h b/Source/cmStringAlgorithms.h index 531678ad22..20061e9af1 100644 --- a/Source/cmStringAlgorithms.h +++ b/Source/cmStringAlgorithms.h @@ -291,6 +291,16 @@ inline bool cmHasPrefix(cm::string_view str, cm::string_view prefix) } /** Returns true if string @a str starts with string @a prefix. */ +inline bool cmHasPrefix(cm::string_view str, cmProp prefix) +{ + if (!prefix) { + return false; + } + + 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]) { @@ -311,6 +321,17 @@ inline bool cmHasSuffix(cm::string_view str, cm::string_view suffix) } /** Returns true if string @a str ends with string @a suffix. */ +inline bool cmHasSuffix(cm::string_view str, cmProp suffix) +{ + if (!suffix) { + return false; + } + + return str.size() >= suffix->size() && + 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]) { |