Avoid creating a redundant zero APInt.
[oota-llvm.git] / lib / System / Unix / Path.inc
index c3d06a3fa1d573fe63f47ea3fe4e46ab02b956d1..20d09c0f7ffbbc907a50cab66e34061c15d54c34 100644 (file)
@@ -75,6 +75,12 @@ using namespace sys;
 
 extern const char sys::PathSeparator = ':';
 
+Path::Path(const std::string& p)
+  : path(p) {}
+
+Path::Path(const char *StrStart, unsigned StrLen)
+  : path(StrStart, StrLen) {}
+
 bool 
 Path::isValid() const {
   // Check some obvious things
@@ -277,22 +283,42 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
 }
 
 
+std::string Path::getDirname() const {
+  return getDirnameCharSep(path, '/');
+}
+
 std::string
 Path::getBasename() const {
   // Find the last slash
-  size_t slash = path.rfind('/');
+  std::string::size_type slash = path.rfind('/');
   if (slash == std::string::npos)
     slash = 0;
   else
     slash++;
 
-  size_t dot = path.rfind('.');
+  std::string::size_type dot = path.rfind('.');
   if (dot == std::string::npos || dot < slash)
     return path.substr(slash);
   else
     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);
@@ -562,7 +588,7 @@ Path::createDirectoryOnDisk( bool create_parents, std::string* ErrMsg ) {
   path.copy(pathname,MAXPATHLEN);
 
   // Null-terminate the last component
-  int lastchar = path.length() - 1 ;
+  size_t lastchar = path.length() - 1 ;
   
   if (pathname[lastchar] != '/')
     ++lastchar;
@@ -635,7 +661,7 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
   // Otherwise, try to just remove the one directory.
   char pathname[MAXPATHLEN];
   path.copy(pathname, MAXPATHLEN);
-  int lastchar = path.length() - 1 ; 
+  size_t lastchar = path.length() - 1;
   if (pathname[lastchar] == '/') 
     pathname[lastchar] = 0;
   else