mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 00:38:08 +08:00
refactor: remove vec() method, use a constructor
This commit is contained in:
@@ -510,7 +510,7 @@ parse_ml_literal_string(location<Container>& loc)
|
|||||||
const auto first = loc.iter();
|
const auto first = loc.iter();
|
||||||
if(const auto token = lex_ml_literal_string::invoke(loc))
|
if(const auto token = lex_ml_literal_string::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
|
|
||||||
const auto open = lex_ml_literal_string_open::invoke(inner_loc);
|
const auto open = lex_ml_literal_string_open::invoke(inner_loc);
|
||||||
if(!open)
|
if(!open)
|
||||||
@@ -573,7 +573,7 @@ parse_literal_string(location<Container>& loc)
|
|||||||
const auto first = loc.iter();
|
const auto first = loc.iter();
|
||||||
if(const auto token = lex_literal_string::invoke(loc))
|
if(const auto token = lex_literal_string::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
|
|
||||||
const auto open = lex_apostrophe::invoke(inner_loc);
|
const auto open = lex_apostrophe::invoke(inner_loc);
|
||||||
if(!open)
|
if(!open)
|
||||||
@@ -646,7 +646,7 @@ parse_local_date(location<Container>& loc)
|
|||||||
const auto first = loc.iter();
|
const auto first = loc.iter();
|
||||||
if(const auto token = lex_local_date::invoke(loc))
|
if(const auto token = lex_local_date::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
|
|
||||||
const auto y = lex_date_fullyear::invoke(inner_loc);
|
const auto y = lex_date_fullyear::invoke(inner_loc);
|
||||||
if(!y || inner_loc.iter() == inner_loc.end() || *inner_loc.iter() != '-')
|
if(!y || inner_loc.iter() == inner_loc.end() || *inner_loc.iter() != '-')
|
||||||
@@ -696,7 +696,7 @@ parse_local_time(location<Container>& loc)
|
|||||||
const auto first = loc.iter();
|
const auto first = loc.iter();
|
||||||
if(const auto token = lex_local_time::invoke(loc))
|
if(const auto token = lex_local_time::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
|
|
||||||
const auto h = lex_time_hour::invoke(inner_loc);
|
const auto h = lex_time_hour::invoke(inner_loc);
|
||||||
if(!h || inner_loc.iter() == inner_loc.end() || *inner_loc.iter() != ':')
|
if(!h || inner_loc.iter() == inner_loc.end() || *inner_loc.iter() != ':')
|
||||||
@@ -785,7 +785,7 @@ parse_local_datetime(location<Container>& loc)
|
|||||||
const auto first = loc.iter();
|
const auto first = loc.iter();
|
||||||
if(const auto token = lex_local_date_time::invoke(loc))
|
if(const auto token = lex_local_date_time::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
const auto date = parse_local_date(inner_loc);
|
const auto date = parse_local_date(inner_loc);
|
||||||
if(!date || inner_loc.iter() == inner_loc.end())
|
if(!date || inner_loc.iter() == inner_loc.end())
|
||||||
{
|
{
|
||||||
@@ -830,7 +830,7 @@ parse_offset_datetime(location<Container>& loc)
|
|||||||
const auto first = loc.iter();
|
const auto first = loc.iter();
|
||||||
if(const auto token = lex_offset_date_time::invoke(loc))
|
if(const auto token = lex_offset_date_time::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
const auto datetime = parse_local_datetime(inner_loc);
|
const auto datetime = parse_local_datetime(inner_loc);
|
||||||
if(!datetime || inner_loc.iter() == inner_loc.end())
|
if(!datetime || inner_loc.iter() == inner_loc.end())
|
||||||
{
|
{
|
||||||
@@ -903,7 +903,7 @@ parse_key(location<Container>& loc)
|
|||||||
if(const auto token = lex_dotted_key::invoke(loc))
|
if(const auto token = lex_dotted_key::invoke(loc))
|
||||||
{
|
{
|
||||||
const auto reg = token.unwrap();
|
const auto reg = token.unwrap();
|
||||||
location<std::vector<char>> inner_loc(loc.name(), reg.vec());
|
location<std::vector<char>> inner_loc(loc.name(), reg.str());
|
||||||
std::vector<key> keys;
|
std::vector<key> keys;
|
||||||
|
|
||||||
while(inner_loc.iter() != inner_loc.end())
|
while(inner_loc.iter() != inner_loc.end())
|
||||||
@@ -1182,7 +1182,7 @@ template<typename Value, typename Iterator>
|
|||||||
bool is_valid_forward_table_definition(const Value& fwd,
|
bool is_valid_forward_table_definition(const Value& fwd,
|
||||||
Iterator key_first, Iterator key_curr, Iterator key_last)
|
Iterator key_first, Iterator key_curr, Iterator key_last)
|
||||||
{
|
{
|
||||||
location<std::vector<char>> def("internal", detail::get_region(fwd).vec());
|
location<std::vector<char>> def("internal", detail::get_region(fwd).str());
|
||||||
if(const auto tabkeys = parse_table_key(def))
|
if(const auto tabkeys = parse_table_key(def))
|
||||||
{
|
{
|
||||||
// table keys always contains all the nodes from the root.
|
// table keys always contains all the nodes from the root.
|
||||||
@@ -1736,7 +1736,7 @@ parse_table_key(location<Container>& loc)
|
|||||||
{
|
{
|
||||||
if(auto token = lex_std_table::invoke(loc))
|
if(auto token = lex_std_table::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
|
|
||||||
const auto open = lex_std_table_open::invoke(inner_loc);
|
const auto open = lex_std_table_open::invoke(inner_loc);
|
||||||
if(!open || inner_loc.iter() == inner_loc.end())
|
if(!open || inner_loc.iter() == inner_loc.end())
|
||||||
@@ -1798,7 +1798,7 @@ parse_array_table_key(location<Container>& loc)
|
|||||||
{
|
{
|
||||||
if(auto token = lex_array_table::invoke(loc))
|
if(auto token = lex_array_table::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
|
|
||||||
const auto open = lex_array_table_open::invoke(inner_loc);
|
const auto open = lex_array_table_open::invoke(inner_loc);
|
||||||
if(!open || inner_loc.iter() == inner_loc.end())
|
if(!open || inner_loc.iter() == inner_loc.end())
|
||||||
@@ -1970,7 +1970,7 @@ result<Value, std::string> parse_toml_file(location<Container>& loc)
|
|||||||
>;
|
>;
|
||||||
if(const auto token = lex_first_comments::invoke(loc))
|
if(const auto token = lex_first_comments::invoke(loc))
|
||||||
{
|
{
|
||||||
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().vec());
|
location<std::vector<char>> inner_loc(loc.name(), token.unwrap().str());
|
||||||
while(inner_loc.iter() != inner_loc.end())
|
while(inner_loc.iter() != inner_loc.end())
|
||||||
{
|
{
|
||||||
maybe<lex_ws>::invoke(inner_loc); // remove ws if exists
|
maybe<lex_ws>::invoke(inner_loc); // remove ws if exists
|
||||||
|
@@ -48,8 +48,6 @@ 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
|
||||||
@@ -149,8 +147,6 @@ 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_);
|
||||||
@@ -269,8 +265,6 @@ 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_);
|
||||||
|
Reference in New Issue
Block a user