mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Expressions
- Implemented Nibbler::getWord. - Re-implemented Nibbler::getDOM. - Modified DOM addressed for context-based attributes from "due" to ".due", the help disambiguate DOM references in expressions. There is now a consistency: <id>.due Task-specific .due Contextual <uuid>.due General - Implemented associated unit tests.
This commit is contained in:
parent
dd75c1af1e
commit
ab6e230f10
6 changed files with 184 additions and 71 deletions
107
src/Nibbler.cpp
107
src/Nibbler.cpp
|
@ -34,6 +34,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <Nibbler.h>
|
||||
#include <Date.h>
|
||||
#include <text.h>
|
||||
#include <RX.h>
|
||||
|
||||
const char* c_digits = "0123456789";
|
||||
|
@ -920,37 +921,93 @@ bool Nibbler::getOneOf (
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Nibbler::getDOM (std::string& found)
|
||||
// [<number>|<uuid>|<word>|].<word>[.<word> ...]
|
||||
bool Nibbler::getDOM (std::string& result)
|
||||
{
|
||||
std::string::size_type i = mCursor;
|
||||
std::string::size_type start = mCursor;
|
||||
|
||||
while ( isdigit (mInput[i]) ||
|
||||
mInput[i] == '.' ||
|
||||
mInput[i] == '-' ||
|
||||
mInput[i] == '_' ||
|
||||
(! ispunct (mInput[i]) &&
|
||||
! isspace (mInput[i])))
|
||||
std::string::size_type i = mCursor;
|
||||
if (i < mLength)
|
||||
{
|
||||
++i;
|
||||
save ();
|
||||
|
||||
std::string left;
|
||||
std::string right;
|
||||
int number;
|
||||
|
||||
if (skip ('.') &&
|
||||
getWord (right))
|
||||
{
|
||||
while (skip ('.') &&
|
||||
getWord (right))
|
||||
;
|
||||
|
||||
result = mInput.substr (i, mCursor - i);
|
||||
return true;
|
||||
}
|
||||
|
||||
restore ();
|
||||
if (getWord (left) &&
|
||||
skip ('.') &&
|
||||
getWord (right))
|
||||
{
|
||||
while (skip ('.') &&
|
||||
getWord (right))
|
||||
;
|
||||
|
||||
result = mInput.substr (i, mCursor - i);
|
||||
return true;
|
||||
}
|
||||
|
||||
restore ();
|
||||
if (getInt (number) &&
|
||||
skip ('.') &&
|
||||
getWord (right))
|
||||
{
|
||||
while (skip ('.') &&
|
||||
getWord (right))
|
||||
;
|
||||
|
||||
result = mInput.substr (i, mCursor - i);
|
||||
return true;
|
||||
}
|
||||
|
||||
restore ();
|
||||
if (getUUID (left) &&
|
||||
skip ('.') &&
|
||||
getWord (right))
|
||||
{
|
||||
while (skip ('.') &&
|
||||
getWord (right))
|
||||
;
|
||||
|
||||
result = mInput.substr (i, mCursor - i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (i > mCursor)
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// A word is a contiguous string of non-space, non-digit, non-punct characters.
|
||||
bool Nibbler::getWord (std::string& result)
|
||||
{
|
||||
std::string::size_type i = mCursor;
|
||||
|
||||
if (i < mLength)
|
||||
{
|
||||
found = mInput.substr (start, i - start);
|
||||
while (!isdigit (mInput[i]) &&
|
||||
!ispunct (mInput[i]) &&
|
||||
!isspace (mInput[i]))
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
// If found is simple a number, then it is not a DOM reference.
|
||||
double d;
|
||||
Nibbler exclusion (found);
|
||||
if (exclusion.getNumber (d) && exclusion.depleted ())
|
||||
return false;
|
||||
|
||||
int in;
|
||||
if (exclusion.getInt (in) && exclusion.depleted ())
|
||||
return false;
|
||||
|
||||
mCursor = i;
|
||||
return true;
|
||||
if (i > mCursor)
|
||||
{
|
||||
result = mInput.substr (mCursor, i - mCursor);
|
||||
mCursor = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue