Lexer: Migrated isdigit to Lexer::isDigit

This commit is contained in:
Paul Beckingham 2015-04-16 23:33:25 -04:00
parent c6dbdf87a4
commit 3cbb2bb20f
5 changed files with 85 additions and 81 deletions

View file

@ -30,6 +30,7 @@
#include <text.h> #include <text.h>
#include <Dates.h> #include <Dates.h>
#include <Date.h> #include <Date.h>
#include <Lexer.h>
#include <i18n.h> #include <i18n.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -354,7 +355,7 @@ bool namedDates (const std::string& name, Variant& value)
// 4th // 4th
else if (( else if ((
name.length () == 3 && name.length () == 3 &&
isdigit (name[0]) && Lexer::isDigit (name[0]) &&
((name[1] == 's' && name[2] == 't') || ((name[1] == 's' && name[2] == 't') ||
(name[1] == 'n' && name[2] == 'd') || (name[1] == 'n' && name[2] == 'd') ||
(name[1] == 'r' && name[2] == 'd') || (name[1] == 'r' && name[2] == 'd') ||
@ -363,8 +364,8 @@ bool namedDates (const std::string& name, Variant& value)
|| ||
( (
name.length () == 4 && name.length () == 4 &&
isdigit (name[0]) && Lexer::isDigit (name[0]) &&
isdigit (name[1]) && Lexer::isDigit (name[1]) &&
((name[2] == 's' && name[3] == 't') || ((name[2] == 's' && name[3] == 't') ||
(name[2] == 'n' && name[3] == 'd') || (name[2] == 'n' && name[3] == 'd') ||
(name[2] == 'r' && name[3] == 'd') || (name[2] == 'r' && name[3] == 'd') ||
@ -375,7 +376,7 @@ bool namedDates (const std::string& name, Variant& value)
int number; int number;
std::string ordinal; std::string ordinal;
if (isdigit (name[1])) if (Lexer::isDigit (name[1]))
{ {
number = strtol (name.substr (0, 2).c_str (), NULL, 10); number = strtol (name.substr (0, 2).c_str (), NULL, 10);
ordinal = lowerCase (name.substr (2)); ordinal = lowerCase (name.substr (2));

View file

@ -25,6 +25,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <cmake.h> #include <cmake.h>
#include <Lexer.h>
#include <ISO8601.h> #include <ISO8601.h>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -196,7 +197,7 @@ bool ISO8601d::parse_date_time_ext (Nibbler& n)
else if (parse_off_ext (n)) else if (parse_off_ext (n))
; ;
if (! isdigit (n.next ())) if (! Lexer::isDigit (n.next ()))
return true; return true;
} }
@ -228,16 +229,16 @@ bool ISO8601d::parse_date_time (Nibbler& n)
if (n.skip ('Z')) if (n.skip ('Z'))
{ {
_utc = true; _utc = true;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
else if (parse_off (n)) else if (parse_off (n))
{ {
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
@ -277,13 +278,13 @@ bool ISO8601d::parse_date_ext (Nibbler& n)
} }
_year = year; _year = year;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
else if (n.getDigit3 (_julian)) else if (n.getDigit3 (_julian))
{ {
_year = year; _year = year;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
else if (n.getDigit2 (month) && else if (n.getDigit2 (month) &&
@ -293,7 +294,7 @@ bool ISO8601d::parse_date_ext (Nibbler& n)
_year = year; _year = year;
_month = month; _month = month;
_day = day; _day = day;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
} }
@ -327,7 +328,7 @@ bool ISO8601d::parse_date (Nibbler& n, bool ambiguous)
_weekday = day; _weekday = day;
_year = year; _year = year;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
} }
@ -336,7 +337,7 @@ bool ISO8601d::parse_date (Nibbler& n, bool ambiguous)
if (n.getDigit2 (_month)) if (n.getDigit2 (_month))
{ {
_year = year; _year = year;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
} }
@ -345,13 +346,13 @@ bool ISO8601d::parse_date (Nibbler& n, bool ambiguous)
_year = year; _year = year;
_month = month / 100; _month = month / 100;
_day = month % 100; _day = month % 100;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
else if (ambiguous && n.getDigit3 (_julian)) else if (ambiguous && n.getDigit3 (_julian))
{ {
_year = year; _year = year;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
} }
@ -382,7 +383,7 @@ bool ISO8601d::parse_off_ext (Nibbler& n)
offset += mm * 60; offset += mm * 60;
_offset = (sign == "-") ? -offset : offset; _offset = (sign == "-") ? -offset : offset;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
} }
@ -412,7 +413,7 @@ bool ISO8601d::parse_off (Nibbler& n)
offset += mm * 60; offset += mm * 60;
_offset = (sign == "-") ? -offset : offset; _offset = (sign == "-") ? -offset : offset;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
} }
@ -453,7 +454,7 @@ bool ISO8601d::parse_time_ext (Nibbler& n)
if (_ambiguity) if (_ambiguity)
{ {
_seconds = seconds; _seconds = seconds;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
} }
@ -487,7 +488,7 @@ bool ISO8601d::parse_time (Nibbler& n, bool ambiguous)
} }
_seconds = seconds; _seconds = seconds;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
@ -504,7 +505,7 @@ bool ISO8601d::parse_time_utc_ext (Nibbler& n)
n.skip ('Z')) n.skip ('Z'))
{ {
_utc = true; _utc = true;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
@ -521,7 +522,7 @@ bool ISO8601d::parse_time_utc (Nibbler& n)
n.skip ('Z')) n.skip ('Z'))
{ {
_utc = true; _utc = true;
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
@ -537,7 +538,7 @@ bool ISO8601d::parse_time_off_ext (Nibbler& n)
if (parse_time_ext (n) && if (parse_time_ext (n) &&
parse_off_ext (n)) parse_off_ext (n))
{ {
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }
@ -553,7 +554,7 @@ bool ISO8601d::parse_time_off (Nibbler& n)
if (parse_time (n, true) && if (parse_time (n, true) &&
parse_off (n)) parse_off (n))
{ {
if (!isdigit (n.next ())) if (!Lexer::isDigit (n.next ()))
return true; return true;
} }

View file

@ -30,6 +30,7 @@
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#include <inttypes.h> #include <inttypes.h>
#include <Lexer.h>
#include <Nibbler.h> #include <Nibbler.h>
#ifdef NIBBLER_FEATURE_DATE #ifdef NIBBLER_FEATURE_DATE
#include <Date.h> #include <Date.h>
@ -284,7 +285,7 @@ bool Nibbler::getQuoted (
bool Nibbler::getDigit (int& result) bool Nibbler::getDigit (int& result)
{ {
if (_cursor < _length && if (_cursor < _length &&
isdigit (_input[_cursor])) Lexer::isDigit (_input[_cursor]))
{ {
result = _input[_cursor++] - '0'; result = _input[_cursor++] - '0';
return true; return true;
@ -300,12 +301,12 @@ bool Nibbler::getDigit6 (int& result)
if (i < _length && if (i < _length &&
_length - i >= 6) _length - i >= 6)
{ {
if (isdigit (_input[i + 0]) && if (Lexer::isDigit (_input[i + 0]) &&
isdigit (_input[i + 1]) && Lexer::isDigit (_input[i + 1]) &&
isdigit (_input[i + 2]) && Lexer::isDigit (_input[i + 2]) &&
isdigit (_input[i + 3]) && Lexer::isDigit (_input[i + 3]) &&
isdigit (_input[i + 4]) && Lexer::isDigit (_input[i + 4]) &&
isdigit (_input[i + 5])) Lexer::isDigit (_input[i + 5]))
{ {
result = strtoimax (_input.substr (_cursor, 6).c_str (), NULL, 10); result = strtoimax (_input.substr (_cursor, 6).c_str (), NULL, 10);
_cursor += 6; _cursor += 6;
@ -323,10 +324,10 @@ bool Nibbler::getDigit4 (int& result)
if (i < _length && if (i < _length &&
_length - i >= 4) _length - i >= 4)
{ {
if (isdigit (_input[i + 0]) && if (Lexer::isDigit (_input[i + 0]) &&
isdigit (_input[i + 1]) && Lexer::isDigit (_input[i + 1]) &&
isdigit (_input[i + 2]) && Lexer::isDigit (_input[i + 2]) &&
isdigit (_input[i + 3])) Lexer::isDigit (_input[i + 3]))
{ {
result = strtoimax (_input.substr (_cursor, 4).c_str (), NULL, 10); result = strtoimax (_input.substr (_cursor, 4).c_str (), NULL, 10);
_cursor += 4; _cursor += 4;
@ -344,9 +345,9 @@ bool Nibbler::getDigit3 (int& result)
if (i < _length && if (i < _length &&
_length - i >= 3) _length - i >= 3)
{ {
if (isdigit (_input[i + 0]) && if (Lexer::isDigit (_input[i + 0]) &&
isdigit (_input[i + 1]) && Lexer::isDigit (_input[i + 1]) &&
isdigit (_input[i + 2])) Lexer::isDigit (_input[i + 2]))
{ {
result = strtoimax (_input.substr (_cursor, 3).c_str (), NULL, 10); result = strtoimax (_input.substr (_cursor, 3).c_str (), NULL, 10);
_cursor += 3; _cursor += 3;
@ -364,8 +365,8 @@ bool Nibbler::getDigit2 (int& result)
if (i < _length && if (i < _length &&
_length - i >= 2) _length - i >= 2)
{ {
if (isdigit (_input[i + 0]) && if (Lexer::isDigit (_input[i + 0]) &&
isdigit (_input[i + 1])) Lexer::isDigit (_input[i + 1]))
{ {
result = strtoimax (_input.substr (_cursor, 2).c_str (), NULL, 10); result = strtoimax (_input.substr (_cursor, 2).c_str (), NULL, 10);
_cursor += 2; _cursor += 2;
@ -390,7 +391,7 @@ bool Nibbler::getInt (int& result)
} }
// TODO Potential for use of find_first_not_of // TODO Potential for use of find_first_not_of
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
if (i > _cursor) if (i > _cursor)
@ -408,7 +409,7 @@ bool Nibbler::getUnsignedInt (int& result)
{ {
std::string::size_type i = _cursor; std::string::size_type i = _cursor;
// TODO Potential for use of find_first_not_of // TODO Potential for use of find_first_not_of
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
if (i > _cursor) if (i > _cursor)
@ -446,11 +447,11 @@ bool Nibbler::getNumber (std::string& result)
++i; ++i;
// digit+ // digit+
if (i < _length && isdigit (_input[i])) if (i < _length && Lexer::isDigit (_input[i]))
{ {
++i; ++i;
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
// ( . digit+ )? // ( . digit+ )?
@ -458,7 +459,7 @@ bool Nibbler::getNumber (std::string& result)
{ {
++i; ++i;
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
} }
@ -470,11 +471,11 @@ bool Nibbler::getNumber (std::string& result)
if (i < _length && (_input[i] == '+' || _input[i] == '-')) if (i < _length && (_input[i] == '+' || _input[i] == '-'))
++i; ++i;
if (i < _length && isdigit (_input[i])) if (i < _length && Lexer::isDigit (_input[i]))
{ {
++i; ++i;
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
result = _input.substr (_cursor, i - _cursor); result = _input.substr (_cursor, i - _cursor);
@ -528,11 +529,11 @@ bool Nibbler::getUnsignedNumber (double& result)
std::string::size_type i = _cursor; std::string::size_type i = _cursor;
// digit+ // digit+
if (i < _length && isdigit (_input[i])) if (i < _length && Lexer::isDigit (_input[i]))
{ {
++i; ++i;
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
// ( . digit+ )? // ( . digit+ )?
@ -540,7 +541,7 @@ bool Nibbler::getUnsignedNumber (double& result)
{ {
++i; ++i;
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
} }
@ -552,11 +553,11 @@ bool Nibbler::getUnsignedNumber (double& result)
if (i < _length && (_input[i] == '+' || _input[i] == '-')) if (i < _length && (_input[i] == '+' || _input[i] == '-'))
++i; ++i;
if (i < _length && isdigit (_input[i])) if (i < _length && Lexer::isDigit (_input[i]))
{ {
++i; ++i;
while (i < _length && isdigit (_input[i])) while (i < _length && Lexer::isDigit (_input[i]))
++i; ++i;
result = strtof (_input.substr (_cursor, i - _cursor).c_str (), NULL); result = strtof (_input.substr (_cursor, i - _cursor).c_str (), NULL);
@ -710,21 +711,21 @@ bool Nibbler::getDateISO (time_t& t)
if (i < _length && if (i < _length &&
_length - i >= 16) _length - i >= 16)
{ {
if (isdigit (_input[i + 0]) && if (Lexer::isDigit (_input[i + 0]) &&
isdigit (_input[i + 1]) && Lexer::isDigit (_input[i + 1]) &&
isdigit (_input[i + 2]) && Lexer::isDigit (_input[i + 2]) &&
isdigit (_input[i + 3]) && Lexer::isDigit (_input[i + 3]) &&
isdigit (_input[i + 4]) && Lexer::isDigit (_input[i + 4]) &&
isdigit (_input[i + 5]) && Lexer::isDigit (_input[i + 5]) &&
isdigit (_input[i + 6]) && Lexer::isDigit (_input[i + 6]) &&
isdigit (_input[i + 7]) && Lexer::isDigit (_input[i + 7]) &&
_input[i + 8] == 'T' && _input[i + 8] == 'T' &&
isdigit (_input[i + 9]) && Lexer::isDigit (_input[i + 9]) &&
isdigit (_input[i + 10]) && Lexer::isDigit (_input[i + 10]) &&
isdigit (_input[i + 11]) && Lexer::isDigit (_input[i + 11]) &&
isdigit (_input[i + 12]) && Lexer::isDigit (_input[i + 12]) &&
isdigit (_input[i + 13]) && Lexer::isDigit (_input[i + 13]) &&
isdigit (_input[i + 14]) && Lexer::isDigit (_input[i + 14]) &&
_input[i + 15] == 'Z') _input[i + 15] == 'Z')
{ {
_cursor += 16; _cursor += 16;
@ -790,7 +791,7 @@ bool Nibbler::parseDigits(std::string::size_type& i,
// Check that 'f' of them are digits // Check that 'f' of them are digits
unsigned int g; unsigned int g;
for (g = 0; g < f; g++) for (g = 0; g < f; g++)
if (! isdigit (_input[i + g])) if (! Lexer::isDigit (_input[i + g]))
break; break;
// Parse the integer when it is the case // Parse the integer when it is the case
if (g == f) if (g == f)
@ -881,9 +882,9 @@ bool Nibbler::getDate (const std::string& format, time_t& t)
case 'a': case 'a':
case 'A': case 'A':
if (i + 3 <= _length && if (i + 3 <= _length &&
! isdigit (_input[i + 0]) && ! Lexer::isDigit (_input[i + 0]) &&
! isdigit (_input[i + 1]) && ! Lexer::isDigit (_input[i + 1]) &&
! isdigit (_input[i + 2])) ! Lexer::isDigit (_input[i + 2]))
{ {
wday = Date::dayOfWeek (_input.substr (i, 3).c_str ()); wday = Date::dayOfWeek (_input.substr (i, 3).c_str ());
i += (format[f] == 'a') ? 3 : Date::dayName (wday).size (); i += (format[f] == 'a') ? 3 : Date::dayName (wday).size ();
@ -895,9 +896,9 @@ bool Nibbler::getDate (const std::string& format, time_t& t)
case 'b': case 'b':
case 'B': case 'B':
if (i + 3 <= _length && if (i + 3 <= _length &&
! isdigit (_input[i + 0]) && ! Lexer::isDigit (_input[i + 0]) &&
! isdigit (_input[i + 1]) && ! Lexer::isDigit (_input[i + 1]) &&
! isdigit (_input[i + 2])) ! Lexer::isDigit (_input[i + 2]))
{ {
if (month != -1) if (month != -1)
return false; return false;
@ -1003,7 +1004,7 @@ bool Nibbler::getName (std::string& result)
if (i < _length) if (i < _length)
{ {
if (! isdigit (_input[i]) && if (! Lexer::isDigit (_input[i]) &&
! ispunct (_input[i]) && ! ispunct (_input[i]) &&
! Lexer::isWhitespace (_input[i])) ! Lexer::isWhitespace (_input[i]))
{ {
@ -1035,7 +1036,7 @@ bool Nibbler::getWord (std::string& result)
if (i < _length) if (i < _length)
{ {
while (!isdigit (_input[i]) && while (!Lexer::isDigit (_input[i]) &&
!isPunctuation (_input[i]) && !isPunctuation (_input[i]) &&
!Lexer::isWhitespace (_input[i])) !Lexer::isWhitespace (_input[i]))
{ {

View file

@ -40,6 +40,7 @@
#include <Context.h> #include <Context.h>
#include <Date.h> #include <Date.h>
#include <Duration.h> #include <Duration.h>
#include <Lexer.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <text.h> #include <text.h>
#include <util.h> #include <util.h>
@ -242,7 +243,7 @@ Date getNextRecurrence (Date& current, std::string& period)
return current + (days * 86400); return current + (days * 86400);
} }
else if (isdigit (period[0]) && period[period.length () - 1] == 'm') else if (Lexer::isDigit (period[0]) && period[period.length () - 1] == 'm')
{ {
std::string numeric = period.substr (0, period.length () - 1); std::string numeric = period.substr (0, period.length () - 1);
int increment = atoi (numeric.c_str ()); int increment = atoi (numeric.c_str ());
@ -275,7 +276,7 @@ Date getNextRecurrence (Date& current, std::string& period)
return Date (m, d, y); return Date (m, d, y);
} }
else if (isdigit (period[0]) && period[period.length () - 1] == 'q') else if (Lexer::isDigit (period[0]) && period[period.length () - 1] == 'q')
{ {
std::string numeric = period.substr (0, period.length () - 1); std::string numeric = period.substr (0, period.length () - 1);
int increment = atoi (numeric.c_str ()); int increment = atoi (numeric.c_str ());

View file

@ -351,7 +351,7 @@ std::string commify (const std::string& data)
int i; int i;
for (int i = 0; i < (int) data.length (); ++i) for (int i = 0; i < (int) data.length (); ++i)
{ {
if (isdigit (data[i])) if (Lexer::isDigit (data[i]))
end = i; end = i;
if (data[i] == '.') if (data[i] == '.')
@ -369,11 +369,11 @@ std::string commify (const std::string& data)
int consecutiveDigits = 0; int consecutiveDigits = 0;
for (; i >= 0; --i) for (; i >= 0; --i)
{ {
if (isdigit (data[i])) if (Lexer::isDigit (data[i]))
{ {
result += data[i]; result += data[i];
if (++consecutiveDigits == 3 && i && isdigit (data[i - 1])) if (++consecutiveDigits == 3 && i && Lexer::isDigit (data[i - 1]))
{ {
result += ','; result += ',';
consecutiveDigits = 0; consecutiveDigits = 0;
@ -393,11 +393,11 @@ std::string commify (const std::string& data)
int consecutiveDigits = 0; int consecutiveDigits = 0;
for (; i >= 0; --i) for (; i >= 0; --i)
{ {
if (isdigit (data[i])) if (Lexer::isDigit (data[i]))
{ {
result += data[i]; result += data[i];
if (++consecutiveDigits == 3 && i && isdigit (data[i - 1])) if (++consecutiveDigits == 3 && i && Lexer::isDigit (data[i - 1]))
{ {
result += ','; result += ',';
consecutiveDigits = 0; consecutiveDigits = 0;