15#ifndef GPUCA_STANDALONE
17#include <fmt/format.h>
24std::vector<std::string>
Str::tokenize(
const std::string&
src,
char delim,
bool trimToken,
bool skipEmpty)
26 std::stringstream ss(
src);
28 std::vector<std::string> tokens;
30 while (std::getline(ss, token, delim)) {
34 if (!token.empty() || !skipEmpty) {
35 tokens.push_back(std::move(token));
41std::vector<std::string>
Str::tokenize(
const std::string&
src,
const std::string& delim,
bool trimToken,
bool skipEmpty)
43 std::string inptStr{
src};
44 char* input = inptStr.data();
45 auto mystrtok = [&]() ->
char* {
46 input += std::strspn(input, delim.c_str());
50 char*
const token = input;
51 input += std::strcspn(input, delim.c_str());
57 std::vector<std::string> tokens;
58 while (*input !=
'\0') {
59 std::string token = mystrtok();
63 if (!token.empty() || !skipEmpty) {
64 tokens.push_back(std::move(token));
71int Str::replaceAll(std::string& s,
const std::string& from,
const std::string& to)
75 while ((
pos = s.find(from,
pos)) != std::string::npos) {
76 s.replace(
pos, from.length(), to);
87 auto nextAllowed = [
pid]() {
88 constexpr char chars[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
89 constexpr size_t L =
sizeof(chars) - 1;
90 int rn = std::rand() |
pid;
93 std::string
str(lenght, 0);
94 std::generate_n(
str.begin(), lenght, nextAllowed);
100 return p.compare(0, 8,
"alien://") ? std::filesystem::exists(std::string{p}) :
true;
105 return std::filesystem::is_directory(std::string{p});
110 return std::filesystem::canonical(std::string{p}).
string();
113#ifndef GPUCA_STANDALONE
117 if (dir.empty() || dir ==
"none") {
120 if (p.compare(0, 8,
"alien://") == 0) {
121 if (!gGrid && !TGrid::Connect(
"alien://")) {
122 throw std::runtime_error(fmt::format(
"failed to initialize alien for {}", dir));
131 throw std::runtime_error(fmt::format(
"{} is not an accessible directory", dir));
133 if (dir.back() !=
'/') {
149 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)