Code Cleanup

- Merging Record and Task objects, step 3.
This commit is contained in:
Paul Beckingham 2011-08-07 16:40:02 -04:00
parent 33cfdec5a6
commit 740cacc49f
3 changed files with 38 additions and 48 deletions

View file

@ -47,7 +47,6 @@ Record::Record ()
////////////////////////////////////////////////////////////////////////////////
Record::Record (const std::string& input)
{
parse (input);
}
////////////////////////////////////////////////////////////////////////////////
@ -55,42 +54,3 @@ Record::~Record ()
{
}
////////////////////////////////////////////////////////////////////////////////
//
// start --> [ --> Att --> ] --> end
// ^ |
// +-------+
//
void Record::parse (const std::string& input)
{
clear ();
Nibbler n (input);
std::string line;
if (n.skip ('[') &&
n.getUntil (']', line) &&
n.skip (']') &&
n.depleted ())
{
if (line.length () == 0)
throw std::string (STRING_RECORD_EMPTY);
Nibbler nl (line);
Att a;
while (!nl.depleted ())
{
a.parse (nl);
(*this)[a.name ()] = a;
nl.skip (' ');
}
std::string remainder;
nl.getUntilEOS (remainder);
if (remainder.length ())
throw std::string (STRING_RECORD_JUNK_AT_EOL);
}
else
throw std::string (STRING_RECORD_NOT_FF4);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -40,9 +40,6 @@ public:
Record (); // Default constructor
Record (const std::string&); // Copy constructor
virtual ~Record (); // Destructor
void parse (const std::string&);
};
#endif

View file

@ -271,17 +271,50 @@ void Task::setStatus (Task::status status)
////////////////////////////////////////////////////////////////////////////////
// Attempt an FF4 parse first, using Record::parse, and in the event of an error
// try a legacy parse (F3, FF2). Note that FF1 is no longer supported.
void Task::parse (const std::string& line)
//
// start --> [ --> Att --> ] --> end
// ^ |
// +-------+
//
void Task::parse (const std::string& input)
{
std::string copy;
if (line[line.length () - 1] == '\n')
copy = line.substr (0, line.length () - 1);
if (input[input.length () - 1] == '\n')
copy = input.substr (0, input.length () - 1);
else
copy = line;
copy = input;
try
{
Record::parse (copy);
// Record::parse (copy);
clear ();
Nibbler n (copy);
std::string line;
if (n.skip ('[') &&
n.getUntil (']', line) &&
n.skip (']') &&
n.depleted ())
{
if (line.length () == 0)
throw std::string (STRING_RECORD_EMPTY);
Nibbler nl (line);
Att a;
while (!nl.depleted ())
{
a.parse (nl);
(*this)[a.name ()] = a;
nl.skip (' ');
}
std::string remainder;
nl.getUntilEOS (remainder);
if (remainder.length ())
throw std::string (STRING_RECORD_JUNK_AT_EOL);
}
else
throw std::string (STRING_RECORD_NOT_FF4);
}
catch (std::string& e)