Better organized
This commit is contained in:
33
luprex/syscpp/util.hpp
Normal file
33
luprex/syscpp/util.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef UTIL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace util {
|
||||
|
||||
using stringvec = std::vector<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);
|
||||
|
||||
} // namespace util
|
||||
#endif // UTIL_HPP
|
||||
Reference in New Issue
Block a user