feat(util/lean_path): add dirname and path_append aux functions
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
700c911cf7
commit
8768197c24
2 changed files with 30 additions and 0 deletions
|
@ -267,4 +267,31 @@ void display_path(std::ostream & out, std::string const & fname) {
|
||||||
out << fname;
|
out << fname;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string dirname(char const * fname) {
|
||||||
|
if (fname == nullptr)
|
||||||
|
return ".";
|
||||||
|
unsigned i = 0;
|
||||||
|
optional<unsigned> last_sep;
|
||||||
|
char const * it = fname;
|
||||||
|
while (*it) {
|
||||||
|
if (*it == g_sep)
|
||||||
|
last_sep = i;
|
||||||
|
++i;
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
if (!last_sep)
|
||||||
|
return ".";
|
||||||
|
std::string r;
|
||||||
|
for (unsigned i = 0; i < *last_sep; i++)
|
||||||
|
r.push_back(fname[i]);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string path_append(char const * p1, char const * p2) {
|
||||||
|
std::string r(p1);
|
||||||
|
r += g_sep;
|
||||||
|
r += p2;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,7 @@ std::string name_to_file(name const & fname);
|
||||||
In some platforms it will fix the notation used to display the path.
|
In some platforms it will fix the notation used to display the path.
|
||||||
*/
|
*/
|
||||||
void display_path(std::ostream & out, std::string const & fname);
|
void display_path(std::ostream & out, std::string const & fname);
|
||||||
|
|
||||||
|
std::string dirname(char const * fname);
|
||||||
|
std::string path_append(char const * path1, char const * path2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue