From cd0082da8dfc0b7f58aeb236871a62716dc7ca84 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 17 Jun 2020 09:47:18 +0200 Subject: [PATCH] Removed filesystem::read_lines --- src/cmake.cpp | 16 ++++++++++------ src/filesystem.cpp | 13 ------------- src/filesystem.hpp | 3 --- src/meson.cpp | 14 +++++++++----- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/cmake.cpp b/src/cmake.cpp index 0bac4b7..fe85904 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -9,12 +9,16 @@ #include CMake::CMake(const boost::filesystem::path &path) { - const auto find_cmake_project = [](const boost::filesystem::path &cmake_path) { - for(auto &line : filesystem::read_lines(cmake_path)) { - const static std::regex project_regex(R"(^ *project *\(.*\r?$)", std::regex::icase); - std::smatch sm; - if(std::regex_match(line, sm, project_regex)) - return true; + const auto find_cmake_project = [](const boost::filesystem::path &file_path) { + std::ifstream input(file_path.string(), std::ofstream::binary); + if(input) { + std::string line; + while(std::getline(input, line)) { + const static std::regex project_regex("^ *project *\\(.*$", std::regex::icase); + std::smatch sm; + if(std::regex_match(line, sm, project_regex)) + return true; + } } return false; }; diff --git a/src/filesystem.cpp b/src/filesystem.cpp index ee1f44c..58628c9 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -20,19 +20,6 @@ std::string filesystem::read(const std::string &path) { return str; } -//Only use on small files -std::vector filesystem::read_lines(const std::string &path) { - std::vector 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 bool filesystem::write(const std::string &path, const std::string &new_content) { std::ofstream output(path, std::ofstream::binary); diff --git a/src/filesystem.hpp b/src/filesystem.hpp index de00bac..3f14e86 100644 --- a/src/filesystem.hpp +++ b/src/filesystem.hpp @@ -8,9 +8,6 @@ public: static std::string read(const std::string &path); static std::string read(const boost::filesystem::path &path) { return read(path.string()); } - static std::vector read_lines(const std::string &path); - static std::vector 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 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, ""); }; diff --git a/src/meson.cpp b/src/meson.cpp index 9717efe..23de259 100644 --- a/src/meson.cpp +++ b/src/meson.cpp @@ -10,11 +10,15 @@ Meson::Meson(const boost::filesystem::path &path) { const auto find_project = [](const boost::filesystem::path &file_path) { - for(auto &line : filesystem::read_lines(file_path)) { - const static std::regex project_regex(R"(^ *project *\(.*\r?$)", std::regex::icase); - std::smatch sm; - if(std::regex_match(line, sm, project_regex)) - return true; + std::ifstream input(file_path.string(), std::ofstream::binary); + if(input) { + std::string line; + while(std::getline(input, line)) { + const static std::regex project_regex("^ *project *\\(.*", std::regex::icase); + std::smatch sm; + if(std::regex_match(line, sm, project_regex)) + return true; + } } return false; };