40 lines
994 B
C++
40 lines
994 B
C++
#ifndef UTIL_HPP
|
|
#define UTIL_HPP
|
|
|
|
#include <string>
|
|
#include <set>
|
|
#include <algorithm>
|
|
#include <sstream>
|
|
|
|
namespace util {
|
|
|
|
using stringvec = std::vector<std::string>;
|
|
using stringset = std::set<std::string>;
|
|
|
|
// trim from start
|
|
static inline std::string ltrim(std::string s) {
|
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
|
std::not1(std::ptr_fun<int, int>(std::isspace))));
|
|
return s;
|
|
}
|
|
|
|
// trim from end
|
|
static inline std::string rtrim(std::string s) {
|
|
s.erase(std::find_if(s.rbegin(), s.rend(),
|
|
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
|
return s;
|
|
}
|
|
|
|
// trim from both ends
|
|
static inline std::string trim(std::string s) {
|
|
return ltrim(rtrim(s));
|
|
}
|
|
|
|
const stringvec read_lines(const std::string &path);
|
|
const stringvec trim_and_uncomment(const stringvec &lines);
|
|
std::string get_file_fingerprint(const std::string &path);
|
|
std::string get_file_contents(const std::string &fn);
|
|
|
|
} // namespace util
|
|
#endif // UTIL_HPP
|