瀏覽代碼

cmSystemTool: Let TrimWhitespace accept a cm::string_view

Sebastian Holtermann 6 年之前
父節點
當前提交
09977c1816
共有 2 個文件被更改,包括 7 次插入7 次删除
  1. 6 6
      Source/cmSystemTools.cxx
  2. 1 1
      Source/cmSystemTools.h

+ 6 - 6
Source/cmSystemTools.cxx

@@ -197,16 +197,16 @@ std::string cmSystemTools::HelpFileName(cm::string_view str)
   return name;
 }
 
-std::string cmSystemTools::TrimWhitespace(const std::string& s)
+std::string cmSystemTools::TrimWhitespace(cm::string_view str)
 {
-  std::string::const_iterator start = s.begin();
-  while (start != s.end() && cm_isspace(*start)) {
+  auto start = str.begin();
+  while (start != str.end() && cm_isspace(*start)) {
     ++start;
   }
-  if (start == s.end()) {
-    return "";
+  if (start == str.end()) {
+    return std::string();
   }
-  std::string::const_iterator stop = s.end() - 1;
+  auto stop = str.end() - 1;
   while (cm_isspace(*stop)) {
     --stop;
   }

+ 1 - 1
Source/cmSystemTools.h

@@ -86,7 +86,7 @@ public:
   /**
    * Returns a string that has whitespace removed from the start and the end.
    */
-  static std::string TrimWhitespace(const std::string& s);
+  static std::string TrimWhitespace(cm::string_view str);
 
   using MessageCallback = std::function<void(const std::string&, const char*)>;
   /**