File tree 6 files changed +8
-7
lines changed
6 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ Token ParserBase::peekNextToken() const
43
43
return m_scanner->peekNextToken ();
44
44
}
45
45
46
- std::string ParserBase::currentLiteral () const
46
+ std::string_view ParserBase::currentLiteral () const
47
47
{
48
48
return m_scanner->currentLiteral ();
49
49
}
Original file line number Diff line number Diff line change @@ -71,7 +71,8 @@ class ParserBase
71
71
Token currentToken () const ;
72
72
Token peekNextToken () const ;
73
73
std::string tokenName (Token _token);
74
- std::string currentLiteral () const ;
74
+ // / Points to the current literal. The string view invalidates when the parser advances.
75
+ std::string_view currentLiteral () const ;
75
76
virtual Token advance ();
76
77
// /@}
77
78
Original file line number Diff line number Diff line change @@ -470,7 +470,7 @@ inline std::string asString(bytesConstRef _b)
470
470
}
471
471
472
472
// / Converts a string to a byte array containing the string's (byte) data.
473
- inline bytes asBytes (std::string const & _b)
473
+ inline bytes asBytes (std::string_view const _b)
474
474
{
475
475
return bytes ((uint8_t const *)_b.data (), (uint8_t const *)(_b.data () + _b.size ()));
476
476
}
Original file line number Diff line number Diff line change @@ -779,7 +779,7 @@ void Parser::checkBreakContinuePosition(std::string const& _which)
779
779
}
780
780
}
781
781
782
- bool Parser::isValidNumberLiteral (std::string const & _literal)
782
+ bool Parser::isValidNumberLiteral (std::string_view const _literal)
783
783
{
784
784
try
785
785
{
@@ -793,7 +793,7 @@ bool Parser::isValidNumberLiteral(std::string const& _literal)
793
793
if (boost::starts_with (_literal, " 0x" ))
794
794
return true ;
795
795
else
796
- return _literal.find_first_not_of (" 0123456789" ) == std::string ::npos;
796
+ return _literal.find_first_not_of (" 0123456789" ) == std::string_view ::npos;
797
797
}
798
798
799
799
void Parser::raiseUnsupportedTypesError (SourceLocation const & _location) const
Original file line number Diff line number Diff line change @@ -152,7 +152,7 @@ class Parser: public langutil::ParserBase
152
152
// / Reports an error if we are currently not inside the body part of a for loop.
153
153
void checkBreakContinuePosition (std::string const & _which);
154
154
155
- static bool isValidNumberLiteral (std::string const & _literal);
155
+ static bool isValidNumberLiteral (std::string_view _literal);
156
156
157
157
private:
158
158
Dialect const & m_dialect;
Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ void ObjectParser::parseData(Object& _containingObject)
198
198
std::string ObjectParser::parseUniqueName (Object const * _containingObject)
199
199
{
200
200
expectToken (Token::StringLiteral, false );
201
- auto const name = currentLiteral ();
201
+ std::string const name{ currentLiteral ()} ;
202
202
if (name.empty ())
203
203
parserError (3287_error, " Object name cannot be empty." );
204
204
else if (_containingObject && _containingObject->name == name)
You can’t perform that action at this time.
0 commit comments