FF4 - snapshot

This commit is contained in:
Paul Beckingham 2009-05-23 00:35:47 -04:00
parent eb5bd63459
commit 5ac3f0c47e
7 changed files with 269 additions and 10 deletions

View file

@ -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
// , <- &comma;
// [ <- &open;
// ] <- &close;
void Att::decode (std::string&) const
// : <- &colon;
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 ("&quot;")) != std::string::npos)
value.replace (i, 6, "\"");
while ((i = value.find ("&comma;")) != 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 ("&colon;")) != std::string::npos)
value.replace (i, 7, ":");
}
////////////////////////////////////////////////////////////////////////////////

View file

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

View file

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

49
src/rewrite/Mod.cpp Normal file
View file

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

42
src/rewrite/Mod.h Normal file
View file

@ -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 <string>
class Mod : public std::string
{
public:
Mod (); // Default constructor
~Mod (); // Destructor
bool isRecognized ();
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -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 ()
{
}
////////////////////////////////////////////////////////////////////////////////

46
src/rewrite/StringTable.h Normal file
View file

@ -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 <map>
#include <string>
class StringTable
{
public:
StringTable (); // Default constructor
StringTable (const StringTable&); // Copy constructor
StringTable& operator= (const StringTable&); // Assignment operator
~StringTable (); // Destructor
private:
std::map <std::string, std::string> mMapping;
};
#endif
////////////////////////////////////////////////////////////////////////////////