diff options
Diffstat (limited to 'LocalFileReader.cpp')
-rw-r--r-- | LocalFileReader.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/LocalFileReader.cpp b/LocalFileReader.cpp index 1f9d574..a505616 100644 --- a/LocalFileReader.cpp +++ b/LocalFileReader.cpp @@ -1,17 +1,18 @@ #include <cstdio> +#include <cstring> #include <iterator> #include "LocalFileReader.h" #include "Exception.h" -LocalFileReader LocalFileReader::instance(protocol); +using namespace std; -void LocalFileReader::open(const std::string url) { - std::string path = url; - if (path.starts_with(protocol)) - path = path.substr(protocol.size()); +void LocalFileReader::open() { + string path = this->url; + if (path.starts_with("file://")) + path = path.substr(strlen("file://")); - this->file = new std::ifstream(path, std::ios::in); + this->file = new ifstream(path, ios::in); if (this->file->fail() || !this->file->is_open()) throw Exception("cannot open file://%s\n", path.c_str()); } @@ -23,7 +24,7 @@ void LocalFileReader::close() { this->file->close(); } -const std::string LocalFileReader::read() { +const string LocalFileReader::read() { if (this->content != nullptr) return *this->content; @@ -33,9 +34,9 @@ const std::string LocalFileReader::read() { if (!this->file->is_open()) throw Exception("FileReader read after close\n"); - this->content = new std::string( - std::istreambuf_iterator<char>(*this->file), - std::istreambuf_iterator<char>() + this->content = new string( + istreambuf_iterator<char>(*this->file), + istreambuf_iterator<char>() ); return *this->content; @@ -55,9 +56,3 @@ LocalFileReader::~LocalFileReader() { } } -LocalFileReader * LocalFileReader::clone() const { - return new LocalFileReader(this); -} - -LocalFileReader::LocalFileReader(const LocalFileReader *) : FileReader() { } - |