mirror of https://gitlab.com/cppit/jucipp
3 changed files with 36 additions and 27 deletions
@ -1,32 +1,38 @@
|
||||
#include "sourcefile.h" |
||||
#include <fstream> |
||||
#include <sstream> |
||||
|
||||
std::string juci::filesystem::open(std::string path) { |
||||
std::string res; |
||||
for (auto &line : lines(path)) { |
||||
res += line+'\n'; |
||||
//TODO: make bool juci::filesystem::open(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> buffer)
|
||||
//TODO: make bool juci::filesystem::save(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> buffer)
|
||||
//Only use on small files
|
||||
std::string juci::filesystem::open(const std::string &path) { |
||||
std::stringstream ss; |
||||
std::ifstream input(path); |
||||
if(input) { |
||||
ss << input.rdbuf(); |
||||
input.close(); |
||||
} |
||||
return res; |
||||
return ss.str(); |
||||
} |
||||
|
||||
std::vector<std::string> juci::filesystem::lines(std::string path) { |
||||
//Only use on small files
|
||||
std::vector<std::string> juci::filesystem::lines(const std::string &path) { |
||||
std::vector<std::string> res; |
||||
std::ifstream input(path); |
||||
if (input.is_open()) { |
||||
if (input) { |
||||
do { res.emplace_back(); } while(getline(input, res.back())); |
||||
} |
||||
input.close(); |
||||
return res; |
||||
} |
||||
|
||||
int juci::filesystem::save(std::string path, std::string new_content) { |
||||
//Only use on small files
|
||||
bool juci::filesystem::save(const std::string &path, const std::string &new_content) { |
||||
std::ofstream output(path); |
||||
if(output.is_open()) { |
||||
if(output) |
||||
output << new_content; |
||||
} else { |
||||
output.close(); |
||||
return 1; |
||||
} |
||||
else |
||||
return false; |
||||
output.close(); |
||||
return 0; |
||||
return true; |
||||
} |
||||
Loading…
Reference in new issue