20std::vector<std::string>
Str::tokenize(
const std::string&
src,
char delim,
bool trimToken,
bool skipEmpty)
22 std::stringstream ss(
src);
24 std::vector<std::string> tokens;
26 while (std::getline(ss, token, delim)) {
30 if (!token.empty() || !skipEmpty) {
31 tokens.push_back(std::move(token));
38int Str::replaceAll(std::string& s,
const std::string& from,
const std::string& to)
42 while ((
pos = s.find(from,
pos)) != std::string::npos) {
43 s.replace(
pos, from.length(), to);
54 auto nextAllowed = [
pid]() {
55 constexpr char chars[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
56 constexpr size_t L =
sizeof(chars) - 1;
57 int rn = std::rand() |
pid;
60 std::string
str(lenght, 0);
61 std::generate_n(
str.begin(), lenght, nextAllowed);
67 return p.compare(0, 8,
"alien://") ? std::filesystem::exists(std::string{p}) :
true;
72 return std::filesystem::is_directory(std::string{p});
77 return std::filesystem::canonical(std::string{p}).
string();
83 if (dir.empty() || dir ==
"none") {
86 if (p.compare(0, 8,
"alien://") == 0) {
87 if (!gGrid && !TGrid::Connect(
"alien://")) {
88 throw std::runtime_error(fmt::format(
"failed to initialize alien for {}", dir));
97 throw std::runtime_error(fmt::format(
"{} is not an accessible directory", dir));
99 if (dir.back() !=
'/') {
114 bool needSlash =
pathIsDirectory(prefix) && !prefix.empty() && prefix.back() !=
'/';
GLuint GLsizei GLsizei * length
GLsizei const GLchar *const * path
static bool pathIsDirectory(const std::string_view p)
static void trim(std::string &s)
static std::string rectifyDirectory(const std::string_view p)
static bool pathExists(const std::string_view p)
static std::vector< std::string > tokenize(const std::string &src, char delim, bool trimToken=true, bool skipEmpty=true)
static int replaceAll(std::string &s, const std::string &from, const std::string &to)
static std::string concat_string(Ts const &... ts)
static std::string getFullPath(const std::string_view p)
static std::string create_unique_path(const std::string_view prefix="", int length=16)
static bool endsWith(const std::string &s, const std::string &ending)
static std::string getRandomString(int length)