From c1665986aac79888515b75a8a851211b1fb4c516 Mon Sep 17 00:00:00 2001
From: Priyanjit Dey <priyanjitcareer@gmail.com>
Date: Thu, 7 Apr 2016 23:58:27 +0530
Subject: [PATCH] Modification of ListSliceParser

---
 Source/Processors/Editors/ChannelSelector.cpp | 14 ++---
 Source/Processors/Editors/ListSliceParser.cpp | 56 ++++++++-----------
 Source/Processors/Editors/ListSliceParser.h   |  9 ++-
 3 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/Source/Processors/Editors/ChannelSelector.cpp b/Source/Processors/Editors/ChannelSelector.cpp
index 0201c081a..0677f4e51 100755
--- a/Source/Processors/Editors/ChannelSelector.cpp
+++ b/Source/Processors/Editors/ChannelSelector.cpp
@@ -581,7 +581,7 @@ int ChannelSelector::getDesiredWidth()
 void ChannelSelector::buttonClicked(Button* button)
 {
     //checkChannelSelectors();
-    ListSliceParser* sp = new ListSliceParser("");
+    ListSliceParser sp;
     if (button == paramsButton)
     {
         // make sure param buttons are visible
@@ -686,7 +686,7 @@ void ChannelSelector::buttonClicked(Button* button)
         selectButtonParam->removeListener(this);
         deselectButtonParam->removeListener(this);
         int fa, lim, comd, i, j;
-        std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(),parameterButtons.size());
+        Array<int> getBoxList = sp.parseStringIntoRange(paramBox->getText(),parameterButtons.size());
         if (getBoxList.size() < 3)
         {
             selectButtonParam->addListener(this);
@@ -712,7 +712,7 @@ void ChannelSelector::buttonClicked(Button* button)
     {   // select channels in record tab
         selectButtonRecord->removeListener(this);
         deselectButtonRecord->removeListener(this);
-        std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
+        Array<int> getBoxList = sp.parseStringIntoRange(recordBox->getText(), recordButtons.size());
         int fa, lim, comd, i, j;
         if (getBoxList.size() < 3)
         {
@@ -739,7 +739,7 @@ void ChannelSelector::buttonClicked(Button* button)
     {   // select channels in audio tab
         selectButtonAudio->removeListener(this);
         deselectButtonAudio->removeListener(this);
-        std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
+        Array<int> getBoxList = sp.parseStringIntoRange(audioBox->getText(), audioButtons.size());
         int fa, lim, comd, i, j;
         if (getBoxList.size() < 3)
         {
@@ -766,7 +766,7 @@ void ChannelSelector::buttonClicked(Button* button)
     {   // deselect channels in param tab
         selectButtonParam->removeListener(this);
         deselectButtonParam->removeListener(this);
-        std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(), parameterButtons.size());
+        Array<int> getBoxList = sp.parseStringIntoRange(paramBox->getText(), parameterButtons.size());
         int fa, lim, comd, i, j;
         if (getBoxList.size() < 3)
         {
@@ -793,7 +793,7 @@ void ChannelSelector::buttonClicked(Button* button)
     {   // deselect channels in record tab
         selectButtonRecord->removeListener(this);
         deselectButtonRecord->removeListener(this);
-        std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
+        Array<int> getBoxList = sp.parseStringIntoRange(recordBox->getText(), recordButtons.size());
         int fa, lim, comd, i, j;
         if (getBoxList.size() < 3)
         {
@@ -820,7 +820,7 @@ void ChannelSelector::buttonClicked(Button* button)
     {   // deselect channels in audio tab
         selectButtonAudio->removeListener(this);
         deselectButtonAudio->removeListener(this);
-        std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
+        Array<int> getBoxList = sp.parseStringIntoRange(audioBox->getText(), audioButtons.size());
         int fa, lim, comd, i, j;
         if (getBoxList.size() < 3)
         {
diff --git a/Source/Processors/Editors/ListSliceParser.cpp b/Source/Processors/Editors/ListSliceParser.cpp
index 51be5af34..519b452d7 100644
--- a/Source/Processors/Editors/ListSliceParser.cpp
+++ b/Source/Processors/Editors/ListSliceParser.cpp
@@ -25,21 +25,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <vector>
 
 
-ListSliceParser::ListSliceParser(std::string s)
-{
-    defaultString = s;
-}
-
-ListSliceParser::~ListSliceParser()
-{
-
-}
-
-int ListSliceParser::convertToInteger(std::string s)
+int ListSliceParser::convertToInteger(String s)
 {
     char ar[20];
     int i, j, k = 0;
-    for (i = 0; i < s.size(); i++)
+    for (i = 0; i < s.length(); i++)
     {
         if (s[i] >= 48 && s[i] <= 57)
         {
@@ -56,18 +46,18 @@ int ListSliceParser::convertToInteger(std::string s)
     return k;
 }
 
-std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,int rangeValue)
+Array<int> ListSliceParser::parseStringIntoRange(String textBoxInfo, int rangeValue)
 {
-    std::string s = ",";
+    String s = ",";
     s += textBoxInfo;
-    std::vector<int> finalList, separator, rangeseparator;
+    Array<int> finalList, separator, rangeseparator;
     int i, j, a, b, k, openb, closeb, otherchar, x, y;
     s += ",";
-    for (i = 0; i < s.size(); i++)      //split string by ' , ' or ' ; '
+    for (i = 0; i < s.length(); i++)      //split string by ' , ' or ' ; '
     {
         if (s[i] == ';' || s[i] == ',')
         {
-            separator.push_back(i);
+            separator.add(i);
         }
     }
     for (i = 0; i < separator.size() - 1; i++)  // split ranges by ' : ' or ' - '
@@ -79,7 +69,7 @@ std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,i
         {
             if (s[j] == '-' || s[j] == ':')
             {
-                rangeseparator.push_back(j);
+                rangeseparator.add(j);
             }
             else if (((int)s[j] == 32))
             {
@@ -127,19 +117,19 @@ std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,i
 
         if (rangeseparator.size() == 0)   //syntax of form - x or [x]
         {
-            a = convertToInteger(s.substr(x, y - x + 1));
+            a = convertToInteger(s.substring(x, y + 1));
             if (a == 0 || a>rangeValue)
             {
                 continue;
             }
-            finalList.push_back(a - 1);
-            finalList.push_back(a - 1);
-            finalList.push_back(1);
+            finalList.add(a - 1);
+            finalList.add(a - 1);
+            finalList.add(1);
         }
         else if (rangeseparator.size() == 1) // syntax of type - x-y or [x-y]
         {
-            a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
-            b = convertToInteger(s.substr(rangeseparator[0], y - rangeseparator[0] + 1));
+            a = convertToInteger(s.substring(x, rangeseparator[0]));
+            b = convertToInteger(s.substring(rangeseparator[0], y + 1));
             if (a == 0)
             {
                 a = 1;
@@ -152,15 +142,15 @@ std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,i
             {
                 continue;
             }
-            finalList.push_back(a - 1);
-            finalList.push_back(b - 1);
-            finalList.push_back(1);
+            finalList.add(a - 1);
+            finalList.add(b - 1);
+            finalList.add(1);
         }
         else if (rangeseparator.size() == 2)   // syntax of type [x:y:z] or x-y-z
         {
-            a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
-            k = convertToInteger(s.substr(rangeseparator[0], rangeseparator[1] - rangeseparator[0] + 1));
-            b = convertToInteger(s.substr(rangeseparator[1], y - rangeseparator[1] + 1));
+            a = convertToInteger(s.substring(x, rangeseparator[0] + 1));
+            k = convertToInteger(s.substring(rangeseparator[0], rangeseparator[1]));
+            b = convertToInteger(s.substring(rangeseparator[1], y + 1));
             if (a == 0)
             {
                 a = 1;
@@ -177,9 +167,9 @@ std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,i
             {
                 continue;
             }
-            finalList.push_back(a - 1);
-            finalList.push_back(b - 1);
-            finalList.push_back(k);
+            finalList.add(a - 1);
+            finalList.add(b - 1);
+            finalList.add(k);
         }
     }
     return finalList;
diff --git a/Source/Processors/Editors/ListSliceParser.h b/Source/Processors/Editors/ListSliceParser.h
index f3c412dcf..f25b0e136 100644
--- a/Source/Processors/Editors/ListSliceParser.h
+++ b/Source/Processors/Editors/ListSliceParser.h
@@ -38,12 +38,11 @@ The range can be of one of the following type:
 class ListSliceParser
 {
 public:
-    ListSliceParser(std::string s);
-    ~ListSliceParser();
-    std::vector<int> parseStringIntoRange(std::string textBoxInfo,int rangeValue);
+    //ListSliceParser();
+    //~ListSliceParser();
+    static Array<int> parseStringIntoRange(String textBoxInfo,int rangeValue);
 private:
-    std::string defaultString;
-    int convertToInteger(std::string s);        //Changes string to int. Make this public if you want to use it outside this class.
+    static int convertToInteger(String s);        //Changes string to int. Make this public if you want to use it outside this class.
 };
 
 
-- 
GitLab