mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Merge from libexpr
- Incorporated Nibbler changes from libexpr.
This commit is contained in:
parent
4efe5d4a52
commit
efae57d56b
3 changed files with 107 additions and 2 deletions
|
@ -294,6 +294,89 @@ bool Nibbler::getDigit (int& result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Nibbler::getDigit6 (int& result)
|
||||||
|
{
|
||||||
|
std::string::size_type i = _cursor;
|
||||||
|
if (i < _length &&
|
||||||
|
_length - i >= 6)
|
||||||
|
{
|
||||||
|
if (isdigit (_input[i + 0]) &&
|
||||||
|
isdigit (_input[i + 1]) &&
|
||||||
|
isdigit (_input[i + 2]) &&
|
||||||
|
isdigit (_input[i + 3]) &&
|
||||||
|
isdigit (_input[i + 4]) &&
|
||||||
|
isdigit (_input[i + 5]))
|
||||||
|
{
|
||||||
|
result = strtoimax (_input.substr (_cursor, 6).c_str (), NULL, 10);
|
||||||
|
_cursor += 6;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Nibbler::getDigit4 (int& result)
|
||||||
|
{
|
||||||
|
std::string::size_type i = _cursor;
|
||||||
|
if (i < _length &&
|
||||||
|
_length - i >= 4)
|
||||||
|
{
|
||||||
|
if (isdigit (_input[i + 0]) &&
|
||||||
|
isdigit (_input[i + 1]) &&
|
||||||
|
isdigit (_input[i + 2]) &&
|
||||||
|
isdigit (_input[i + 3]))
|
||||||
|
{
|
||||||
|
result = strtoimax (_input.substr (_cursor, 4).c_str (), NULL, 10);
|
||||||
|
_cursor += 4;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Nibbler::getDigit3 (int& result)
|
||||||
|
{
|
||||||
|
std::string::size_type i = _cursor;
|
||||||
|
if (i < _length &&
|
||||||
|
_length - i >= 3)
|
||||||
|
{
|
||||||
|
if (isdigit (_input[i + 0]) &&
|
||||||
|
isdigit (_input[i + 1]) &&
|
||||||
|
isdigit (_input[i + 2]))
|
||||||
|
{
|
||||||
|
result = strtoimax (_input.substr (_cursor, 3).c_str (), NULL, 10);
|
||||||
|
_cursor += 3;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Nibbler::getDigit2 (int& result)
|
||||||
|
{
|
||||||
|
std::string::size_type i = _cursor;
|
||||||
|
if (i < _length &&
|
||||||
|
_length - i >= 2)
|
||||||
|
{
|
||||||
|
if (isdigit (_input[i + 0]) &&
|
||||||
|
isdigit (_input[i + 1]))
|
||||||
|
{
|
||||||
|
result = strtoimax (_input.substr (_cursor, 2).c_str (), NULL, 10);
|
||||||
|
_cursor += 2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Nibbler::getInt (int& result)
|
bool Nibbler::getInt (int& result)
|
||||||
{
|
{
|
||||||
|
@ -716,7 +799,6 @@ bool Nibbler::getDateISO (time_t& t)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
#ifdef NIBBLER_FEATURE_DATE
|
|
||||||
// Parse the longest integer using the next 'limit' characters of 'result'
|
// Parse the longest integer using the next 'limit' characters of 'result'
|
||||||
// following position 'i' (when strict is true, the number of digits must be
|
// following position 'i' (when strict is true, the number of digits must be
|
||||||
// equal to limit).
|
// equal to limit).
|
||||||
|
@ -758,6 +840,7 @@ bool Nibbler::parseDigits(std::string::size_type& i,
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef NIBBLER_FEATURE_DATE
|
||||||
bool Nibbler::getDate (const std::string& format, time_t& t)
|
bool Nibbler::getDate (const std::string& format, time_t& t)
|
||||||
{
|
{
|
||||||
std::string::size_type i = _cursor;
|
std::string::size_type i = _cursor;
|
||||||
|
|
|
@ -63,6 +63,10 @@ public:
|
||||||
bool getN (const int, std::string&);
|
bool getN (const int, std::string&);
|
||||||
bool getQuoted (char, std::string&, bool quote = false);
|
bool getQuoted (char, std::string&, bool quote = false);
|
||||||
bool getDigit (int&);
|
bool getDigit (int&);
|
||||||
|
bool getDigit6 (int&);
|
||||||
|
bool getDigit4 (int&);
|
||||||
|
bool getDigit3 (int&);
|
||||||
|
bool getDigit2 (int&);
|
||||||
bool getInt (int&);
|
bool getInt (int&);
|
||||||
bool getHex (int&);
|
bool getHex (int&);
|
||||||
bool getUnsignedInt (int&);
|
bool getUnsignedInt (int&);
|
||||||
|
@ -76,8 +80,8 @@ public:
|
||||||
bool getUUID (std::string&);
|
bool getUUID (std::string&);
|
||||||
bool getPartialUUID (std::string&);
|
bool getPartialUUID (std::string&);
|
||||||
bool getDateISO (time_t&);
|
bool getDateISO (time_t&);
|
||||||
#ifdef NIBBLER_FEATURE_DATE
|
|
||||||
bool parseDigits(std::string::size_type&, int&, unsigned int, bool strict = true);
|
bool parseDigits(std::string::size_type&, int&, unsigned int, bool strict = true);
|
||||||
|
#ifdef NIBBLER_FEATURE_DATE
|
||||||
bool getDate (const std::string&, time_t&);
|
bool getDate (const std::string&, time_t&);
|
||||||
#endif
|
#endif
|
||||||
bool getOneOf (const std::vector <std::string>&, std::string&);
|
bool getOneOf (const std::vector <std::string>&, std::string&);
|
||||||
|
|
|
@ -268,6 +268,24 @@ int main (int argc, char** argv)
|
||||||
t.is (i, 2, " '2x' : getDigit () -> 2");
|
t.is (i, 2, " '2x' : getDigit () -> 2");
|
||||||
t.notok (n.getDigit (i), " 'x' : getDigit () -> false");
|
t.notok (n.getDigit (i), " 'x' : getDigit () -> false");
|
||||||
|
|
||||||
|
// bool getDigit6 (int&);
|
||||||
|
t.diag ("Nibbler::getDigit6");
|
||||||
|
n = Nibbler ("654321");
|
||||||
|
t.ok (n.getDigit6 (i), " 654321 : getDigit6 () -> true");
|
||||||
|
t.is (i, 654321, " 654321 : getDigit6 () -> 654321");
|
||||||
|
|
||||||
|
// bool getDigit4 (int&);
|
||||||
|
t.diag ("Nibbler::getDigit4");
|
||||||
|
n = Nibbler ("4321");
|
||||||
|
t.ok (n.getDigit4 (i), " 4321 : getDigit4 () -> true");
|
||||||
|
t.is (i, 4321, " 4321 : getDigit4 () -> 4321");
|
||||||
|
|
||||||
|
// bool getDigit2 (int&);
|
||||||
|
t.diag ("Nibbler::getDigit2");
|
||||||
|
n = Nibbler ("21");
|
||||||
|
t.ok (n.getDigit2 (i), " 21 : getDigit2 () -> true");
|
||||||
|
t.is (i, 21, " 21 : getDigit2 () -> 21");
|
||||||
|
|
||||||
// bool getInt (int&);
|
// bool getInt (int&);
|
||||||
t.diag ("Nibbler::getInt");
|
t.diag ("Nibbler::getInt");
|
||||||
n = Nibbler ("123 -4");
|
n = Nibbler ("123 -4");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue