Expression: evaluate adjusts the end iterator to the end

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I1e3f3a0acedcaf9feb6d888e3ac31bf5bb542a9d
diff --git a/include/Expression.hpp b/include/Expression.hpp
index e2ecb52..00b9cc0 100644
--- a/include/Expression.hpp
+++ b/include/Expression.hpp
@@ -34,6 +34,6 @@
 
 std::optional<Operation> parseOperation(std::string& op);
 int evaluate(int a, Operation op, int b);
-int evaluate(int substitute, std::vector<std::string>::iterator& curr,
-             std::vector<std::string>::iterator&& end);
+int evaluate(int substitute, std::vector<std::string>::iterator curr,
+             std::vector<std::string>::iterator& end);
 } // namespace expression
diff --git a/src/Expression.cpp b/src/Expression.cpp
index b3f21d9..34be337 100644
--- a/src/Expression.cpp
+++ b/src/Expression.cpp
@@ -78,8 +78,8 @@
     }
 }
 
-int evaluate(int substitute, std::vector<std::string>::iterator& curr,
-             std::vector<std::string>::iterator&& end)
+int evaluate(int substitute, std::vector<std::string>::iterator curr,
+             std::vector<std::string>::iterator& end)
 {
     bool isOperator = true;
     std::optional<Operation> next = Operation::addition;
@@ -111,6 +111,7 @@
         isOperator = !isOperator;
     }
 
+    end = curr;
     return substitute;
 }
 } // namespace expression
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 4ebb246..f96e56f 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -292,30 +292,31 @@
             continue;
         }
 
-        auto it = split.begin();
-
         // we assume that the replacement is a number, because we can
         // only do math on numbers.. we might concatenate strings in the
         // future, but thats later
         int number = std::visit(VariantToIntVisitor(), propValue);
+        auto exprBegin = split.begin();
+        auto exprEnd = split.end();
 
-        number = expression::evaluate(number, it, split.end());
+        number = expression::evaluate(number, exprBegin, exprEnd);
 
         std::string result = prefix + std::to_string(number);
 
         std::string replaced(find.begin(), find.end());
-        for (auto it2 = split.begin(); it2 != it; it2++)
+        while (exprBegin != exprEnd)
         {
             replaced += " ";
-            replaced += *it2;
+            replaced += *exprBegin++;
         }
+
         ret = replaced;
 
-        if (it != split.end())
+        if (exprEnd != split.end())
         {
-            for (; it != split.end(); it++)
+            while (exprEnd != split.end())
             {
-                result += " " + *it;
+                result += " " + *exprEnd++;
             }
         }
         keyPair.value() = result;