]> git.tdb.fi Git - libs/core.git/blobdiff - source/utils.cpp
Refactor the API
[libs/core.git] / source / utils.cpp
index 5c8c8d4cdd08e899336b2bf8d15b3f0170a5be2b..0ca1d6064e1bd2cfcfa48bd8a3b649efc7333ca0 100644 (file)
@@ -22,11 +22,30 @@ using namespace std;
 namespace Msp {
 namespace FS {
 
-/**
-Fixes the case of the given path to match files / directories on the
-filesystem.  Intended to be used in programs that need to interact with
-emulated Windows programs.
-*/
+string basename(const Path &p)
+{
+       return p[-1];
+}
+
+Path dirname(const Path &p)
+{
+       return p.subpath(0, p.size()-1);
+}
+
+string basepart(const string &fn)
+{
+       unsigned dot=fn.rfind('.');
+       return fn.substr(0, dot);
+}
+
+string extpart(const string &fn)
+{
+       unsigned dot=fn.rfind('.');
+       if(dot==string::npos)
+               return string();
+       return fn.substr(dot);
+}
+
 Path fix_case(const Path &path)
 {
        bool found=true;
@@ -65,25 +84,6 @@ void unlink(const Path &path)
                throw SystemError("unlink failed", errno);
 }
 
-Filename splitext(const string &fn)
-{
-       Filename result;
-       unsigned dot=fn.rfind('.');
-       result.base=fn.substr(0, dot);
-       if(dot!=string::npos)
-               result.ext=fn.substr(dot);
-       return result;
-}
-
-int fnmatch(const string &pat, const Path &fn)
-{
-#ifdef WIN32
-       return globcasematch(pat, fn.str());
-#else
-       return ::fnmatch(pat.c_str(), fn.str().c_str(), FNM_PATHNAME);
-#endif
-}
-
 Path relative(const Path &path, const Path &base)
 {
        Path::Iterator i=path.begin();
@@ -99,18 +99,5 @@ 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 FS
 } // namespace Msp