19 #include <sys/types.h>
33 const std::vector<T> &v)
36 for (
const T &p : v){ os << p <<
" ";}
45 bool contains(
const std::vector<std::string>& v,
const std::string& other){
46 for (
const auto& entry: v){
47 if (entry.compare(other) == 0){
65 return (stat (name.c_str(), &buffer) == 0);
76 stat(foldername.c_str(), &st);
77 return st.st_mode & S_IFDIR;
105 std::string current_level =
"";
107 std::stringstream ss(path);
110 while (std::getline(ss, level,
'/'))
112 current_level += level;
118 current_level +=
"/";
132 std::vector<std::string>
list_dir(
const std::string& path,
133 const std::string& pattern =
".*") {
135 struct dirent *entry;
136 DIR *dir = opendir(path.c_str());
137 const std::regex txt_regex(pattern);
139 std::vector<std::string> results;
143 while ((entry = readdir(dir)) != NULL) {
144 if (std::regex_match(entry->d_name, txt_regex)){
145 results.push_back(path +
"/" + entry->d_name);
162 const std::string & delimiter){
166 std::vector<std::string> tokens;
167 while ((pos = s.find(delimiter)) != std::string::npos) {
168 token = s.substr(0, pos);
169 tokens.push_back(token);
170 s.erase(0, pos + delimiter.length());
181 std::transform(s.begin(), s.end(), s.begin(),
182 [](
unsigned char c){ return std::toupper(c); }
191 std::transform(s.begin(), s.end(), s.begin(),
192 [](
unsigned char c){ return std::tolower(c); }
206 template<
typename... Args >
208 int length = std::snprintf(
nullptr, 0, format, args... );
209 assert( length >= 0 );
211 char* buf =
new char[length + 1];
212 std::snprintf( buf, length + 1, format, args... );
214 std::string str( buf );
226 template <
typename T>
228 T d = std::atof(txt);
239 template <
typename T>
241 T d = std::atof(txt.c_str());
246 // vim: expandtab:ts=4:softtabstop=4:shiftwidth=4