DOM: Migrated from Nibbler to Lexer

This commit is contained in:
Paul Beckingham 2016-12-11 20:52:54 -05:00
parent f6ae39cb82
commit abd4cfc4ed

View file

@ -30,6 +30,7 @@
#include <map> #include <map>
#include <stdlib.h> #include <stdlib.h>
#include <Variant.h> #include <Variant.h>
#include <Lexer.h>
#include <Context.h> #include <Context.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <shared.h> #include <shared.h>
@ -193,26 +194,25 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
auto elements = split (name, '.'); auto elements = split (name, '.');
Task ref (task); Task ref (task);
Nibbler n (elements[0]); Lexer lexer (elements[0]);
n.save (); std::string token;
int id; Lexer::Type type;
std::string uuid; if (lexer.token (token, type))
// If elements[0] is a UUID, load that task (if necessary), and clobber ref.
if (n.getPartialUUID (uuid) && n.depleted ())
{ {
if (uuid != ref.get ("uuid")) if (type == Lexer::Type::uuid &&
context.tdb2.get (uuid, ref); token.length () == elements[0].length ())
{
if (token != ref.get ("uuid"))
context.tdb2.get (token, ref);
// Eat elements[0]/UUID. // Eat elements[0]/UUID.
elements.erase (elements.begin ()); elements.erase (elements.begin ());
} }
else else if (type == Lexer::Type::number &&
token.find ('.') == std::string::npos)
{ {
// If elements[0] is a ID, load that task (if necessary), and clobber ref. auto id = strtol (token.c_str (), NULL, 10);
if (n.getInt (id) && n.depleted ()) if (id && id != ref.id)
{
if (id != ref.id)
context.tdb2.get (id, ref); context.tdb2.get (id, ref);
// Eat elements[0]/ID. // Eat elements[0]/ID.