mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-30 02:17:21 +02:00
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:
parent
ccff27b535
commit
7248267a72
10 changed files with 149 additions and 71 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue