Enhancement - Subst object

- Implemented most of Subst object, except Subst::apply
This commit is contained in:
Paul Beckingham 2009-05-27 00:30:42 -04:00
parent de08c1d32e
commit 2083dc4175
6 changed files with 180 additions and 3 deletions

View file

@ -64,16 +64,15 @@ public:
void setSubstitution (const std::string&, const std::string&, bool);
bool hasTag (const std::string&) const;
void getRemoveTags (std::vector<std::string>&); // SPECIAL
void addRemoveTag (const std::string&); // SPECIAL
int getTagCount () const;
void getTags (std::vector<std::string>&) const;
void addTag (const std::string&);
void addTags (const std::vector <std::string>&);
void removeTag (const std::string&);
void removeTags ();
void getAttributes (std::map<std::string, std::string>&);
const std::string getAttribute (const std::string&);
void setAttribute (const std::string&, const std::string&);

View file

@ -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)

112
src/sandbox/Subst.cpp Normal file
View file

@ -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.h>
////////////////////////////////////////////////////////////////////////////////
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...")
}
////////////////////////////////////////////////////////////////////////////////

52
src/sandbox/Subst.h Normal file
View file

@ -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 <string>
#include <Record.h>
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
////////////////////////////////////////////////////////////////////////////////

View file

@ -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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -42,6 +42,12 @@ public:
std::string composeCSV ();
// TODO Series of helper functions.
/*
status getStatus () const;
void setStatus (status s);
*/
bool validate () const;
private:
};