aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dicealias.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2015-04-06 14:26:23 +0200
committerRenaud G <renaud@rolisteam.org>2015-04-06 14:26:23 +0200
commit379ffeb21fd4f067ea542e6b45967bab1ca004d5 (patch)
tree1f609e31581954c0597698b5aa74635c09870434 /dicealias.cpp
parent3ac6eea8269ee5b28c88fd0736c8963c0b8c2906 (diff)
downloadOneRoll-379ffeb21fd4f067ea542e6b45967bab1ca004d5.tar.gz
OneRoll-379ffeb21fd4f067ea542e6b45967bab1ca004d5.zip
-Creation of dedicated class for alias management
Diffstat (limited to 'dicealias.cpp')
-rw-r--r--dicealias.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/dicealias.cpp b/dicealias.cpp
new file mode 100644
index 0000000..2a09206
--- /dev/null
+++ b/dicealias.cpp
@@ -0,0 +1,67 @@
+#include "dicealias.h"
+#include <QRegularExpression>
+
+DiceAlias::DiceAlias(QString cmd, QString key, bool isReplace)
+ : m_command(cmd),m_value(key)
+{
+ if(isReplace)
+ {
+ m_type = REPLACE;
+ }
+ else
+ {
+ m_type = REGEXP;
+ }
+}
+
+DiceAlias::~DiceAlias()
+{
+
+}
+
+bool DiceAlias::resolved(QString & str)
+{
+ if((m_type == REPLACE)&&(str.contains(m_command)))
+ {
+ str.replace(m_command,m_value);
+ return true;
+ }
+ else if(m_type == REGEXP)
+ {
+ QRegularExpression exp(m_command);
+ str.replace(exp,m_value);
+ return true;
+ }
+ return false;
+}
+
+void DiceAlias::setCommand(QString key)
+{
+ m_command = key;
+}
+
+void DiceAlias::setValue(QString value)
+{
+ m_value = value;
+}
+
+void DiceAlias::setType(RESOLUTION_TYPE type)
+{
+ m_type = type;
+}
+QString DiceAlias::getCommand()
+{
+ return m_command;
+}
+
+QString DiceAlias::getValue()
+{
+ return m_value;
+}
+
+bool DiceAlias::isReplace()
+{
+ return (m_type == REPLACE) ? true : false;
+}
+
+