From bd6e0323b94361559e125b07cb244629b0da0281 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Tue, 2 Nov 2010 22:18:37 +0000 Subject: [PATCH] appendSuffix: don't append a dot when the suffix is empty. 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 | 3 ++- lib/System/Path.cpp | 15 +++++++++++++++ lib/System/Unix/Path.inc | 12 ------------ lib/System/Win32/Path.inc | 12 ------------ 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h index c13f2e8d6c4..20495287b14 100644 --- a/include/llvm/System/Path.h +++ b/include/llvm/System/Path.h @@ -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); diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp index 8fc4153acb1..5d8de656612 100644 --- a/lib/System/Path.cpp +++ b/lib/System/Path.cpp @@ -196,6 +196,21 @@ StringRef Path::GetDLLSuffix() { } 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; if (!getMagicNumber(actualMagic, 4)) diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 15588689f92..b1d2ad24465 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -638,18 +638,6 @@ Path::eraseComponent() { } 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; size_t dotpos = path.rfind('.',path.size()); diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index ea6d4639ba7..2ead80127b3 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -552,18 +552,6 @@ Path::eraseComponent() { } 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()); size_t slashpos = path.rfind('/',path.size()); -- 2.11.0