diff options
| author | 2015-04-06 14:26:23 +0200 | |
|---|---|---|
| committer | 2015-04-06 14:26:23 +0200 | |
| commit | 379ffeb21fd4f067ea542e6b45967bab1ca004d5 (patch) | |
| tree | 1f609e31581954c0597698b5aa74635c09870434 /dicealias.cpp | |
| parent | 3ac6eea8269ee5b28c88fd0736c8963c0b8c2906 (diff) | |
| download | OneRoll-379ffeb21fd4f067ea542e6b45967bab1ca004d5.tar.gz OneRoll-379ffeb21fd4f067ea542e6b45967bab1ca004d5.zip | |
-Creation of dedicated class for alias management
Diffstat (limited to 'dicealias.cpp')
| -rw-r--r-- | dicealias.cpp | 67 |
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; +} + + |