From 780d9e070bec694c12a10162d64196073c6d2ba2 Mon Sep 17 00:00:00 2001
From: KWSys Upstream <kwrobot@kitware.com>
Date: Thu, 25 Jul 2019 07:53:43 -0400
Subject: KWSys 2019-07-25 (a24a6acb)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit a24a6acbbb4a51cf6fefbeb10d1f63ed1b670c69 (master).

Upstream Shortlog
-----------------

Brad King (3):
      15896025 SystemTools: Use C++11 in SystemToolsAppendComponents
      c6f8e24a SystemTools: Fix CollapseFullPath with relative base path
      5ca03af6 SystemTools: Revert "Reduce scope of 'buf' variable in CollapseFullPath"

David Bodnar (5):
      116a4919 RegularExpression: Reduce scope of 'len' variable
      31f5cdeb RegularExpression: Initialize private members on construction
      6e36d909 SystemTools: Reduce scope of 'buf' variable in CollapseFullPath
      a93bc28c SystemTools: Drop unnecessary .c_str()
      6c3dfd25 CommandLineArguments: initialize internal class members directly
---
 CommandLineArguments.cxx |  6 +++---
 RegularExpression.cxx    |  3 +--
 RegularExpression.hxx.in | 18 +++++++++++++++---
 SystemTools.cxx          | 17 +++++++++--------
 testSystemTools.cxx      |  8 ++++++--
 5 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/CommandLineArguments.cxx b/CommandLineArguments.cxx
index a97f7a8..dc9f01d 100644
--- a/CommandLineArguments.cxx
+++ b/CommandLineArguments.cxx
@@ -67,10 +67,10 @@ class CommandLineArgumentsInternal
 {
 public:
   CommandLineArgumentsInternal()
+    : UnknownArgumentCallback{ KWSYS_NULLPTR }
+    , ClientData{ KWSYS_NULLPTR }
+    , LastArgument{ 0 }
   {
-    this->UnknownArgumentCallback = KWSYS_NULLPTR;
-    this->ClientData = KWSYS_NULLPTR;
-    this->LastArgument = 0;
   }
 
   typedef CommandLineArgumentsVectorOfStrings VectorOfStrings;
diff --git a/RegularExpression.cxx b/RegularExpression.cxx
index 5f84b19..3e10765 100644
--- a/RegularExpression.cxx
+++ b/RegularExpression.cxx
@@ -337,7 +337,6 @@ bool RegularExpression::compile(const char* exp)
 {
   const char* scan;
   const char* longest;
-  size_t len;
   int flags;
 
   if (exp == KWSYS_NULLPTR) {
@@ -412,7 +411,7 @@ bool RegularExpression::compile(const char* exp)
     //
     if (flags & SPSTART) {
       longest = KWSYS_NULLPTR;
-      len = 0;
+      size_t len = 0;
       for (; scan != KWSYS_NULLPTR; scan = regnext(scan))
         if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
           longest = OPERAND(scan);
diff --git a/RegularExpression.hxx.in b/RegularExpression.hxx.in
index b7b93f9..ed86418 100644
--- a/RegularExpression.hxx.in
+++ b/RegularExpression.hxx.in
@@ -407,8 +407,12 @@ private:
  * Create an empty regular expression.
  */
 inline RegularExpression::RegularExpression()
+  : regstart{}
+  , reganch{}
+  , regmust{}
+  , program{ 0 }
+  , progsize{}
 {
-  this->program = 0;
 }
 
 /**
@@ -416,8 +420,12 @@ inline RegularExpression::RegularExpression()
  * compiles s.
  */
 inline RegularExpression::RegularExpression(const char* s)
+  : regstart{}
+  , reganch{}
+  , regmust{}
+  , program{ 0 }
+  , progsize{}
 {
-  this->program = 0;
   if (s) {
     this->compile(s);
   }
@@ -428,8 +436,12 @@ inline RegularExpression::RegularExpression(const char* s)
  * compiles s.
  */
 inline RegularExpression::RegularExpression(const std::string& s)
+  : regstart{}
+  , reganch{}
+  , regmust{}
+  , program{ 0 }
+  , progsize{}
 {
-  this->program = 0;
   this->compile(s);
 }
 
diff --git a/SystemTools.cxx b/SystemTools.cxx
index 2135913..36f24c7 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -3394,15 +3394,16 @@ static void SystemToolsAppendComponents(
   static const std::string cur = ".";
   for (std::vector<std::string>::const_iterator i = first; i != last; ++i) {
     if (*i == up) {
-      if (out_components.size() > 1) {
+      // Remove the previous component if possible.  Ignore ../ components
+      // that try to go above the root.  Keep ../ components if they are
+      // at the beginning of a relative path (base path is relative).
+      if (out_components.size() > 1 && out_components.back() != up) {
         out_components.resize(out_components.size() - 1);
+      } else if (!out_components.empty() && out_components[0].empty()) {
+        out_components.emplace_back(std::move(*i));
       }
     } else if (!i->empty() && *i != cur) {
-#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
-      out_components.push_back(std::move(*i));
-#else
-      out_components.push_back(*i);
-#endif
+      out_components.emplace_back(std::move(*i));
     }
   }
 }
@@ -4738,7 +4739,7 @@ void SystemTools::ClassInitialize()
       // Test progressively shorter logical-to-physical mappings.
       std::string cwd_str = cwd;
       std::string pwd_path;
-      Realpath(pwd_str.c_str(), pwd_path);
+      Realpath(pwd_str, pwd_path);
       while (cwd_str == pwd_path && cwd_str != pwd_str) {
         // The current pair of paths is a working logical mapping.
         cwd_changed = cwd_str;
@@ -4748,7 +4749,7 @@ void SystemTools::ClassInitialize()
         // mapping still works.
         pwd_str = SystemTools::GetFilenamePath(pwd_str);
         cwd_str = SystemTools::GetFilenamePath(cwd_str);
-        Realpath(pwd_str.c_str(), pwd_path);
+        Realpath(pwd_str, pwd_path);
       }
 
       // Add the translation to keep the logical path name.
diff --git a/testSystemTools.cxx b/testSystemTools.cxx
index 9a40b53..ffa6a29 100644
--- a/testSystemTools.cxx
+++ b/testSystemTools.cxx
@@ -684,9 +684,10 @@ static bool CheckRelativePaths()
 }
 
 static bool CheckCollapsePath(const std::string& path,
-                              const std::string& expected)
+                              const std::string& expected,
+                              const char* base = nullptr)
 {
-  std::string result = kwsys::SystemTools::CollapseFullPath(path);
+  std::string result = kwsys::SystemTools::CollapseFullPath(path, base);
   if (!kwsys::SystemTools::ComparePath(expected, result)) {
     std::cerr << "CollapseFullPath(" << path << ")  yielded " << result
               << " instead of " << expected << std::endl;
@@ -710,6 +711,9 @@ static bool CheckCollapsePath()
   res &= CheckCollapsePath("C:/", "C:/");
   res &= CheckCollapsePath("C:/../", "C:/");
   res &= CheckCollapsePath("C:/../../", "C:/");
+  res &= CheckCollapsePath("../b", "../../b", "../");
+  res &= CheckCollapsePath("../a/../b", "../b", "../rel");
+  res &= CheckCollapsePath("a/../b", "../rel/b", "../rel");
   return res;
 }
 
-- 
cgit v0.12