Porytiles
Loading...
Searching...
No Matches
utilities.hpp
Go to the documentation of this file.
1#ifndef PORYTILES_UTILITIES_H
2#define PORYTILES_UTILITIES_H
3
4#include <filesystem>
5#include <string>
6#include <vector>
7
8namespace porytiles {
9
10template <typename T>
11T parseInteger(const char *integerString, const int base) {
12 try {
13 std::size_t pos;
14 T arg = std::stoi(integerString, &pos, base);
15 if (std::string{integerString}.size() != pos) {
16 // throw here so it catches below and prints an error message
17 throw std::runtime_error{"invalid integral string: " + std::string{integerString}};
18 }
19 return arg;
20 } catch (const std::exception &e) {
21 throw std::runtime_error{e.what()};
22 }
23 // unreachable, here for compiler
24 throw std::runtime_error("utilities::parseInteger reached unreachable code path");
25}
26
27template <typename T>
28T parseInteger(const char *integerString) {
29 return parseInteger<T>(integerString, 0);
30}
31
32std::vector<std::string> split(std::string input, const std::string &delimiter);
33
34bool checkFullStringMatch(const std::string &str, const std::string &pattern);
35
36void trim(std::string &string);
37
38std::filesystem::path getTmpfilePath(const std::filesystem::path &parentDir, const std::string &fileName);
39
40std::filesystem::path createTmpdir();
41
42std::string palIndexToFileName(std::size_t index);
43
44} // namespace porytiles
45
46#endif // PORYTILES_UTILITIES_H
bool checkFullStringMatch(const std::string &str, const std::string &pattern)
Definition utilities.cpp:30
std::filesystem::path getTmpfilePath(const std::filesystem::path &parentDir, const std::string &fileName)
Definition utilities.cpp:47
std::filesystem::path createTmpdir()
Definition utilities.cpp:51
std::string palIndexToFileName(std::size_t index)
Definition utilities.cpp:74
std::vector< std::string > split(std::string input, const std::string &delimiter)
Definition utilities.cpp:17
T parseInteger(const char *integerString, const int base)
Definition utilities.hpp:11
void trim(std::string &string)
Definition utilities.cpp:39