mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Expressions
- Added list of non-word characters to assist is_attr.
This commit is contained in:
parent
2ab24fa08b
commit
f8d9338102
4 changed files with 80 additions and 56 deletions
|
@ -56,8 +56,8 @@
|
|||
their descriptions.
|
||||
|
||||
# Tracked Bugs, sorted by ID.
|
||||
+ Fixed bug #475, which allowed a blank annotation command to be entered (thanks
|
||||
to Andreas Kalex).
|
||||
+ Fixed bug #475, which allowed a blank annotation command to be entered
|
||||
(thanks to Andreas Kalex).
|
||||
+ Fixed bug #511, which caused display problem on Cygwin when colored output
|
||||
used the full width of the terminal. The 'avoidlastcolumn' configuration
|
||||
variable forces taskwarrior to never use the last column.
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <sys/select.h>
|
||||
#include <Context.h>
|
||||
#include <Nibbler.h>
|
||||
#include <Lexer.h>
|
||||
#include <Directory.h>
|
||||
#include <ViewText.h>
|
||||
#include <text.h>
|
||||
|
@ -107,6 +108,8 @@ static struct
|
|||
#define NUM_MODIFIER_NAMES (sizeof (modifierNames) / sizeof (modifierNames[0]))
|
||||
#define NUM_OPERATORS (sizeof (operators) / sizeof (operators[0]))
|
||||
|
||||
static const char* non_word_chars = " +-*/%()=<>!~";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Arguments::Arguments ()
|
||||
{
|
||||
|
@ -603,6 +606,9 @@ bool Arguments::is_attr (const std::string& input)
|
|||
if (name.length () == 0)
|
||||
return false;
|
||||
|
||||
if (name.find_first_of (non_word_chars) != std::string::npos)
|
||||
return false;
|
||||
|
||||
if (n.skip (':') ||
|
||||
n.skip ('='))
|
||||
{
|
||||
|
@ -642,6 +648,9 @@ bool Arguments::is_attmod (const std::string& input)
|
|||
if (name.length () == 0)
|
||||
return false;
|
||||
|
||||
if (name.find_first_of (non_word_chars) != std::string::npos)
|
||||
return false;
|
||||
|
||||
if (n.skip ('.'))
|
||||
{
|
||||
n.skip ('~');
|
||||
|
@ -820,8 +829,14 @@ bool Arguments::is_operator (
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Arguments::is_expression (const std::string& input)
|
||||
{
|
||||
Lexer lexer (unquoteText (input));
|
||||
lexer.skipWhitespace (true);
|
||||
lexer.coalesceAlpha (true);
|
||||
lexer.coalesceDigits (true);
|
||||
lexer.coalesceQuoted (true);
|
||||
|
||||
std::vector <std::string> tokens;
|
||||
splitq (tokens, input, ' ');
|
||||
lexer.tokenize (tokens);
|
||||
|
||||
std::vector <std::string>::iterator token;
|
||||
for (token = tokens.begin (); token != tokens.end (); ++token)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
@ -96,14 +97,16 @@ int CmdCustom::execute (std::string& output)
|
|||
Arguments f = context.args.extract_read_only_filter ();
|
||||
Expression e (f);
|
||||
|
||||
return 0;
|
||||
|
||||
std::vector <Task> filtered;
|
||||
std::vector <Task>::iterator task;
|
||||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
filtered.push_back (*task);
|
||||
|
||||
std::cout << "# tasks=" << tasks.size () << "\n"
|
||||
<< "# filtered=" << filtered.size () << "\n";
|
||||
return 0;
|
||||
|
||||
////////////////////////////////////
|
||||
|
||||
// Sort the tasks.
|
||||
|
|
|
@ -34,7 +34,7 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (109);
|
||||
UnitTest t (113);
|
||||
|
||||
const char* fake[] =
|
||||
{
|
||||
|
@ -78,18 +78,24 @@ int main (int argc, char** argv)
|
|||
t.ok (Arguments::is_attr ("name=\"one\""), "name=\"one\" -> attr");
|
||||
t.ok (Arguments::is_attr ("name=\"one two\""), "name=\"one two\" -> attr");
|
||||
|
||||
// bool is_attmod (const std::string&);
|
||||
t.ok (Arguments::is_attmod ("name.is:"), "name.is: -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is:\"\""), "name.is:\"\" -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is:one"), "name.is:one -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is:\"one\""), "name.is:\"one\" -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is:\"one two\""), "name.is:\"one two\" -> attr");
|
||||
t.notok (Arguments::is_attr ("name"), "name -> not attr");
|
||||
t.notok (Arguments::is_attr ("(name=val and 1<2)"), "(name=val and 1<2) -> not attr");
|
||||
|
||||
t.ok (Arguments::is_attmod ("name.is="), "name.is= -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is=\"\""), "name.is=\"\" -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is=one"), "name.is=one -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is=\"one\""), "name.is=\"one\" -> attr");
|
||||
t.ok (Arguments::is_attmod ("name.is=\"one two\""), "name.is=\"one two\" -> attr");
|
||||
// bool is_attmod (const std::string&);
|
||||
t.ok (Arguments::is_attmod ("name.is:"), "name.is: -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is:\"\""), "name.is:\"\" -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is:one"), "name.is:one -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is:\"one\""), "name.is:\"one\" -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is:\"one two\""), "name.is:\"one two\" -> attmod");
|
||||
|
||||
t.ok (Arguments::is_attmod ("name.is="), "name.is= -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is=\"\""), "name.is=\"\" -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is=one"), "name.is=one -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is=\"one\""), "name.is=\"one\" -> attmod");
|
||||
t.ok (Arguments::is_attmod ("name.is=\"one two\""), "name.is=\"one two\" -> attmod");
|
||||
|
||||
t.notok (Arguments::is_attmod ("name"), "name -> not attmod");
|
||||
t.notok (Arguments::is_attmod ("(name=value and 1<2"), "(name=value and 1<2 -> not attmod");
|
||||
|
||||
// bool is_subst (const std::string&);
|
||||
t.notok (Arguments::is_subst ("///"), "/// -> not subst");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue