diff --git a/src/Att.cpp b/src/Att.cpp index 0781d32b0..312c91f36 100644 --- a/src/Att.cpp +++ b/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 & all) +void Att::mods (std::vector & 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, ":"); } - //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Att.h b/src/Att.h index a6b5316b2..a1cbcf7f1 100644 --- a/src/Att.h +++ b/src/Att.h @@ -30,7 +30,6 @@ #include #include #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 &); + void addMod (const std::string&); + void mods (std::vector &); std::string name () const; void name (const std::string&); @@ -66,7 +67,7 @@ private: private: std::string mName; std::string mValue; - std::vector mMods; + std::vector mMods; }; #endif diff --git a/src/Makefile.am b/src/Makefile.am index 60662a8ef..3cdf75dc4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/Mod.cpp b/src/Mod.cpp deleted file mode 100644 index 12a5e6af8..000000000 --- a/src/Mod.cpp +++ /dev/null @@ -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; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Mod.h b/src/Mod.h deleted file mode 100644 index e96b7e7ce..000000000 --- a/src/Mod.h +++ /dev/null @@ -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 - -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 -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/tests/.gitignore b/src/tests/.gitignore index f12269bc7..972e0f93c 100644 --- a/src/tests/.gitignore +++ b/src/tests/.gitignore @@ -8,7 +8,6 @@ autocomplete.t parse.t seq.t att.t -mod.t record.t stringtable.t nibbler.t diff --git a/src/tests/Makefile b/src/tests/Makefile index 971e560b8..e5ccc1914 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -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 diff --git a/src/tests/att.t.cpp b/src/tests/att.t.cpp index 7726bd91c..88f1f4b59 100644 --- a/src/tests/att.t.cpp +++ b/src/tests/att.t.cpp @@ -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 mods; + std::vector mods; a6.mods (mods); t.is (mods.size (), (size_t)1, "Att::mods () size == 1"); t.is (mods[0], "is", "Att::mods [0] == 'is'"); diff --git a/src/tests/mod.t.cpp b/src/tests/mod.t.cpp deleted file mode 100644 index be37a3f5f..000000000 --- a/src/tests/mod.t.cpp +++ /dev/null @@ -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 -#include -#include - -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; -} - -////////////////////////////////////////////////////////////////////////////////