15#ifndef GPUCA_STANDALONE
17#include <fmt/format.h>
23std::vector<std::string>
Str::tokenize(
const std::string&
src,
char delim,
bool trimToken,
bool skipEmpty)
25 std::stringstream ss(
src);
27 std::vector<std::string> tokens;
29 while (std::getline(ss, token, delim)) {
33 if (!token.empty() || !skipEmpty) {
34 tokens.push_back(std::move(token));
41int Str::replaceAll(std::string& s,
const std::string& from,
const std::string& to)
45 while ((
pos = s.find(from,
pos)) != std::string::npos) {
46 s.replace(
pos, from.length(), to);
57 auto nextAllowed = [
pid]() {
58 constexpr char chars[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
59 constexpr size_t L =
sizeof(chars) - 1;
60 int rn = std::rand() |
pid;
63 std::string
str(lenght, 0);
64 std::generate_n(
str.begin(), lenght, nextAllowed);
70 return p.compare(0, 8,
"alien://") ? std::filesystem::exists(std::string{p}) :
true;
75 return std::filesystem::is_directory(std::string{p});
80 return std::filesystem::canonical(std::string{p}).
string();
83#ifndef GPUCA_STANDALONE
87 if (dir.empty() || dir ==
"none") {
90 if (p.compare(0, 8,
"alien://") == 0) {
91 if (!gGrid && !TGrid::Connect(
"alien://")) {
92 throw std::runtime_error(fmt::format(
"failed to initialize alien for {}", dir));
101 throw std::runtime_error(fmt::format(
"{} is not an accessible directory", dir));
103 if (dir.back() !=
'/') {
119 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)