Преглед изворни кода

Merge topic 'update-kwsys'

51e3b1b4b2 cmSystemTools: Simplify string case conversion methods
bc89442828 Merge branch 'upstream-KWSys' into update-kwsys
f4258b93d2 KWSys 2026-02-08 (29120a5d)
85a4d0cde7 cmList: Simplify overload selection for function pointer

Acked-by: Kitware Robot <[email protected]>
Merge-request: !11669
Brad King пре 1 недеља
родитељ
комит
860ba3d6b5
5 измењених фајлова са 26 додато и 61 уклоњено
  1. 3 3
      Source/cmList.cxx
  2. 0 24
      Source/cmSystemTools.cxx
  3. 10 8
      Source/cmSystemTools.h
  4. 9 18
      Source/kwsys/SystemTools.cxx
  5. 4 8
      Source/kwsys/SystemTools.hxx.in

+ 3 - 3
Source/cmList.cxx

@@ -114,9 +114,9 @@ protected:
 
   StringFilter GetCaseFilter(CaseSensitivity sensitivity)
   {
-    constexpr std::string (*filter)(std::string const&) =
-      cmSystemTools::LowerCase;
-    return (sensitivity == CaseSensitivity::INSENSITIVE) ? filter : nullptr;
+    return (sensitivity == CaseSensitivity::INSENSITIVE)
+      ? cmsys::SystemTools::LowerCase
+      : nullptr;
   }
 
   using ComparisonFunction =

+ 0 - 24
Source/cmSystemTools.cxx

@@ -457,30 +457,6 @@ void cmSystemTools::ExpandRegistryValues(std::string& source,
 }
 #endif
 
-// Return a lower case string
-std::string cmSystemTools::LowerCase(cm::string_view s)
-{
-  std::string n;
-  n.resize(s.size());
-  for (size_t i = 0; i < s.size(); i++) {
-    n[i] = static_cast<std::string::value_type>(
-      tolower(static_cast<unsigned char>(s[i])));
-  }
-  return n;
-}
-
-// Return an upper case string
-std::string cmSystemTools::UpperCase(cm::string_view s)
-{
-  std::string n;
-  n.resize(s.size());
-  for (size_t i = 0; i < s.size(); i++) {
-    n[i] = static_cast<std::string::value_type>(
-      toupper(static_cast<unsigned char>(s[i])));
-  }
-  return n;
-}
-
 std::string cmSystemTools::HelpFileName(cm::string_view str)
 {
   std::string name(str);

+ 10 - 8
Source/cmSystemTools.h

@@ -40,20 +40,22 @@ public:
   using Superclass = cmsys::SystemTools;
   using Encoding = cmProcessOutput::Encoding;
 
-  /**
-   * Return a lower case string
-   */
-  static std::string LowerCase(cm::string_view);
+  /** Return a lower-case string.  */
+  static std::string LowerCase(cm::string_view s)
+  {
+    return cmsys::SystemTools::LowerCase(std::string(s));
+  }
   static std::string LowerCase(char const* s)
   {
     return LowerCase(cm::string_view{ s });
   }
   using cmsys::SystemTools::LowerCase;
 
-  /**
-   * Return an upper case string
-   */
-  static std::string UpperCase(cm::string_view);
+  /** Return an upper-case string.  */
+  static std::string UpperCase(cm::string_view s)
+  {
+    return cmsys::SystemTools::UpperCase(std::string(s));
+  }
   static std::string UpperCase(char const* s)
   {
     return UpperCase(cm::string_view{ s });

+ 9 - 18
Source/kwsys/SystemTools.cxx

@@ -27,6 +27,7 @@
 #include KWSYS_HEADER(Encoding.hxx)
 
 #include <algorithm>
+#include <cctype>
 #include <fstream>
 #include <iostream>
 #include <set>
@@ -1768,28 +1769,18 @@ char* SystemTools::AppendStrings(char const* str1, char const* str2,
   return newstr;
 }
 
-// Return a lower case string
-std::string SystemTools::LowerCase(std::string const& s)
+std::string SystemTools::LowerCase(std::string s)
 {
-  std::string n;
-  n.resize(s.size());
-  for (size_t i = 0; i < s.size(); i++) {
-    n[i] = static_cast<std::string::value_type>(
-      tolower(static_cast<unsigned char>(s[i])));
-  }
-  return n;
+  std::transform(s.begin(), s.end(), s.begin(),
+                 [](unsigned char c) { return std::tolower(c); });
+  return s;
 }
 
-// Return a lower case string
-std::string SystemTools::UpperCase(std::string const& s)
+std::string SystemTools::UpperCase(std::string s)
 {
-  std::string n;
-  n.resize(s.size());
-  for (size_t i = 0; i < s.size(); i++) {
-    n[i] = static_cast<std::string::value_type>(
-      toupper(static_cast<unsigned char>(s[i])));
-  }
-  return n;
+  std::transform(s.begin(), s.end(), s.begin(),
+                 [](unsigned char c) { return std::toupper(c); });
+  return s;
 }
 
 // Count char in string

+ 4 - 8
Source/kwsys/SystemTools.hxx.in

@@ -133,15 +133,11 @@ public:
    */
   static std::string UnCapitalizedWords(std::string const&);
 
-  /**
-   * Return a lower case string
-   */
-  static std::string LowerCase(std::string const&);
+  /** Return a lower-case string.  */
+  static std::string LowerCase(std::string);
 
-  /**
-   * Return a lower case string
-   */
-  static std::string UpperCase(std::string const&);
+  /** Return an upper-case string.  */
+  static std::string UpperCase(std::string);
 
   /**
    * Count char in string