mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 10:28:09 +08:00
consider LF in the range when writing error msg
This commit is contained in:
@@ -76,13 +76,14 @@ struct region_base
|
|||||||
region_base& operator=(const region_base&) = default;
|
region_base& operator=(const region_base&) = default;
|
||||||
region_base& operator=(region_base&& ) = default;
|
region_base& operator=(region_base&& ) = default;
|
||||||
|
|
||||||
virtual bool is_ok() const noexcept {return false;}
|
virtual bool is_ok() const noexcept {return false;}
|
||||||
|
|
||||||
virtual std::string str() const {return std::string("unknown region");}
|
virtual std::string str() const {return std::string("unknown region");}
|
||||||
virtual std::string name() const {return std::string("unknown file");}
|
virtual std::string name() const {return std::string("unknown file");}
|
||||||
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::size_t before() const noexcept {return 0;}
|
virtual std::size_t before() const noexcept {return 0;}
|
||||||
virtual std::size_t size() const noexcept {return 0;}
|
virtual std::size_t size() const noexcept {return 0;}
|
||||||
virtual std::size_t after() const noexcept {return 0;}
|
virtual std::size_t after() const noexcept {return 0;}
|
||||||
@@ -136,6 +137,11 @@ struct region final : public region_base
|
|||||||
std::string str() const override {return make_string(first_, last_);}
|
std::string str() const override {return make_string(first_, last_);}
|
||||||
std::string line() const override
|
std::string line() const override
|
||||||
{
|
{
|
||||||
|
if(this->contain_newline())
|
||||||
|
{
|
||||||
|
return make_string(this->line_begin(),
|
||||||
|
std::find(this->line_begin(), this->last(), '\n'));
|
||||||
|
}
|
||||||
return make_string(this->line_begin(), this->line_end());
|
return make_string(this->line_begin(), this->line_end());
|
||||||
}
|
}
|
||||||
std::string line_num() const override
|
std::string line_num() const override
|
||||||
@@ -156,6 +162,11 @@ struct region final : public region_base
|
|||||||
return std::distance(this->last(), this->line_end());
|
return std::distance(this->last(), this->line_end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool contain_newline() const noexcept
|
||||||
|
{
|
||||||
|
return std::find(this->first(), this->last(), '\n') != this->last();
|
||||||
|
}
|
||||||
|
|
||||||
const_iterator line_begin() const noexcept
|
const_iterator line_begin() const noexcept
|
||||||
{
|
{
|
||||||
using reverse_iterator = std::reverse_iterator<const_iterator>;
|
using reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||||
|
Reference in New Issue
Block a user