aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2020-05-01 04:37:47 +0200
committerRenaud G <renaud@rolisteam.org>2020-05-01 04:37:47 +0200
commitcdc2fcccdbdb40530ff1c63f70c43bf1100e3410 (patch)
tree27fa234c20495dc455ec4c7b4f09104eab94dcda
parent2e09c80db228b5ac4043864e90e8c4c1e3284418 (diff)
downloadOneRoll-cdc2fcccdbdb40530ff1c63f70c43bf1100e3410.tar.gz
OneRoll-cdc2fcccdbdb40530ff1c63f70c43bf1100e3410.zip
fix #82 return 0 for no reason.
-rw-r--r--include/parsingtoolbox.h2
-rw-r--r--parsingtoolbox.cpp37
2 files changed, 18 insertions, 21 deletions
diff --git a/include/parsingtoolbox.h b/include/parsingtoolbox.h
index f8e88af..f3031f2 100644
--- a/include/parsingtoolbox.h
+++ b/include/parsingtoolbox.h
@@ -381,7 +381,7 @@ private:
QMap<QString, BooleanCondition::LogicOperator> m_logicOp;
QMap<QString, ValidatorList::LogicOperation> m_logicOperation;
QMap<QString, OperationCondition::ConditionOperator> m_conditionOperation;
- QHash<QString, Die::ArithmeticOperator> m_arithmeticOperation;
+ std::vector<std::pair<QString, Die::ArithmeticOperator>> m_arithmeticOperation;
QMap<QString, DiceOperator> m_mapDiceOp;
QMap<QString, OptionOperator> m_OptionOp;
QMap<QString, NodeAction> m_nodeActionMap;
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index e53cf96..e0b1df0 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -74,14 +74,14 @@ ParsingToolBox::ParsingToolBox()
m_conditionOperation.insert("%", OperationCondition::Modulo);
// m_arithmeticOperation = new QHash<QString,ScalarOperatorNode::ArithmeticOperator>();
- m_arithmeticOperation.insert(QStringLiteral("+"), Die::PLUS);
- m_arithmeticOperation.insert(QStringLiteral("-"), Die::MINUS);
- m_arithmeticOperation.insert(QStringLiteral("**"), Die::POW);
- m_arithmeticOperation.insert(QStringLiteral("*"), Die::MULTIPLICATION);
- m_arithmeticOperation.insert(QStringLiteral("x"), Die::MULTIPLICATION);
- m_arithmeticOperation.insert(QStringLiteral("|"), Die::INTEGER_DIVIDE);
- m_arithmeticOperation.insert(QStringLiteral("/"), Die::DIVIDE);
- m_arithmeticOperation.insert(QStringLiteral("÷"), Die::DIVIDE);
+ m_arithmeticOperation.push_back({QStringLiteral("**"), Die::POW});
+ m_arithmeticOperation.push_back({QStringLiteral("+"), Die::PLUS});
+ m_arithmeticOperation.push_back({QStringLiteral("-"), Die::MINUS});
+ m_arithmeticOperation.push_back({QStringLiteral("*"), Die::MULTIPLICATION});
+ m_arithmeticOperation.push_back({QStringLiteral("x"), Die::MULTIPLICATION});
+ m_arithmeticOperation.push_back({QStringLiteral("|"), Die::INTEGER_DIVIDE});
+ m_arithmeticOperation.push_back({QStringLiteral("/"), Die::DIVIDE});
+ m_arithmeticOperation.push_back({QStringLiteral("÷"), Die::DIVIDE});
m_mapDiceOp.insert(QStringLiteral("D"), D);
m_mapDiceOp.insert(QStringLiteral("L"), L);
@@ -177,19 +177,16 @@ bool ParsingToolBox::readDiceLogicOperator(QString& str, OperationCondition::Con
bool ParsingToolBox::readArithmeticOperator(QString& str, Die::ArithmeticOperator& op)
{
- bool found= false;
- // QHash<QString,ScalarOperatorNode::ArithmeticOperator>::Iterator
- for(auto i= m_arithmeticOperation.begin(); i != m_arithmeticOperation.end() && !found; ++i)
- {
- if(str.startsWith(i.key()))
- {
- op= i.value();
- str= str.remove(0, i.key().size());
- found= true;
- }
- }
- return found;
+ auto it= std::find_if(
+ m_arithmeticOperation.begin(), m_arithmeticOperation.end(),
+ [str](const std::pair<QString, Die::ArithmeticOperator>& pair) { return str.startsWith(pair.first); });
+ if(it == m_arithmeticOperation.end())
+ return false;
+
+ op= it->second;
+ str= str.remove(0, it->first.size());
+ return true;
}
bool ParsingToolBox::readLogicOperator(QString& str, BooleanCondition::LogicOperator& op)