diff --git a/src/T.h b/src/T.h index 3c4f62b7d..125718d26 100644 --- a/src/T.h +++ b/src/T.h @@ -64,16 +64,15 @@ public: void setSubstitution (const std::string&, const std::string&, bool); bool hasTag (const std::string&) const; - void getRemoveTags (std::vector&); // SPECIAL void addRemoveTag (const std::string&); // SPECIAL - int getTagCount () const; void getTags (std::vector&) const; void addTag (const std::string&); void addTags (const std::vector &); void removeTag (const std::string&); void removeTags (); + void getAttributes (std::map&); const std::string getAttribute (const std::string&); void setAttribute (const std::string&, const std::string&); diff --git a/src/sandbox/Makefile b/src/sandbox/Makefile index 471ceb66d..d9f5139d0 100644 --- a/src/sandbox/Makefile +++ b/src/sandbox/Makefile @@ -4,7 +4,7 @@ LFLAGS = LIBS = OBJECTS = main.o Context.o TDB.o T.o ../Sequence.o ../Filter.o ../Att.o \ Keymap.o ../Record.o ../Mod.o ../StringTable.o ../util.o ../text.o \ - ../Date.o ../Config.o ../Location.o + ../Date.o ../Config.o ../Location.o Subst.o all: $(PROJECT) diff --git a/src/sandbox/Subst.cpp b/src/sandbox/Subst.cpp new file mode 100644 index 000000000..32e1c9f9f --- /dev/null +++ b/src/sandbox/Subst.cpp @@ -0,0 +1,112 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 + +//////////////////////////////////////////////////////////////////////////////// +Subst::Subst () +: mFrom ("") +, mTo ("") +, mGlobal (false) +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Subst::Subst (const std::string& input) +{ + parse (input); +} + +//////////////////////////////////////////////////////////////////////////////// +Subst::Subst (const Subst& other) +{ + mFrom = other.mFrom; + mTo = other.mTo; + mGlobal = other.mGlobal; +} + +//////////////////////////////////////////////////////////////////////////////// +Subst& Subst::operator= (const Subst& other) +{ + if (this != &other) + { + mFrom = other.mFrom; + mTo = other.mTo; + mGlobal = other.mGlobal; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +Subst::~Subst () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +bool Subst::parse (const std::string& input) +{ + size_t first = input.find ('/'); + if (first != std::string::npos) + { + size_t second = input.find ('/', first + 1); + if (second != std::string::npos) + { + size_t third = input.find ('/', second + 1); + if (third != std::string::npos) + { + if (first == 0 && + first < second && + second < third && + (third == input.length () - 1 || + third == input.length () - 2)) + { + mFrom = input.substr (first + 1, second - first - 1); + mTo = input.substr (second + 1, third - second - 1); + + mGlobal = false; + if (third == input.length () - 2 && + input.find ('g', third + 1) != std::string::npos) + mGlobal = true; + + return true; + } + } + } + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +void Subst::apply (Record& record) const +{ + // TODO Apply /mFrom/mTo/mGlobal to record.get ("description") + // TODO Apply /mFrom/mTo/mGlobal to record.get ("annotation...") +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/sandbox/Subst.h b/src/sandbox/Subst.h new file mode 100644 index 000000000..07ef967e8 --- /dev/null +++ b/src/sandbox/Subst.h @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_SUBST +#define INCLUDED_SUBST + +#include +#include + +class Subst +{ +public: + Subst (); // Default constructor + Subst (const std::string&); // Default constructor + Subst (const Subst&); // Copy constructor + Subst& operator= (const Subst&); // Assignment operator + ~Subst (); // Destructor + + bool parse (const std::string&); + void apply (Record&) const; + +public: + std::string mFrom; + std::string mTo; + bool mGlobal; +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/sandbox/T.cpp b/src/sandbox/T.cpp index 50c31b1e9..2620e4899 100644 --- a/src/sandbox/T.cpp +++ b/src/sandbox/T.cpp @@ -72,3 +72,11 @@ std::string T::composeCSV () } //////////////////////////////////////////////////////////////////////////////// +bool T::validate () const +{ + // TODO Verify until > due + // TODO Verify entry < until, due, start, end + return true; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/sandbox/T.h b/src/sandbox/T.h index e10b0f513..97706b4f9 100644 --- a/src/sandbox/T.h +++ b/src/sandbox/T.h @@ -42,6 +42,12 @@ public: std::string composeCSV (); // TODO Series of helper functions. +/* + status getStatus () const; + void setStatus (status s); +*/ + + bool validate () const; private: };