mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Lexer: Do not allow leading zero for two and more digit integers
This commit is contained in:
parent
6a33bb8656
commit
05e7c2aff2
1 changed files with 9 additions and 1 deletions
|
@ -687,17 +687,25 @@ bool Lexer::isNumber (std::string& token, Lexer::Type& type)
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Lexer::Type::number
|
||||
// \d+
|
||||
// 0
|
||||
// [1-9]\d*
|
||||
// Integers do not start with a leading 0, unless they are zero.
|
||||
bool Lexer::isInteger (std::string& token, Lexer::Type& type)
|
||||
{
|
||||
std::size_t marker = _cursor;
|
||||
|
||||
bool leading_zero = (_text[marker] == '0');
|
||||
|
||||
if (unicodeLatinDigit (_text[marker]))
|
||||
{
|
||||
++marker;
|
||||
while (unicodeLatinDigit (_text[marker]))
|
||||
utf8_next_char (_text, marker);
|
||||
|
||||
// Leading zero is only allowed in the case of number 0
|
||||
if (leading_zero and marker - _cursor > 1)
|
||||
return false;
|
||||
|
||||
token = _text.substr (_cursor, marker - _cursor);
|
||||
type = Lexer::Type::number;
|
||||
_cursor = marker;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue