Fix the sys::Path::getSuffix() implementation.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 15 Jun 2008 15:15:19 +0000 (15:15 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 15 Jun 2008 15:15:19 +0000 (15:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52288 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Path.cpp
lib/System/Unix/Path.inc
lib/System/Win32/Path.inc

index 03cdbf7764ec3613f0d4c5ba983dc8120323c545..af400e95e3cd5127cd8c9492235a3bf23b4bb3eb 100644 (file)
@@ -185,11 +185,6 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
   return false;
 }
 
-std::string
-Path::getSuffix() const {
-  return path.substr(path.rfind('.') + 1);
-}
-
 static void getPathList(const char*path, std::vector<Path>& Paths) {
   const char* at = path;
   const char* delim = strchr(at, PathSeparator);
index 6035a14d27aebb77fb03d71076c25ec96de2cbcb..5b91b038d43d19ec32c722a87ba0bbd6c322cad9 100644 (file)
@@ -303,6 +303,22 @@ Path::getBasename() const {
     return path.substr(slash, dot - slash);
 }
 
+std::string
+Path::getSuffix() const {
+  // Find the last slash
+  std::string::size_type slash = path.rfind('/');
+  if (slash == std::string::npos)
+    slash = 0;
+  else
+    slash++;
+
+  std::string::size_type dot = path.rfind('.');
+  if (dot == std::string::npos || dot < slash)
+    return std::string()
+  else
+    return path.substr(dot + 1);
+}
+
 bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
   assert(len < 1024 && "Request for magic string too long");
   char* buf = (char*) alloca(1 + len);
index b5897053b3c228ea5bb964694aa36068a07d646a..8f3366467ae1c102a1ebf0190c7d1f3a3f0a3c46 100644 (file)
@@ -259,6 +259,22 @@ Path::getBasename() const {
     return path.substr(slash, dot - slash);
 }
 
+std::string
+Path::getSuffix() const {
+  // Find the last slash
+  size_t slash = path.rfind('/');
+  if (slash == std::string::npos)
+    slash = 0;
+  else
+    slash++;
+
+  size_t dot = path.rfind('.');
+  if (dot == std::string::npos || dot < slash)
+    return std::string();
+  else
+    return path.substr(dot + 1);
+}
+
 bool
 Path::exists() const {
   DWORD attr = GetFileAttributes(path.c_str());