]> git.tdb.fi Git - libs/core.git/blobdiff - source/utils.cpp
strutils.h -> strings/utils.h
[libs/core.git] / source / utils.cpp
index 204f33bfdedcf841e6b4b4e0e090d9caa1824d67..5c7d6a230803bcaf47c08b9e43b21aaeb2e55ae6 100644 (file)
@@ -9,7 +9,7 @@ Distributed under the LGPL
 #ifndef WIN32
 #include <fnmatch.h>
 #endif
-#include <msp/strutils.h>
+#include <msp/strings/utils.h>
 #include "path.h"
 #include "utils.h"
 
@@ -55,6 +55,14 @@ Path fix_case(const Path &path)
        return result;
 }
 
+/**
+Creates the given directory and any parent directories if needed.
+
+@param   path  The path to create
+@param   mode  Access mode for new directories
+
+@return  0 on success, -1 on error
+*/
 int mkpath(const Path &path, int mode)
 {
        Path p;
@@ -173,5 +181,18 @@ Path relative(const Path &path, const Path &base)
        return result;
 }
 
+/**
+Extracts the basename from the given path.  Same thing as Path::Path(p)[-1],
+but faster.
+*/
+string basename(const std::string &p)
+{
+       unsigned slash=p.rfind(DIRCHAR);
+       if(slash==string::npos)
+               return p;
+       else
+               return p.substr(slash+1);
+}
+
 } // namespace Path
 } // namespace Msp