diff --git a/src/rewrite/Att.cpp b/src/rewrite/Att.cpp index 43f51bdd7..27146b10b 100644 --- a/src/rewrite/Att.cpp +++ b/src/rewrite/Att.cpp @@ -44,6 +44,7 @@ Att::Att (const std::string& name, const std::string& value) mMods.clear (); } + //////////////////////////////////////////////////////////////////////////////// Att::Att (const Att& other) { @@ -81,10 +82,14 @@ void Att::parse (const std::string& input) } //////////////////////////////////////////////////////////////////////////////// +// name : " value " std::string Att::composeF4 () const { - throw std::string ("unimplemented Att::composeF4"); - return ""; + std::string value = mValue; + encode (value); + enquote (value); + + return mName + ":" + value; } //////////////////////////////////////////////////////////////////////////////// @@ -145,12 +150,29 @@ bool Att::required () const } //////////////////////////////////////////////////////////////////////////////// -bool Att::internal () const +bool Att::reserved () const { - throw std::string ("unimplemented Att::internal"); + throw std::string ("unimplemented Att::reserved"); return false; } +//////////////////////////////////////////////////////////////////////////////// +// Add quotes. +void Att::enquote (std::string& value) const +{ + value = '"' + value + '"'; +} + +//////////////////////////////////////////////////////////////////////////////// +// Remove quotes. +void Att::dequote (std::string& value) const +{ + if (value.length () > 2 && + value[0] == '"' && + value[value.length () - 1] == '"') + value = value.substr (1, value.length () - 2); +} + //////////////////////////////////////////////////////////////////////////////// // Encode values prior to serialization. // \t -> &tab; @@ -158,9 +180,28 @@ bool Att::internal () const // , -> , // [ -> &open; // ] -> &close; -void Att::encode (std::string&) const +// : -> : +void Att::encode (std::string& value) const { - throw std::string ("unimplemented Att::internal"); + std::string::size_type i; + + while ((i = value.find ('\t')) != std::string::npos) + value.replace (i, 1, "&tab;"); + + while ((i = value.find ('"')) != std::string::npos) + value.replace (i, 1, """); + + while ((i = value.find (',')) != std::string::npos) + value.replace (i, 1, ","); + + while ((i = value.find ('[')) != std::string::npos) + value.replace (i, 1, "&open;"); + + while ((i = value.find (']')) != std::string::npos) + value.replace (i, 1, "&close;"); + + while ((i = value.find (':')) != std::string::npos) + value.replace (i, 1, ":"); } //////////////////////////////////////////////////////////////////////////////// @@ -170,9 +211,28 @@ void Att::encode (std::string&) const // , <- , // [ <- &open; // ] <- &close; -void Att::decode (std::string&) const +// : <- : +void Att::decode (std::string& value) const { - throw std::string ("unimplemented Att::internal"); + std::string::size_type i; + + while ((i = value.find ("&tab;")) != std::string::npos) + value.replace (i, 5, "\t"); + + while ((i = value.find (""")) != std::string::npos) + value.replace (i, 6, "\""); + + while ((i = value.find (",")) != std::string::npos) + value.replace (i, 7, ","); + + while ((i = value.find ("&open;")) != std::string::npos) + value.replace (i, 6, "["); + + while ((i = value.find ("&close;")) != std::string::npos) + value.replace (i, 7, "]"); + + while ((i = value.find (":")) != std::string::npos) + value.replace (i, 7, ":"); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/rewrite/Att.h b/src/rewrite/Att.h index 708e82952..d0c116cc1 100644 --- a/src/rewrite/Att.h +++ b/src/rewrite/Att.h @@ -55,9 +55,11 @@ public: bool filter () const; bool required () const; - bool internal () const; + bool reserved () const; private: + void enquote (std::string&) const; + void dequote (std::string&) const; void encode (std::string&) const; void decode (std::string&) const; diff --git a/src/rewrite/Makefile b/src/rewrite/Makefile index fd26bdde4..d6518d60f 100644 --- a/src/rewrite/Makefile +++ b/src/rewrite/Makefile @@ -3,7 +3,8 @@ CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti -fstack-check LFLAGS = LIBS = OBJECTS = main.o Context.o TDB.o T.o Sequence.o Filter.o Att.o Keymap.o \ - Record.o ../util.o ../text.o ../Config.o ../Date.o + Record.o Mod.o StringTable.o ../util.o ../text.o ../Config.o \ + ../Date.o all: $(PROJECT) diff --git a/src/rewrite/Mod.cpp b/src/rewrite/Mod.cpp new file mode 100644 index 000000000..65e87be09 --- /dev/null +++ b/src/rewrite/Mod.cpp @@ -0,0 +1,49 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +Mod::~Mod () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +bool Mod::isRecognized () +{ + if (*this == ".is") + return true; + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/rewrite/Mod.h b/src/rewrite/Mod.h new file mode 100644 index 000000000..c18ad8c2e --- /dev/null +++ b/src/rewrite/Mod.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 : public std::string +{ +public: + Mod (); // Default constructor + ~Mod (); // Destructor + + bool isRecognized (); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/rewrite/StringTable.cpp b/src/rewrite/StringTable.cpp new file mode 100644 index 000000000..b4dd01299 --- /dev/null +++ b/src/rewrite/StringTable.cpp @@ -0,0 +1,59 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 "StringTable.h" + +//////////////////////////////////////////////////////////////////////////////// +StringTable::StringTable () +{ +} + +//////////////////////////////////////////////////////////////////////////////// +StringTable::StringTable (const StringTable& other) +{ + throw std::string ("unimplemented StringTable::StringTable"); + mMapping = other.mMapping; +} + +//////////////////////////////////////////////////////////////////////////////// +StringTable& StringTable::operator= (const StringTable& other) +{ + throw std::string ("unimplemented StringTable::operator="); + if (this != &other) + { + mMapping = other.mMapping; + } + + return *this; +} + +//////////////////////////////////////////////////////////////////////////////// +StringTable::~StringTable () +{ +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/rewrite/StringTable.h b/src/rewrite/StringTable.h new file mode 100644 index 000000000..3a608fed5 --- /dev/null +++ b/src/rewrite/StringTable.h @@ -0,0 +1,46 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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_STRINGTABLE +#define INCLUDED_STRINGTABLE + +#include +#include + +class StringTable +{ +public: + StringTable (); // Default constructor + StringTable (const StringTable&); // Copy constructor + StringTable& operator= (const StringTable&); // Assignment operator + ~StringTable (); // Destructor + +private: + std::map mMapping; +}; + +#endif +////////////////////////////////////////////////////////////////////////////////