appendSuffix: don't append a dot when the suffix is empty.
authorMikhail Glushenkov <foldr@codedgers.com>
Tue, 2 Nov 2010 22:18:37 +0000 (22:18 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Tue, 2 Nov 2010 22:18:37 +0000 (22:18 +0000)
Additionally, move the implementation of appendSuffix to Path.cpp: it is
platform-independent.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118089 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Path.h
lib/System/Path.cpp
lib/System/Unix/Path.inc
lib/System/Win32/Path.inc

index c13f2e8d6c41315ffb05df3643534c30af93d81b..20495287b140519bfdba7ea42e4ae3d81c7a61fe 100644 (file)
@@ -454,7 +454,8 @@ namespace sys {
       /// The precondition for this function is that the Path reference a file
       /// name (i.e. isFile() returns true). If the Path is not a file, no
       /// action is taken and the function returns false. If the path would
-      /// become invalid for the host operating system, false is returned.
+      /// become invalid for the host operating system, false is returned. When
+      /// the \p suffix is empty, no action is performed.
       /// @returns false if the suffix could not be added, true if it was.
       /// @brief Adds a period and the \p suffix to the end of the pathname.
       bool appendSuffix(StringRef suffix);
index 8fc4153acb1ad60a2600e4b2f2a67c3124c971ae..5d8de65661273e159b8d7051f1e03f3da7fa687c 100644 (file)
@@ -195,6 +195,21 @@ StringRef Path::GetDLLSuffix() {
   return &(LTDL_SHLIB_EXT[1]);
 }
 
+bool
+Path::appendSuffix(StringRef suffix) {
+  if (!suffix.empty()) {
+    std::string save(path);
+    path.append(".");
+    path.append(suffix);
+    if (!isValid()) {
+      path = save;
+      return false;
+    }
+  }
+
+  return true;
+}
+
 bool
 Path::isBitcodeFile() const {
   std::string actualMagic;
index 15588689f925df5cb185bc05483a1e114fcece9b..b1d2ad24465b1b0642cfa5250e64b24490eb9ae1 100644 (file)
@@ -637,18 +637,6 @@ Path::eraseComponent() {
   return true;
 }
 
-bool
-Path::appendSuffix(StringRef suffix) {
-  std::string save(path);
-  path.append(".");
-  path.append(suffix);
-  if (!isValid()) {
-    path = save;
-    return false;
-  }
-  return true;
-}
-
 bool
 Path::eraseSuffix() {
   std::string save = path;
index ea6d4639ba7e6aa2cbe1166696f53be5207c2ebf..2ead80127b3a14159be691cccb7a6c19e9fd28f6 100644 (file)
@@ -551,18 +551,6 @@ Path::eraseComponent() {
   return true;
 }
 
-bool
-Path::appendSuffix(StringRef suffix) {
-  std::string save(path);
-  path.append(".");
-  path.append(suffix);
-  if (!isValid()) {
-    path = save;
-    return false;
-  }
-  return true;
-}
-
 bool
 Path::eraseSuffix() {
   size_t dotpos = path.rfind('.',path.size());