refactor: add a method to reduce complexity later

This commit is contained in:
ToruNiina
2020-07-20 19:40:55 +09:00
parent d43139a471
commit b461f363da

View File

@@ -48,6 +48,8 @@ struct region_base
virtual std::string line() const {return std::string("unknown line");} virtual std::string line() const {return std::string("unknown line");}
virtual std::string line_num() const {return std::string("?");} virtual std::string line_num() const {return std::string("?");}
virtual std::vector<char> vec() const {return std::vector<char>{};}
// length of the region // length of the region
virtual std::size_t size() const noexcept {return 0;} virtual std::size_t size() const noexcept {return 0;}
// number of characters in the line before the region // number of characters in the line before the region
@@ -141,6 +143,8 @@ struct location final : public region_base
std::string str() const override {return make_string(1, *this->iter());} std::string str() const override {return make_string(1, *this->iter());}
std::string name() const override {return source_name_;} std::string name() const override {return source_name_;}
std::vector<char> vec() const override {return std::vector<char>{*this->iter()};}
std::string line_num() const override std::string line_num() const override
{ {
return std::to_string(this->line_number_); return std::to_string(this->line_number_);
@@ -259,6 +263,8 @@ struct region final : public region_base
return std::to_string(1 + std::count(this->begin(), this->first(), '\n')); return std::to_string(1 + std::count(this->begin(), this->first(), '\n'));
} }
std::vector<char> vec() const override {return std::vector<char>(first_, last_);}
std::size_t size() const noexcept override std::size_t size() const noexcept override
{ {
const auto sz = std::distance(first_, last_); const auto sz = std::distance(first_, last_);