X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Futils.cpp;h=0ca1d6064e1bd2cfcfa48bd8a3b649efc7333ca0;hp=5c8c8d4cdd08e899336b2bf8d15b3f0170a5be2b;hb=a17d6ad286e19e2222ab8b6c9a762a83bf2c6c56;hpb=f91f1df3e0b00b3a270e571d4b2c8251da4d1226 diff --git a/source/utils.cpp b/source/utils.cpp index 5c8c8d4..0ca1d60 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -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