diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2016-12-15 18:19:22 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2016-12-15 18:19:22 -0800 |
| commit | e4548a8cf46b20b8e89ab75ee9201e3b244484ba (patch) | |
| tree | aefa2373cef54fcb03ec5c915473434804fc8fcb /toolsrc/src/vcpkg_Files.cpp | |
| parent | 8f397bb8d1bd05a2e1f6d5de808322364100ae5d (diff) | |
| download | vcpkg-e4548a8cf46b20b8e89ab75ee9201e3b244484ba.tar.gz vcpkg-e4548a8cf46b20b8e89ab75ee9201e3b244484ba.zip | |
Add Files::read_all_lines() and Files::write_all_lines()
Diffstat (limited to 'toolsrc/src/vcpkg_Files.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg_Files.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp index 698579736..889ceb055 100644 --- a/toolsrc/src/vcpkg_Files.cpp +++ b/toolsrc/src/vcpkg_Files.cpp @@ -42,6 +42,35 @@ namespace vcpkg {namespace Files return std::move(output); } + expected<std::vector<std::string>> read_all_lines(const fs::path& file_path) + { + std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary); + if (file_stream.fail()) + { + return std::errc::no_such_file_or_directory; + } + + std::vector<std::string> output; + std::string line; + while (std::getline(file_stream, line)) + { + output.push_back(line); + } + file_stream.close(); + + return std::move(output); + } + + void write_all_lines(const fs::path& file_path, const std::vector<std::string>& lines) + { + std::fstream output(file_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + for (const std::string& line : lines) + { + output << line << "\n"; + } + output.close(); + } + fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) { fs::path current_dir = starting_dir; |
