- Added regex support to substirutions.
- Fixed bug that prevented 1.9.4 from shipping with regexes.  If the
  description is "aXXaaXXa", and the substitution is /XX/.../ then the
  first substitutions changes the length of the string to "a...aaXXa"
  and therefore invalidates the index for the second match, and makes
  this change: "a...a...Xa".  The fix is to keep a running 'skew' count
  of the difference in 'from' and 'to' length, to adjust the match
  indexes.
- Moved the helper deltaSubstitutions function into the Task object,
  which makes more sense.
- Cleaned up output composition for CmdAdd.
- Eliminated #ifdef FEATURE_REGEX.  They are here to stay.
This commit is contained in:
Paul Beckingham 2011-06-25 16:33:55 -04:00
parent 622e9c5e1e
commit b58438bdd4
11 changed files with 152 additions and 166 deletions

View file

@ -358,149 +358,3 @@ int deltaAttributes (Task& task)
}
////////////////////////////////////////////////////////////////////////////////
int deltaSubstitutions (Task& task)
{
/*
std::string description = task.get ("description");
std::vector <Att> annotations;
task.getAnnotations (annotations);
apply_subst (description, annotations);
task.set ("description", description);
task.setAnnotations (annotations);
*/
return 1;
}
////////////////////////////////////////////////////////////////////////////////
/*
void apply_subst (
std::string& description,
std::vector <Att>& annotations) const
{
std::string::size_type pattern;
bool sensitive = context.config.getBoolean ("search.case.sensitive");
if (mFrom != "")
{
#ifdef FEATURE_REGEX
if (context.config.getBoolean ("regex"))
{
// Insert capturing parentheses, if necessary.
std::string pattern;
if (mFrom.find ('(') != std::string::npos)
pattern = mFrom;
else
pattern = "(" + mFrom + ")";
std::vector <int> start;
std::vector <int> end;
// Perform all subs on description.
int counter = 0;
if (regexMatch (start, end, description, pattern, sensitive))
{
for (unsigned int i = 0; i < start.size (); ++i)
{
description.replace (start[i], end[i] - start[i], mTo);
if (!mGlobal)
break;
if (++counter > 1000)
throw ("Terminated substitution because more than a thousand changes were made - infinite loop protection.");
}
}
// Perform all subs on annotations.
counter = 0;
std::vector <Att>::iterator i;
for (i = annotations.begin (); i != annotations.end (); ++i)
{
std::string annotation = i->value ();
start.clear ();
end.clear ();
if (regexMatch (start, end, annotation, pattern, sensitive))
{
for (unsigned int match = 0; match < start.size (); ++match)
{
annotation.replace (start[match], end[match] - start[match], mTo);
i->value (annotation);
if (!mGlobal)
break;
if (++counter > 1000)
throw ("Terminated substitution because more than a thousand changes were made - infinite loop protection.");
}
}
}
}
else
{
#endif
if (mGlobal)
{
// Perform all subs on description.
int counter = 0;
pattern = 0;
while ((pattern = find (description, mFrom, pattern, sensitive)) != std::string::npos)
{
description.replace (pattern, mFrom.length (), mTo);
pattern += mTo.length ();
if (++counter > 1000)
throw ("Terminated substitution because more than a thousand changes were made - infinite loop protection.");
}
// Perform all subs on annotations.
counter = 0;
std::vector <Att>::iterator i;
for (i = annotations.begin (); i != annotations.end (); ++i)
{
pattern = 0;
std::string annotation = i->value ();
while ((pattern = find (annotation, mFrom, pattern, sensitive)) != std::string::npos)
{
annotation.replace (pattern, mFrom.length (), mTo);
pattern += mTo.length ();
i->value (annotation);
if (++counter > 1000)
throw ("Terminated substitution because more than a thousand changes were made - infinite loop protection.");
}
}
}
else
{
// Perform first description substitution.
if ((pattern = find (description, mFrom, sensitive)) != 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 annotation = i->value ();
if ((pattern = find (annotation, mFrom, sensitive)) != std::string::npos)
{
annotation.replace (pattern, mFrom.length (), mTo);
i->value (annotation);
break;
}
}
}
}
#ifdef FEATURE_REGEX
}
#endif
}
}
*/
////////////////////////////////////////////////////////////////////////////////