aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/parsingtoolbox.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@buf.com>2015-05-15 14:49:49 +0200
committerRenaud G <renaud@buf.com>2015-05-15 14:49:49 +0200
commitf8a2e958e699ca41730cb785e7284c07eaaa5a82 (patch)
tree0fcf40cbd39840432bb61932479a5d4bb6b2d85c /parsingtoolbox.cpp
parent03cae353e4a070391850118b5c7e2b5ce4c8828f (diff)
downloadOneRoll-f8a2e958e699ca41730cb785e7284c07eaaa5a82.tar.gz
OneRoll-f8a2e958e699ca41730cb785e7284c07eaaa5a82.zip
add method to read dice range (a bit different from validator range)
Diffstat (limited to 'parsingtoolbox.cpp')
-rw-r--r--parsingtoolbox.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index 3e09bac..0052f07 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -141,7 +141,7 @@ bool ParsingToolBox::readNumber(QString& str, int& myNumber)
QString number;
int i=0;
- while(i<str.length() && str[i].isNumber())
+ while(i<str.length() && ((str[i].isNumber()) || ( (i==0) && (str[i]=='-'))))
{
number+=str[i];
++i;
@@ -234,3 +234,44 @@ DiceRollerNode* ParsingToolBox::getDiceRollerNode(ExecutionNode* previous)
previous = previous->getPreviousNode();
}
}
+bool ParsingToolBox::readDiceRange(QString& str,int& start, int& end)
+{
+ bool expectSquareBrasket=false;
+
+ qDebug()<<"readDiceRange"<<str;
+ if((str.startsWith("[")))
+ {
+ str=str.remove(0,1);
+ expectSquareBrasket = true;
+ }
+qDebug()<<"readDiceRange"<<str;
+ if(readNumber(str,start))
+ {
+ qDebug()<<"readDiceRange"<<str;
+ if(str.startsWith("-"))
+ {
+ str=str.remove(0,1);
+ if(readNumber(str,end))
+ {
+ if(expectSquareBrasket)
+ {
+ if(str.startsWith("]"))
+ {
+ str=str.remove(0,1);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+ else
+ {
+ return false;
+ }
+ qDebug()<<"readDiceRange"<<str;
+ }
+ }
+
+}