CLI2: Integrated Lexer::decomposeSubstitution

- Task::modify now considers the 'g' at the end of a substitution to be a
  string of characters, which may contain 'g'. No other flags are currently
  supported.
This commit is contained in:
Paul Beckingham 2015-07-11 16:44:13 -04:00
parent 1bef45ff47
commit 1f8a66b7f3
3 changed files with 15 additions and 14 deletions

View file

@ -159,23 +159,22 @@ void A2::decompose ()
else if (_lextype == Lexer::Type::substitution)
{
std::string raw = _attributes["raw"];
//if (Directory (raw).exists ())
// return;
auto slash1 = raw.find ("/");
auto slash2 = raw.find ("/", slash1 + 1);
auto slash3 = raw.find ("/", slash2 + 1);
attribute ("from", raw.substr (slash1 + 1, slash2 - slash1 - 1));
attribute ("to", raw.substr (slash2 + 1, slash3 - slash2 - 1));
attribute ("global", raw.substr (slash3 + 1) == "g" ? 1 : 0);
std::string from;
std::string to;
std::string flags;
if (Lexer::decomposeSubstitution (_attributes["raw"], from, to, flags))
{
attribute ("from", from);
attribute ("to", to);
attribute ("flags", flags);
}
}
else if (_lextype == Lexer::Type::pair)
{
std::string raw = _attributes["raw"];
std::string name;
std::string mod;
std::string sep;

View file

@ -1208,8 +1208,10 @@ void Task::getUDAOrphans (std::vector <std::string>& names) const
void Task::substitute (
const std::string& from,
const std::string& to,
bool global)
const std::string& flags)
{
bool global = (flags.find ('g') != std::string::npos ? true : false);
// Get the data to modify.
std::string description = get ("description");
std::map <std::string, std::string> annotations;
@ -2076,13 +2078,13 @@ void Task::modify (modType type, bool text_required /* = false */)
}
}
// arg7 from='from' global='1' raw='/from/to/g' to='to' ORIGINAL SUBSTITUTION MODIFICATION
// Perform description/annotation substitution.
else if (a._lextype == Lexer::Type::substitution)
{
context.debug (label + "substitute " + a.attribute ("raw"));
substitute (a.attribute ("from"),
a.attribute ("to"),
(a.attribute ("global") == "1"));
a.attribute ("flags"));
++modCount;
}

View file

@ -142,7 +142,7 @@ public:
void getUDAs (std::vector <std::string>&) const;
void getUDAOrphans (std::vector <std::string>&) const;
void substitute (const std::string&, const std::string&, bool);
void substitute (const std::string&, const std::string&, const std::string&);
#endif
void validate (bool applyDefault = true);