Lexer: Collapsed two ::isString calls into one

This commit is contained in:
Paul Beckingham 2015-07-06 16:39:08 -04:00
parent 7a6d546a0d
commit 1fed8c55f1
2 changed files with 39 additions and 30 deletions

View file

@ -73,8 +73,7 @@ bool Lexer::token (std::string& token, Lexer::Type& type)
// - path < substitution < pattern
// - set < number
// - word last
if (isString (token, type, '\'') ||
isString (token, type, '"') ||
if (isString (token, type, "'\"") ||
isDate (token, type) ||
isDuration (token, type) ||
isURL (token, type) ||
@ -369,12 +368,24 @@ int Lexer::hexToInt (int c0, int c1, int c2, int c3)
// '|"
// [ U+XXXX | \uXXXX | \" | \' | \\ | \/ | \b | \f | \n | \r | \t | . ]
// '|"
bool Lexer::isString (std::string& token, Lexer::Type& type, int quote)
bool Lexer::isString (std::string& token, Lexer::Type& type, const std::string& quotes)
{
std::size_t marker = _cursor;
if (_text[marker] == quote)
/*
if (readWord (_text, quotes, marker, token))
{
type = Lexer::Type::string;
_cursor = marker;
return true;
}
return false;
*/
if (quotes.find (_text[marker]) != std::string::npos)
{
int quote = _text[marker];
token = _text.substr (marker++, 1);
int c;
@ -738,8 +749,7 @@ bool Lexer::isPair (std::string& token, Lexer::Type& type)
{
_cursor++;
if (isString (ignoredToken, ignoredType, '\'') ||
isString (ignoredToken, ignoredType, '"') ||
if (isString (ignoredToken, ignoredType, "'\"") ||
isContiguous (ignoredToken, ignoredType))
{
token = _text.substr (marker, _cursor - marker);
@ -755,8 +765,7 @@ bool Lexer::isPair (std::string& token, Lexer::Type& type)
{
_cursor++;
if (isString (ignoredToken, ignoredType, '\'') ||
isString (ignoredToken, ignoredType, '"') ||
if (isString (ignoredToken, ignoredType, "'\"") ||
isContiguous (ignoredToken, ignoredType) ||
_eos == _cursor ||
_text[_cursor] == ' ')
@ -920,11 +929,11 @@ bool Lexer::isSubstitution (std::string& token, Lexer::Type& type)
std::string extractedToken;
Lexer::Type extractedType;
if (isString (extractedToken, extractedType, '/'))
if (isString (extractedToken, extractedType, "/"))
{
--_cursor; // Step back over the '/'.
if (isString (extractedToken, extractedType, '/'))
if (isString (extractedToken, extractedType, "/"))
{
if (_text[_cursor] == 'g')
++_cursor;
@ -953,7 +962,7 @@ bool Lexer::isPattern (std::string& token, Lexer::Type& type)
std::string extractedToken;
Lexer::Type extractedType;
if (isString (extractedToken, extractedType, '/') &&
if (isString (extractedToken, extractedType, "/") &&
(_text[_cursor] == '\0' ||
isWhitespace (_text[_cursor])))
{

View file

@ -85,7 +85,7 @@ public:
bool isEOS () const;
// Stream Classifiers.
bool isString (std::string&, Lexer::Type&, int quote);
bool isString (std::string&, Lexer::Type&, const std::string&);
bool isDate (std::string&, Lexer::Type&);
bool isDuration (std::string&, Lexer::Type&);
bool isUUID (std::string&, Lexer::Type&);