From 1f8a66b7f389d23d2b7a54808ea068c7f9730a41 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 11 Jul 2015 16:44:13 -0400 Subject: [PATCH] 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. --- src/CLI2.cpp | 19 +++++++++---------- src/Task.cpp | 8 +++++--- src/Task.h | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 15e178f83..756f86300 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -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; diff --git a/src/Task.cpp b/src/Task.cpp index 1fc58c0d5..2c9959772 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1208,8 +1208,10 @@ void Task::getUDAOrphans (std::vector & 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 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; } diff --git a/src/Task.h b/src/Task.h index b0166b6a8..6b07cd0fc 100644 --- a/src/Task.h +++ b/src/Task.h @@ -142,7 +142,7 @@ public: void getUDAs (std::vector &) const; void getUDAOrphans (std::vector &) 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);