mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Merging Record and Task objects, step 3.
This commit is contained in:
parent
33cfdec5a6
commit
740cacc49f
3 changed files with 38 additions and 48 deletions
|
@ -47,7 +47,6 @@ Record::Record ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Record::Record (const std::string& input)
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
|
@ -40,9 +40,6 @@ public:
|
||||||
Record (); // Default constructor
|
Record (); // Default constructor
|
||||||
Record (const std::string&); // Copy constructor
|
Record (const std::string&); // Copy constructor
|
||||||
virtual ~Record (); // Destructor
|
virtual ~Record (); // Destructor
|
||||||
|
|
||||||
void parse (const std::string&);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
43
src/Task.cpp
43
src/Task.cpp
|
@ -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
|
// 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.
|
// 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;
|
std::string copy;
|
||||||
if (line[line.length () - 1] == '\n')
|
if (input[input.length () - 1] == '\n')
|
||||||
copy = line.substr (0, line.length () - 1);
|
copy = input.substr (0, input.length () - 1);
|
||||||
else
|
else
|
||||||
copy = line;
|
copy = input;
|
||||||
|
|
||||||
try
|
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)
|
catch (std::string& e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue