mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 00:57:19 +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
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue