mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-02 23:48:35 +02:00
Enhancement - Subst object
- Implemented most of Subst object, except Subst::apply
This commit is contained in:
parent
de08c1d32e
commit
2083dc4175
6 changed files with 180 additions and 3 deletions
3
src/T.h
3
src/T.h
|
@ -64,16 +64,15 @@ public:
|
||||||
void setSubstitution (const std::string&, const std::string&, bool);
|
void setSubstitution (const std::string&, const std::string&, bool);
|
||||||
|
|
||||||
bool hasTag (const std::string&) const;
|
bool hasTag (const std::string&) const;
|
||||||
|
|
||||||
void getRemoveTags (std::vector<std::string>&); // SPECIAL
|
void getRemoveTags (std::vector<std::string>&); // SPECIAL
|
||||||
void addRemoveTag (const std::string&); // SPECIAL
|
void addRemoveTag (const std::string&); // SPECIAL
|
||||||
|
|
||||||
int getTagCount () const;
|
int getTagCount () const;
|
||||||
void getTags (std::vector<std::string>&) const;
|
void getTags (std::vector<std::string>&) const;
|
||||||
void addTag (const std::string&);
|
void addTag (const std::string&);
|
||||||
void addTags (const std::vector <std::string>&);
|
void addTags (const std::vector <std::string>&);
|
||||||
void removeTag (const std::string&);
|
void removeTag (const std::string&);
|
||||||
void removeTags ();
|
void removeTags ();
|
||||||
|
|
||||||
void getAttributes (std::map<std::string, std::string>&);
|
void getAttributes (std::map<std::string, std::string>&);
|
||||||
const std::string getAttribute (const std::string&);
|
const std::string getAttribute (const std::string&);
|
||||||
void setAttribute (const std::string&, const std::string&);
|
void setAttribute (const std::string&, const std::string&);
|
||||||
|
|
|
@ -4,7 +4,7 @@ LFLAGS =
|
||||||
LIBS =
|
LIBS =
|
||||||
OBJECTS = main.o Context.o TDB.o T.o ../Sequence.o ../Filter.o ../Att.o \
|
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 \
|
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)
|
all: $(PROJECT)
|
||||||
|
|
||||||
|
|
112
src/sandbox/Subst.cpp
Normal file
112
src/sandbox/Subst.cpp
Normal 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
52
src/sandbox/Subst.h
Normal 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
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -42,6 +42,12 @@ public:
|
||||||
std::string composeCSV ();
|
std::string composeCSV ();
|
||||||
|
|
||||||
// TODO Series of helper functions.
|
// TODO Series of helper functions.
|
||||||
|
/*
|
||||||
|
status getStatus () const;
|
||||||
|
void setStatus (status s);
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool validate () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue