mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Code Cleanup
- Mod object is no longer necessary, and is removed.
This commit is contained in:
parent
ac871d9e8d
commit
55771cc999
9 changed files with 148 additions and 240 deletions
62
src/Att.cpp
62
src/Att.cpp
|
@ -134,6 +134,63 @@ bool Att::parse (Nibbler& n)
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Att::validMod (const std::string& mod)
|
||||
{
|
||||
if (mod == "before" || mod == "after" || // i18n: TODO
|
||||
mod == "not" || // i18n: TODO
|
||||
mod == "none" || mod == "any" || // i18n: TODO
|
||||
mod == "synth" || // i18n: TODO
|
||||
mod == "under" || mod == "over" || // i18n: TODO
|
||||
mod == "first" || mod == "last" || // i18n: TODO
|
||||
mod == "this" || // i18n: TODO
|
||||
mod == "next" || // i18n: TODO
|
||||
mod == "is" || mod == "isnt" || // i18n: TODO
|
||||
mod == "has" || mod == "hasnt" || // i18n: TODO
|
||||
mod == "startswith" || mod == "endswith") // i18n: TODO
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Att::evalMod (Att& other)
|
||||
{
|
||||
// No modifier means automatic pass.
|
||||
/*
|
||||
if (*this == "") // i18n: no
|
||||
return true;
|
||||
*/
|
||||
|
||||
// TODO before
|
||||
// TODO after
|
||||
// TODO not
|
||||
// TODO none
|
||||
// TODO any
|
||||
// TODO synth
|
||||
// TODO under
|
||||
// TODO over
|
||||
// TODO first
|
||||
// TODO last
|
||||
// TODO this
|
||||
// TODO next
|
||||
|
||||
/*
|
||||
if (*this == "is") // i18n: TODO
|
||||
return *this == other ? true : false;
|
||||
|
||||
if (*this == "isnt") // i18n: TODO
|
||||
return *this != other ? true : false;
|
||||
*/
|
||||
|
||||
// TODO has
|
||||
// TODO hasnt
|
||||
// TODO startswith
|
||||
// TODO endswith
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// name : " value "
|
||||
std::string Att::composeF4 () const
|
||||
|
@ -153,13 +210,13 @@ std::string Att::composeF4 () const
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Att::addMod (const Mod& mod)
|
||||
void Att::addMod (const std::string& mod)
|
||||
{
|
||||
mMods.push_back (mod);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Att::mods (std::vector <Mod>& all)
|
||||
void Att::mods (std::vector <std::string>& all)
|
||||
{
|
||||
all = mMods;
|
||||
}
|
||||
|
@ -281,5 +338,4 @@ void Att::decode (std::string& value) const
|
|||
while ((i = value.find (":")) != std::string::npos)
|
||||
value.replace (i, 7, ":");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include "Nibbler.h"
|
||||
#include "Mod.h"
|
||||
|
||||
class Att
|
||||
{
|
||||
|
@ -43,10 +42,12 @@ public:
|
|||
~Att (); // Destructor
|
||||
|
||||
bool parse (Nibbler&);
|
||||
bool validMod (const std::string&);
|
||||
bool evalMod (Att&);
|
||||
std::string composeF4 () const;
|
||||
|
||||
void addMod (const Mod&);
|
||||
void mods (std::vector <Mod>&);
|
||||
void addMod (const std::string&);
|
||||
void mods (std::vector <std::string>&);
|
||||
|
||||
std::string name () const;
|
||||
void name (const std::string&);
|
||||
|
@ -66,7 +67,7 @@ private:
|
|||
private:
|
||||
std::string mName;
|
||||
std::string mValue;
|
||||
std::vector <Mod> mMods;
|
||||
std::vector <std::string> mMods;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
bin_PROGRAMS = task
|
||||
task_SOURCES = Config.cpp Date.cpp Record.cpp T.cpp T2.cpp TDB.cpp TDB2.cpp \
|
||||
Att.cpp Mod.cpp Filter.cpp Sequence.cpp Table.cpp Grid.cpp \
|
||||
Timer.cpp Duration.cpp StringTable.cpp Location.cpp Subst.cpp \
|
||||
Keymap.cpp Nibbler.cpp Context.cpp color.cpp parse.cpp \
|
||||
task.cpp command.cpp edit.cpp report.cpp util.cpp text.cpp \
|
||||
rules.cpp import.cpp Config.h Date.h Record.h T.h TDB.h Att.h \
|
||||
Mod.h Filter.h Sequence.h Table.h Grid.h Timer.h Duration.h \
|
||||
StringTable.h Location.h Subst.h Keymap.h Nibbler.h Context.h \
|
||||
color.h task.h
|
||||
Att.cpp Filter.cpp Sequence.cpp Table.cpp Grid.cpp Timer.cpp \
|
||||
Duration.cpp StringTable.cpp Location.cpp Subst.cpp Keymap.cpp \
|
||||
Nibbler.cpp Context.cpp color.cpp parse.cpp task.cpp edit.cpp \
|
||||
command.cpp report.cpp util.cpp text.cpp rules.cpp import.cpp \
|
||||
Config.h Date.h Record.h T.h TDB.h Att.h Filter.h Sequence.h \
|
||||
Table.h Grid.h Timer.h Duration.h StringTable.h Location.h \
|
||||
Subst.h Keymap.h Nibbler.h Context.h color.h task.h
|
||||
|
||||
|
|
110
src/Mod.cpp
110
src/Mod.cpp
|
@ -1,110 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Mod.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::Mod ()
|
||||
: std::string ("") // i18n: no
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::Mod (const char* other)
|
||||
: std::string (other)
|
||||
{
|
||||
if (!valid ())
|
||||
throw std::string ("Unrecognized modifier '") + other + "'"; // i18n: TODO
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::Mod (const std::string& other)
|
||||
: std::string (other)
|
||||
{
|
||||
if (!valid ())
|
||||
throw std::string ("Unrecognized modifier '") + other + "'"; // i18n: TODO
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::~Mod ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Mod::valid ()
|
||||
{
|
||||
if (*this == "before" || *this == "after" || // i18n: TODO
|
||||
*this == "not" || // i18n: TODO
|
||||
*this == "none" || *this == "any" || // i18n: TODO
|
||||
*this == "synth" || // i18n: TODO
|
||||
*this == "under" || *this == "over" || // i18n: TODO
|
||||
*this == "first" || *this == "last" || // i18n: TODO
|
||||
*this == "this" || // i18n: TODO
|
||||
*this == "next" || // i18n: TODO
|
||||
*this == "is" || *this == "isnt" || // i18n: TODO
|
||||
*this == "has" || *this == "hasnt" || // i18n: TODO
|
||||
*this == "startswith" || *this == "endswith") // i18n: TODO
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Mod::eval (const Mod& other)
|
||||
{
|
||||
// No modifier means automatic pass.
|
||||
if (*this == "") // i18n: no
|
||||
return true;
|
||||
|
||||
// TODO before
|
||||
// TODO after
|
||||
// TODO not
|
||||
// TODO none
|
||||
// TODO any
|
||||
// TODO synth
|
||||
// TODO under
|
||||
// TODO over
|
||||
// TODO first
|
||||
// TODO last
|
||||
// TODO this
|
||||
// TODO next
|
||||
|
||||
if (*this == "is") // i18n: TODO
|
||||
return *this == other ? true : false;
|
||||
|
||||
if (*this == "isnt") // i18n: TODO
|
||||
return *this != other ? true : false;
|
||||
|
||||
// TODO has
|
||||
// TODO hasnt
|
||||
// TODO startswith
|
||||
// TODO endswith
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
47
src/Mod.h
47
src/Mod.h
|
@ -1,47 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef INCLUDED_MOD
|
||||
#define INCLUDED_MOD
|
||||
|
||||
#include <string>
|
||||
|
||||
class Mod;
|
||||
|
||||
class Mod : public std::string
|
||||
{
|
||||
public:
|
||||
Mod (); // Default constructor
|
||||
Mod (const char*); // Copy constructor
|
||||
Mod (const std::string&); // Copy constructor
|
||||
~Mod (); // Destructor
|
||||
|
||||
bool valid ();
|
||||
bool eval (const Mod&);
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
1
src/tests/.gitignore
vendored
1
src/tests/.gitignore
vendored
|
@ -8,7 +8,6 @@ autocomplete.t
|
|||
parse.t
|
||||
seq.t
|
||||
att.t
|
||||
mod.t
|
||||
record.t
|
||||
stringtable.t
|
||||
nibbler.t
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
|
||||
parse.t seq.t att.t mod.t stringtable.t record.t nibbler.t subst.t
|
||||
parse.t seq.t att.t stringtable.t record.t nibbler.t subst.t
|
||||
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
|
||||
LFLAGS = -L/usr/local/lib
|
||||
OBJECTS = ../TDB.o ../TDB2.o ../T.o ../T2.o ../parse.o ../text.o ../Date.o \
|
||||
|
@ -51,9 +51,6 @@ seq.t: seq.t.o $(OBJECTS) test.o
|
|||
record.t: record.t.o $(OBJECTS) test.o
|
||||
g++ record.t.o $(OBJECTS) test.o $(LFLAGS) -o record.t
|
||||
|
||||
mod.t: mod.t.o $(OBJECTS) test.o
|
||||
g++ mod.t.o $(OBJECTS) test.o $(LFLAGS) -o mod.t
|
||||
|
||||
att.t: att.t.o $(OBJECTS) test.o
|
||||
g++ att.t.o $(OBJECTS) test.o $(LFLAGS) -o att.t
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (42);
|
||||
UnitTest t (59);
|
||||
|
||||
Att a1 ("name", "value");
|
||||
t.is (a1.name (), "name", "Att::Att (name, value), Att.name");
|
||||
|
@ -73,11 +73,84 @@ int main (int argc, char** argv)
|
|||
t.ok (good, "Att::addMod (is)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod (Mod ("fartwizzle"));} catch (...) {good = false;}
|
||||
try {a6.addMod ("before");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (before)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("after");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (after)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("not");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (not)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("none");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (none)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("any");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (any)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("over");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (over)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("under");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (under)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("synth");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (synth)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("first");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (first)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("last");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (last)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("this");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (this)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("next");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (next)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("isnt");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (isnt)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("has");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (has)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("hasnt");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (hasnt)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("startswith");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (startswith)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("endswith");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (endswith)");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
good = true;
|
||||
try {a6.addMod ("fartwizzle");} catch (...) {good = false;}
|
||||
t.notok (good, "Att::addMod (fartwizzle)");
|
||||
|
||||
// Att::mods
|
||||
std::vector <Mod> mods;
|
||||
std::vector <std::string> mods;
|
||||
a6.mods (mods);
|
||||
t.is (mods.size (), (size_t)1, "Att::mods () size == 1");
|
||||
t.is (mods[0], "is", "Att::mods [0] == 'is'");
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <Context.h>
|
||||
#include <Mod.h>
|
||||
#include <test.h>
|
||||
|
||||
Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (18);
|
||||
|
||||
Mod m = "before"; t.ok (m.valid (), "Mod: before is valid");
|
||||
m = "after"; t.ok (m.valid (), "Mod: after is valid");
|
||||
m = "not"; t.ok (m.valid (), "Mod: not is valid");
|
||||
m = "none"; t.ok (m.valid (), "Mod: none is valid");
|
||||
m = "any"; t.ok (m.valid (), "Mod: any is valid");
|
||||
m = "over"; t.ok (m.valid (), "Mod: over is valid");
|
||||
m = "under"; t.ok (m.valid (), "Mod: under is valid");
|
||||
m = "synth"; t.ok (m.valid (), "Mod: synth is valid");
|
||||
m = "first"; t.ok (m.valid (), "Mod: first is valid");
|
||||
m = "last"; t.ok (m.valid (), "Mod: last is valid");
|
||||
m = "this"; t.ok (m.valid (), "Mod: this is valid");
|
||||
m = "next"; t.ok (m.valid (), "Mod: next is valid");
|
||||
m = "is"; t.ok (m.valid (), "Mod: is is valid");
|
||||
m = "isnt"; t.ok (m.valid (), "Mod: isnt is valid");
|
||||
m = "has"; t.ok (m.valid (), "Mod: has is valid");
|
||||
m = "hasnt"; t.ok (m.valid (), "Mod: hasnt is valid");
|
||||
m = "startswith"; t.ok (m.valid (), "Mod: startswith is valid");
|
||||
m = "endswith"; t.ok (m.valid (), "Mod: endswith is valid");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue