dom: Added 'dom.active.tag.<N>' support

- Rewrote DOM parser using Pig.
- Added errors for dom.active.tag.N where N exceeds the tag count.
This commit is contained in:
Paul Beckingham 2016-07-16 11:46:00 -04:00
parent 7df855a607
commit 7439c87647

View file

@ -26,7 +26,9 @@
#include <cmake.h> #include <cmake.h>
#include <timew.h> #include <timew.h>
#include <Pig.h>
#include <format.h> #include <format.h>
#include <vector>
#include <iostream> #include <iostream>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -35,28 +37,43 @@ bool domGet (
const std::string& reference, const std::string& reference,
std::string& value) std::string& value)
{ {
// dom.active Pig pig (reference);
if (reference.substr (0, 10) == "dom.active") if (pig.skipLiteral ("dom."))
{ {
auto latest = getLatestInterval (database); if (pig.skipLiteral ("active"))
{
auto latest = getLatestInterval (database);
if (reference == "dom.active") // dom.active
{ if (pig.eos ())
if (latest.range.is_open ())
{ {
value = "1"; value = latest.range.is_open () ? "1" : "0";
return true; return true;
} }
else
if (pig.skipLiteral (".tag.count"))
{ {
value = "0"; value = format ("{1}", latest.tags ().size ());
return true; return true;
} }
}
else if (reference == "dom.active.tag.count") pig.save ();
{ int n;
value = format ("{1}", latest.tags ().size ()); if (pig.skipLiteral (".tag.") &&
return true; pig.getDigits (n))
{
if (n <= static_cast <int> (latest.tags ().size ()))
{
std::vector <std::string> tags;
for (auto& tag : latest.tags ())
tags.push_back (tag);
value = format ("{1}", tags[n - 1]);
return true;
}
}
pig.restore ();
} }
} }