Avoid creating a redundant zero APInt.
[oota-llvm.git] / lib / System / Unix / Path.inc
index aca4b936e87246c1479f9a3f2777520a6c4a2cf5..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
@@ -297,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);
@@ -566,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;
@@ -639,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