17std::vector<std::string>
split(std::string input,
const std::string &delimiter) {
18 std::vector<std::string> result;
21 while ((pos = input.find(delimiter)) != std::string::npos) {
22 token = input.substr(0, pos);
23 result.push_back(token);
24 input.erase(0, pos + delimiter.length());
26 result.push_back(input);
32 const std::regex re{pattern};
33 return std::regex_match(str, re);
34 }
catch (
const std::regex_error &e) {
35 throw std::runtime_error{e.what()};
39void trim(std::string &
string) {
40 string.erase(
string.begin(),
41 std::find_if(
string.begin(),
string.end(), [](
unsigned char ch) {
return !std::isspace(ch); }));
43 std::find_if(
string.rbegin(),
string.rend(), [](
unsigned char ch) {
return !std::isspace(ch); }).base(),
47std::filesystem::path
getTmpfilePath(
const std::filesystem::path &parentDir,
const std::string &fileName) {
48 return std::filesystem::temp_directory_path() / parentDir / fileName;
53 auto tmpDir = std::filesystem::temp_directory_path();
55 std::random_device randomDevice;
56 std::mt19937 mersennePrng(randomDevice());
57 std::uniform_int_distribution<uint64_t> uniformIntDistribution(0);
58 std::filesystem::path path;
60 std::stringstream stringStream;
61 stringStream << std::hex << uniformIntDistribution(mersennePrng);
62 path = tmpDir / (
"porytiles_" + stringStream.str());
63 if (std::filesystem::create_directory(path)) {
67 Panic(
"tmpfiles::createTmpdir getTmpdirPath took too many tries");
75 std::string file = std::to_string(index) +
".png";
void Panic(const StringViewSourceLoc &s) noexcept
bool checkFullStringMatch(const std::string &str, const std::string &pattern)
std::filesystem::path getTmpfilePath(const std::filesystem::path &parentDir, const std::string &fileName)
std::filesystem::path createTmpdir()
std::string palIndexToFileName(std::size_t index)
std::vector< std::string > split(std::string input, const std::string &delimiter)
void trim(std::string &string)