Enhancements - T2 & Subst

- Implemented more helper functions in T2, prior to integration.
- Completed Subst.
- Completed Subst unit tests.
- Eliminated T::getAnnotationCount.
This commit is contained in:
Paul Beckingham 2009-05-31 23:43:11 -04:00
parent ccff27b535
commit 7248267a72
10 changed files with 149 additions and 71 deletions

View file

@ -103,10 +103,54 @@ bool Subst::parse (const std::string& input)
}
////////////////////////////////////////////////////////////////////////////////
void Subst::apply (Record& record) const
void Subst::apply (
std::string& description,
std::vector <Att>& annotations) const
{
// TODO Apply /mFrom/mTo/mGlobal to record.get ("description")
// TODO Apply /mFrom/mTo/mGlobal to record.get ("annotation...")
if (mFrom != "")
{
std::string::size_type pattern;
if (mGlobal)
{
// Perform all subs on description.
while ((pattern = description.find (mFrom)) != std::string::npos)
description.replace (pattern, mFrom.length (), mTo);
// Perform all subs on annotations.
std::vector <Att>::iterator i;
for (i = annotations.begin (); i != annotations.end (); ++i)
{
std::string description = i->value ();
while ((pattern = description.find (mFrom)) != std::string::npos)
{
description.replace (pattern, mFrom.length (), mTo);
i->value (description);
}
}
}
else
{
// Perform first description substitution.
if ((pattern = description.find (mFrom)) != std::string::npos)
description.replace (pattern, mFrom.length (), mTo);
// Failing that, perform the first annotation substitution.
else
{
std::vector <Att>::iterator i;
for (i = annotations.begin (); i != annotations.end (); ++i)
{
std::string description = i->value ();
if ((pattern = description.find (mFrom)) != std::string::npos)
{
description.replace (pattern, mFrom.length (), mTo);
break;
}
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////////