texdepends/fs.hpp

68 lines
1.5 KiB
C++

/*
* fs.hpp
*
* Created on: 08.10.2017
* Author: julian
*/
#ifndef FS_HPP_
#define FS_HPP_
#include <string>
#include <tuple>
namespace Path {
typedef std::string Path;
// cleanup double path limiters
Path Clean(const Path &p);
inline Path Join(const Path &a, const Path &b) {
if (a.empty()) return b;
if (b.empty()) return a;
return a + "/" + b;
}
// Join n path parts together
template <typename ...T>
inline Path Join(const Path &p, T ... list) {
return Path(p) + "/" + Join(list...);
}
// Split a path into the name and the remainder
// e.g. "a/b/c.d becomes (a/b, c.d)
std::tuple<Path, Path> Split(const Path &path);
// strips the path of the filename
Path Dir(const Path &path);
// returns just the filename
Path Name(const Path &path);
// returns the filename's extension as string
// or empty if the path points to a directory
std::string Extension(const Path &path);
// returns the filename stripped of the first extension
// or empty if the path points to a directory
std::string Basename(const Path &path);
inline bool isRelative(const Path &path) { return path.size() && path.front() != '/'; }
inline bool isAbsolute(const Path &path) { return path.size() && path.front() == '/'; }
inline bool isDir(const Path &path) { return path.size() && path.back() == '/'; }
inline bool isFile(const Path &path) { return path.size() && path.back() != '/'; }
}
namespace fs {
// return the current working directory
Path::Path cwd();
}
#endif /* FS_HPP_ */