From c769891b7629f75345588a34810c4879ea31f795 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 25 Jul 2015 17:54:55 -0400 Subject: [PATCH] Lexer: Implemented ::isInteger to help parsing. --- src/Lexer.cpp | 22 ++++++++++++++++++++++ src/Lexer.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 69466465e..3aebd314f 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -603,6 +603,28 @@ bool Lexer::isNumber (std::string& token, Lexer::Type& type) return false; } +//////////////////////////////////////////////////////////////////////////////// +// Lexer::Type::number +// \d+ +bool Lexer::isInteger (std::string& token, Lexer::Type& type) +{ + std::size_t marker = _cursor; + + if (isDigit (_text[marker])) + { + ++marker; + while (isDigit (_text[marker])) + utf8_next_char (_text, marker); + + token = _text.substr (_cursor, marker - _cursor); + type = Lexer::Type::number; + _cursor = marker; + return true; + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// // Lexer::Type::separator // -- diff --git a/src/Lexer.h b/src/Lexer.h index 5042255c7..3caad292a 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -91,6 +91,7 @@ public: bool isDuration (std::string&, Lexer::Type&); bool isUUID (std::string&, Lexer::Type&); bool isNumber (std::string&, Lexer::Type&); + bool isInteger (std::string&, Lexer::Type&); bool isHexNumber (std::string&, Lexer::Type&); bool isSeparator (std::string&, Lexer::Type&); bool isURL (std::string&, Lexer::Type&);