12 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
14 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
16 std::vector<std::string> tokens;
17 while (std::string::npos != pos || std::string::npos != lastPos)
20 tokens.push_back(str.substr(lastPos, pos - lastPos));
22 lastPos = str.find_first_not_of(delimiters, pos);
24 pos = str.find_first_of(delimiters, lastPos);
34 while ((in >> std::ws).peek() == std::char_traits<char>::to_int_type(
x))
36 std::getline(in, dummy);
44 return (str.compare(0, prefix.size(), prefix) == 0);
50 if (str.length() >= suffix.length())
52 return (0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix));
66 ext = (newext[0] ==
'.' ? newext :
"." + newext);
68 size_t lastdot = filename.find_last_of(
".");
69 if (lastdot == std::string::npos)
71 return filename + ext;
73 return filename.substr(0, lastdot) + ext;
79 inline std::string ltrim(
const std::string &s)
81 static const std::string WHITESPACE =
" \n\r\t";
83 size_t startpos = s.find_first_not_of(WHITESPACE);
84 return (startpos == std::string::npos) ?
"" : s.substr(startpos);
88 inline std::string rtrim(
const std::string &s)
90 static const std::string WHITESPACE =
" \n\r\t";
92 size_t endpos = s.find_last_not_of(WHITESPACE);
93 return (endpos == std::string::npos) ?
"" : s.substr(0, endpos + 1);
100 return rtrim(ltrim(
string));
104 const std::string &path,
105 const std::string &input_file_path,
106 const bool only_if_exists)
113 std::filesystem::path resolved_path(path);
114 if (resolved_path.is_absolute())
116 return resolved_path.string();
118 else if (std::filesystem::exists(resolved_path))
120 return std::filesystem::weakly_canonical(resolved_path).string();
123 std::filesystem::path input_dir_path(input_file_path);
124 if (!std::filesystem::is_directory(input_dir_path))
125 input_dir_path = input_dir_path.parent_path();
127 resolved_path = std::filesystem::weakly_canonical(input_dir_path / resolved_path);
129 if (only_if_exists && !std::filesystem::exists(resolved_path))
133 return resolved_path.string();
std::istream & skip(std::istream &in, char x='#')
std::string trim(const std::string &string)
bool startswith(const std::string &str, const std::string &prefix)
std::vector< std::string > split(const std::string &str, const std::string &delimiters=" ")
bool endswith(const std::string &str, const std::string &suffix)
std::string replace_ext(const std::string &filename, const std::string &newext)
std::string resolve_path(const std::string &path, const std::string &input_file_path, const bool only_if_exists=false)