mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
perf: check string type before parsing it
to avoid unncessary error message generation, check the first some characters before parsing it. It makes parsing process faster and is also helpful to generate more accurate error messages.
This commit is contained in:
@@ -539,10 +539,30 @@ template<typename Container>
|
||||
result<std::pair<toml::string, region<Container>>, std::string>
|
||||
parse_string(location<Container>& loc)
|
||||
{
|
||||
if(const auto rslt = parse_ml_basic_string(loc)) {return rslt;}
|
||||
if(const auto rslt = parse_ml_literal_string(loc)) {return rslt;}
|
||||
if(const auto rslt = parse_basic_string(loc)) {return rslt;}
|
||||
if(const auto rslt = parse_literal_string(loc)) {return rslt;}
|
||||
if(loc.iter() != loc.end() && *(loc.iter()) == '"')
|
||||
{
|
||||
if(loc.iter() + 1 != loc.end() && *(loc.iter() + 1) == '"' &&
|
||||
loc.iter() + 2 != loc.end() && *(loc.iter() + 2) == '"')
|
||||
{
|
||||
return parse_ml_basic_string(loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
return parse_basic_string(loc);
|
||||
}
|
||||
}
|
||||
else if(loc.iter() != loc.end() && *(loc.iter()) == '\'')
|
||||
{
|
||||
if(loc.iter() + 1 != loc.end() && *(loc.iter() + 1) == '\'' &&
|
||||
loc.iter() + 2 != loc.end() && *(loc.iter() + 2) == '\'')
|
||||
{
|
||||
return parse_ml_literal_string(loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
return parse_literal_string(loc);
|
||||
}
|
||||
}
|
||||
return err(format_underline("[error] toml::parse_string: ",
|
||||
{{std::addressof(loc), "the next token is not a string"}}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user