1 #include <msp/strings/utils.h>
10 string basename(const Path &p)
12 return p.empty() ? string() : p[-1];
15 Path dirname(const Path &p)
25 return p.subpath(0, p.size()-1);
28 string basepart(const string &fn)
30 unsigned dot = fn.rfind('.');
31 return fn.substr(0, dot);
34 string extpart(const string &fn)
36 string::size_type dot = fn.rfind('.');
39 return fn.substr(dot);
42 Path fix_case(const Path &path)
46 for(Path::Iterator i=path.begin(); i!=path.end(); ++i)
48 if(!found || (result.empty() && (*i=="/" || *i==".")))
54 files = list_files(result);
56 files = list_files(".");
59 for(list<string>::iterator j=files.begin(); (j!=files.end() && !found); ++j)
60 if(!strcasecmp(*j,*i))
74 Path relative(const Path &path, const Path &base)
76 if(path.is_absolute()!=base.is_absolute())
77 throw invalid_argument("FS::relative");
79 Path::Iterator i = path.begin();
80 Path::Iterator j = base.begin();
81 for(; (i!=path.end() && j!=base.end() && *i==*j); ++i, ++j) ;
84 for(; j!=base.end(); ++j)
86 for(; i!=path.end(); ++i)
92 Path common_ancestor(const Path &path1, const Path &path2)
94 Path::Iterator i = path1.begin();
95 Path::Iterator j = path2.begin();
97 for(; (i!=path1.end() && j!=path2.end() && *i==*j); ++i, ++j)
102 int descendant_depth(const Path &path, const Path &parent)
104 if(path.is_absolute()!=parent.is_absolute())
105 throw invalid_argument("FS::descendant_depth");
107 Path::Iterator i = path.begin();
108 Path::Iterator j = parent.begin();
109 for(; (i!=path.end() && j!=parent.end() && *i==*j); ++i, ++j) ;
115 for(; i!=path.end(); ++i)