Pig: Added ::getHexDigit

This commit is contained in:
Paul Beckingham 2015-12-30 11:06:43 -05:00
parent 91b1d512a7
commit a66e03e858
2 changed files with 31 additions and 0 deletions

View file

@ -171,6 +171,36 @@ bool Pig::getDigits (int& result)
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////////
bool Pig::getHexDigit (int& result)
{
int c = _text[_cursor];
if (c &&
Lexer::isHexDigit (c))
{
if (c >= '0' && c <= '9')
{
result = c - '0';
++_cursor;
return true;
}
else if (c >= 'A' && c <= 'F')
{
result = c - 'A' + 10;
++_cursor;
return true;
}
else if (c >= 'a' && c <= 'f')
{
result = c - 'a' + 10;
++_cursor;
return true;
}
}
return false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// number: // number:
// int frac? exp? // int frac? exp?

View file

@ -43,6 +43,7 @@ public:
bool getUntilWS (std::string&); bool getUntilWS (std::string&);
bool getDigit (int&); bool getDigit (int&);
bool getDigits (int&); bool getDigits (int&);
bool getHexDigit (int&);
bool getNumber (std::string&); bool getNumber (std::string&);
bool getNumber (double&); bool getNumber (double&);
bool getOneOf (const std::vector <std::string>&, std::string&); bool getOneOf (const std::vector <std::string>&, std::string&);