1 #include <msp/strings/utils.h>
10 string basename(const Path &p)
15 Path dirname(const Path &p)
23 return p.subpath(0, p.size()-1);
26 string basepart(const string &fn)
28 unsigned dot = fn.rfind('.');
29 return fn.substr(0, dot);
32 string extpart(const string &fn)
34 string::size_type dot = fn.rfind('.');
37 return fn.substr(dot);
40 Path fix_case(const Path &path)
44 for(Path::Iterator i=path.begin(); i!=path.end(); ++i)
46 if(!found || (result.empty() && (*i=="/" || *i==".")))
52 files = list_files(result);
54 files = list_files(".");
57 for(list<string>::iterator j=files.begin(); (j!=files.end() && !found); ++j)
58 if(!strcasecmp(*j,*i))
72 Path relative(const Path &path, const Path &base)
74 if(path.is_absolute()!=base.is_absolute())
75 throw invalid_argument("FS::relative");
77 Path::Iterator i = path.begin();
78 Path::Iterator j = base.begin();
79 for(; (i!=path.end() && j!=base.end() && *i==*j); ++i, ++j) ;
82 for(; j!=base.end(); ++j)
84 for(; i!=path.end(); ++i)
90 Path common_ancestor(const Path &path1, const Path &path2)
92 Path::Iterator i = path1.begin();
93 Path::Iterator j = path2.begin();
95 for(; (i!=path1.end() && j!=path2.end() && *i==*j); ++i, ++j)
100 int descendant_depth(const Path &path, const Path &parent)
102 if(path.is_absolute()!=parent.is_absolute())
103 throw invalid_argument("FS::descendant_depth");
105 Path::Iterator i = path.begin();
106 Path::Iterator j = parent.begin();
107 for(; (i!=path.end() && j!=parent.end() && *i==*j); ++i, ++j) ;
113 for(; i!=path.end(); ++i)