Better organized
This commit is contained in:
35
luprex/syscpp/util.cpp
Normal file
35
luprex/syscpp/util.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include "util.hpp"
|
||||
|
||||
namespace util {
|
||||
|
||||
// Read a file as lines.
|
||||
const stringvec read_lines(const std::string &path) {
|
||||
stringvec result;
|
||||
std::ifstream f;
|
||||
f.open(path);
|
||||
if (f) {
|
||||
std::string line;
|
||||
while (std::getline(f, line)) {
|
||||
result.push_back(line);
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Strip leading and trailing whitespace and comments.
|
||||
const stringvec trim_and_uncomment(const stringvec &lines) {
|
||||
stringvec result;
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
std::string trimmed = trim(lines[i]);
|
||||
if ((trimmed.size() > 0) && (trimmed[0] != '#')) {
|
||||
result.push_back(trimmed);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
Reference in New Issue
Block a user