]> git.tdb.fi Git - builder.git/blobdiff - source/booleanevaluator.cpp
Use format() when creating strings from more than two parts
[builder.git] / source / booleanevaluator.cpp
index 074956a7a29b4cfddca039b1506eaaf30bf5dabb..58a6fcf1a682b53aa0c6ef54627a9f7729f7eecd 100644 (file)
@@ -1,13 +1,18 @@
 #include <stdexcept>
+#include <msp/strings/format.h>
 #include "booleanevaluator.h"
 
 using namespace std;
+using namespace Msp;
 
-/* I'd rather have overloads with different slots, but that creates an
-ambiguity because slots have template constructors. */
-BooleanEvaluator::BooleanEvaluator(const Function &f, bool allow_compare):
+BooleanEvaluator::BooleanEvaluator(const ValueFunction &f):
+       func([&f](const string &value, const string *){ return f(value); }),
+       ops("&|!")
+{ }
+
+BooleanEvaluator::BooleanEvaluator(const CompareFunction &f):
        func(f),
-       ops(allow_compare ? "&|!=^" : "&|!")
+       ops("&|!=^")
 { }
 
 bool BooleanEvaluator::evaluate(const string &str)
@@ -48,7 +53,7 @@ bool BooleanEvaluator::evaluate(const string &str)
                        else if(ops.find(*i)!=string::npos)
                                push_op(*i);
                        else
-                               throw runtime_error("syntax error at "+string(1, *i));
+                               throw runtime_error(format("syntax error at %c", *i));
                }
        }
 
@@ -64,7 +69,7 @@ bool BooleanEvaluator::evaluate(const string &str)
 void BooleanEvaluator::push_op(char op)
 {
        if(last_was_op!=is_unary(op))
-               throw runtime_error("syntax error at "+string(1, op));
+               throw runtime_error(format("syntax error at %c", op));
        // TODO Disallow mixing of ! and =/^
        if(is_logic(op) && !var_stack.empty())
                value_stack.push_back(pop_value());