Enhancements - Nibbler + parsing

- New Nibbler object greatly assists in FF4 parsing.
- Unit tests for Nibbler.
- Record now parses itself.
- Att now parses itself.
This commit is contained in:
Paul Beckingham
2009-05-29 01:47:39 -04:00
parent 7c0aee4a5f
commit 5263147c83
12 changed files with 623 additions and 77 deletions

View File

@@ -27,6 +27,7 @@
#include <sstream>
#include <stdlib.h>
#include <text.h>
#include "Att.h"
////////////////////////////////////////////////////////////////////////////////
@@ -85,26 +86,45 @@ Att::~Att ()
}
////////////////////////////////////////////////////////////////////////////////
// Parse the following forms:
// name [[.mod] ...] : " [value] "
void Att::parse (const std::string& input)
//
// start --> name --> . --> mod --> : --> " --> value --> " --> end
// ^ |
// |__________|
//
bool Att::parse (Nibbler& n)
{
// Ensure a clean object first.
mName = "";
mValue = "";
mMods.clear ();
std::string::size_type colon = input.find (":");
if (colon != std::string::npos)
if (n.getUntilChars (".:", mName))
{
std::string name = input.substr (0, colon);
// TODO Are there mods?
mName = name;
while (n.skip ('.'))
{
std::string mod;
if (n.getUntilChars (".:", mod))
mMods.push_back (mod);
else
throw std::string ("Missing . or : after modifier");
}
std::string value = input.substr (colon + 1, std::string::npos);
dequote (value);
decode (value);
mValue = value;
if (n.skip (':'))
{
if (n.getQuoted ('"', mValue))
return true;
else if (n.getUntilChar (' ', mValue))
return true;
throw std::string ("Missing attribute value");
}
else
throw std::string ("Missing : after attribute name");
}
else
throw std::string ("Missing : after attribute name");
return false;
}
////////////////////////////////////////////////////////////////////////////////