浏览代码

cmAlgorithms: Add cmHasPrefix to match existing cmHasSuffix

Brad King 6 年之前
父节点
当前提交
2ad14ef4ea
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      Source/cmAlgorithms.h

+ 8 - 0
Source/cmAlgorithms.h

@@ -336,6 +336,14 @@ std::reverse_iterator<Iter> cmMakeReverseIterator(Iter it)
   return std::reverse_iterator<Iter>(it);
 }
 
+inline bool cmHasPrefix(std::string const& str, std::string const& prefix)
+{
+  if (str.size() < prefix.size()) {
+    return false;
+  }
+  return str.compare(0, prefix.size(), prefix) == 0;
+}
+
 inline bool cmHasSuffix(const std::string& str, const std::string& suffix)
 {
   if (str.size() < suffix.size()) {