Browse Source

Removed filesystem::read_lines

pipelines/235045657
eidheim 6 years ago
parent
commit
cd0082da8d
  1. 10
      src/cmake.cpp
  2. 13
      src/filesystem.cpp
  3. 3
      src/filesystem.hpp
  4. 8
      src/meson.cpp

10
src/cmake.cpp

@ -9,13 +9,17 @@
#include <regex> #include <regex>
CMake::CMake(const boost::filesystem::path &path) { CMake::CMake(const boost::filesystem::path &path) {
const auto find_cmake_project = [](const boost::filesystem::path &cmake_path) { const auto find_cmake_project = [](const boost::filesystem::path &file_path) {
for(auto &line : filesystem::read_lines(cmake_path)) { std::ifstream input(file_path.string(), std::ofstream::binary);
const static std::regex project_regex(R"(^ *project *\(.*\r?$)", std::regex::icase); if(input) {
std::string line;
while(std::getline(input, line)) {
const static std::regex project_regex("^ *project *\\(.*$", std::regex::icase);
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, project_regex)) if(std::regex_match(line, sm, project_regex))
return true; return true;
} }
}
return false; return false;
}; };

13
src/filesystem.cpp

@ -20,19 +20,6 @@ std::string filesystem::read(const std::string &path) {
return str; return str;
} }
//Only use on small files
std::vector<std::string> filesystem::read_lines(const std::string &path) {
std::vector<std::string> res;
std::ifstream input(path, std::ofstream::binary);
if(input) {
std::string line;
while(std::getline(input, line))
res.emplace_back(std::move(line));
input.close();
}
return res;
}
//Only use on small files //Only use on small files
bool filesystem::write(const std::string &path, const std::string &new_content) { bool filesystem::write(const std::string &path, const std::string &new_content) {
std::ofstream output(path, std::ofstream::binary); std::ofstream output(path, std::ofstream::binary);

3
src/filesystem.hpp

@ -8,9 +8,6 @@ public:
static std::string read(const std::string &path); static std::string read(const std::string &path);
static std::string read(const boost::filesystem::path &path) { return read(path.string()); } static std::string read(const boost::filesystem::path &path) { return read(path.string()); }
static std::vector<std::string> read_lines(const std::string &path);
static std::vector<std::string> read_lines(const boost::filesystem::path &path) { return read_lines(path.string()); };
static bool write(const std::string &path, const std::string &new_content); static bool write(const std::string &path, const std::string &new_content);
static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); } static bool write(const boost::filesystem::path &path, const std::string &new_content) { return write(path.string(), new_content); }
static bool write(const std::string &path) { return write(path, ""); }; static bool write(const std::string &path) { return write(path, ""); };

8
src/meson.cpp

@ -10,12 +10,16 @@
Meson::Meson(const boost::filesystem::path &path) { Meson::Meson(const boost::filesystem::path &path) {
const auto find_project = [](const boost::filesystem::path &file_path) { const auto find_project = [](const boost::filesystem::path &file_path) {
for(auto &line : filesystem::read_lines(file_path)) { std::ifstream input(file_path.string(), std::ofstream::binary);
const static std::regex project_regex(R"(^ *project *\(.*\r?$)", std::regex::icase); if(input) {
std::string line;
while(std::getline(input, line)) {
const static std::regex project_regex("^ *project *\\(.*", std::regex::icase);
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, project_regex)) if(std::regex_match(line, sm, project_regex))
return true; return true;
} }
}
return false; return false;
}; };

Loading…
Cancel
Save