Skip to content

Commit c166598

Browse files
Modification of ListSliceParser
1 parent 1d4ff66 commit c166598

3 files changed

Lines changed: 34 additions & 45 deletions

File tree

Source/Processors/Editors/ChannelSelector.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ int ChannelSelector::getDesiredWidth()
581581
void ChannelSelector::buttonClicked(Button* button)
582582
{
583583
//checkChannelSelectors();
584-
ListSliceParser* sp = new ListSliceParser("");
584+
ListSliceParser sp;
585585
if (button == paramsButton)
586586
{
587587
// make sure param buttons are visible
@@ -686,7 +686,7 @@ void ChannelSelector::buttonClicked(Button* button)
686686
selectButtonParam->removeListener(this);
687687
deselectButtonParam->removeListener(this);
688688
int fa, lim, comd, i, j;
689-
std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(),parameterButtons.size());
689+
Array<int> getBoxList = sp.parseStringIntoRange(paramBox->getText(),parameterButtons.size());
690690
if (getBoxList.size() < 3)
691691
{
692692
selectButtonParam->addListener(this);
@@ -712,7 +712,7 @@ void ChannelSelector::buttonClicked(Button* button)
712712
{ // select channels in record tab
713713
selectButtonRecord->removeListener(this);
714714
deselectButtonRecord->removeListener(this);
715-
std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
715+
Array<int> getBoxList = sp.parseStringIntoRange(recordBox->getText(), recordButtons.size());
716716
int fa, lim, comd, i, j;
717717
if (getBoxList.size() < 3)
718718
{
@@ -739,7 +739,7 @@ void ChannelSelector::buttonClicked(Button* button)
739739
{ // select channels in audio tab
740740
selectButtonAudio->removeListener(this);
741741
deselectButtonAudio->removeListener(this);
742-
std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
742+
Array<int> getBoxList = sp.parseStringIntoRange(audioBox->getText(), audioButtons.size());
743743
int fa, lim, comd, i, j;
744744
if (getBoxList.size() < 3)
745745
{
@@ -766,7 +766,7 @@ void ChannelSelector::buttonClicked(Button* button)
766766
{ // deselect channels in param tab
767767
selectButtonParam->removeListener(this);
768768
deselectButtonParam->removeListener(this);
769-
std::vector<int> getBoxList = sp->parseStringIntoRange(paramBox->getText().toStdString(), parameterButtons.size());
769+
Array<int> getBoxList = sp.parseStringIntoRange(paramBox->getText(), parameterButtons.size());
770770
int fa, lim, comd, i, j;
771771
if (getBoxList.size() < 3)
772772
{
@@ -793,7 +793,7 @@ void ChannelSelector::buttonClicked(Button* button)
793793
{ // deselect channels in record tab
794794
selectButtonRecord->removeListener(this);
795795
deselectButtonRecord->removeListener(this);
796-
std::vector<int> getBoxList = sp->parseStringIntoRange(recordBox->getText().toStdString(), recordButtons.size());
796+
Array<int> getBoxList = sp.parseStringIntoRange(recordBox->getText(), recordButtons.size());
797797
int fa, lim, comd, i, j;
798798
if (getBoxList.size() < 3)
799799
{
@@ -820,7 +820,7 @@ void ChannelSelector::buttonClicked(Button* button)
820820
{ // deselect channels in audio tab
821821
selectButtonAudio->removeListener(this);
822822
deselectButtonAudio->removeListener(this);
823-
std::vector<int> getBoxList = sp->parseStringIntoRange(audioBox->getText().toStdString(), audioButtons.size());
823+
Array<int> getBoxList = sp.parseStringIntoRange(audioBox->getText(), audioButtons.size());
824824
int fa, lim, comd, i, j;
825825
if (getBoxList.size() < 3)
826826
{

Source/Processors/Editors/ListSliceParser.cpp

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2525
#include <vector>
2626

2727

28-
ListSliceParser::ListSliceParser(std::string s)
29-
{
30-
defaultString = s;
31-
}
32-
33-
ListSliceParser::~ListSliceParser()
34-
{
35-
36-
}
37-
38-
int ListSliceParser::convertToInteger(std::string s)
28+
int ListSliceParser::convertToInteger(String s)
3929
{
4030
char ar[20];
4131
int i, j, k = 0;
42-
for (i = 0; i < s.size(); i++)
32+
for (i = 0; i < s.length(); i++)
4333
{
4434
if (s[i] >= 48 && s[i] <= 57)
4535
{
@@ -56,18 +46,18 @@ int ListSliceParser::convertToInteger(std::string s)
5646
return k;
5747
}
5848

59-
std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,int rangeValue)
49+
Array<int> ListSliceParser::parseStringIntoRange(String textBoxInfo, int rangeValue)
6050
{
61-
std::string s = ",";
51+
String s = ",";
6252
s += textBoxInfo;
63-
std::vector<int> finalList, separator, rangeseparator;
53+
Array<int> finalList, separator, rangeseparator;
6454
int i, j, a, b, k, openb, closeb, otherchar, x, y;
6555
s += ",";
66-
for (i = 0; i < s.size(); i++) //split string by ' , ' or ' ; '
56+
for (i = 0; i < s.length(); i++) //split string by ' , ' or ' ; '
6757
{
6858
if (s[i] == ';' || s[i] == ',')
6959
{
70-
separator.push_back(i);
60+
separator.add(i);
7161
}
7262
}
7363
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
7969
{
8070
if (s[j] == '-' || s[j] == ':')
8171
{
82-
rangeseparator.push_back(j);
72+
rangeseparator.add(j);
8373
}
8474
else if (((int)s[j] == 32))
8575
{
@@ -127,19 +117,19 @@ std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,i
127117

128118
if (rangeseparator.size() == 0) //syntax of form - x or [x]
129119
{
130-
a = convertToInteger(s.substr(x, y - x + 1));
120+
a = convertToInteger(s.substring(x, y + 1));
131121
if (a == 0 || a>rangeValue)
132122
{
133123
continue;
134124
}
135-
finalList.push_back(a - 1);
136-
finalList.push_back(a - 1);
137-
finalList.push_back(1);
125+
finalList.add(a - 1);
126+
finalList.add(a - 1);
127+
finalList.add(1);
138128
}
139129
else if (rangeseparator.size() == 1) // syntax of type - x-y or [x-y]
140130
{
141-
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
142-
b = convertToInteger(s.substr(rangeseparator[0], y - rangeseparator[0] + 1));
131+
a = convertToInteger(s.substring(x, rangeseparator[0]));
132+
b = convertToInteger(s.substring(rangeseparator[0], y + 1));
143133
if (a == 0)
144134
{
145135
a = 1;
@@ -152,15 +142,15 @@ std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,i
152142
{
153143
continue;
154144
}
155-
finalList.push_back(a - 1);
156-
finalList.push_back(b - 1);
157-
finalList.push_back(1);
145+
finalList.add(a - 1);
146+
finalList.add(b - 1);
147+
finalList.add(1);
158148
}
159149
else if (rangeseparator.size() == 2) // syntax of type [x:y:z] or x-y-z
160150
{
161-
a = convertToInteger(s.substr(x, rangeseparator[0] - x + 1));
162-
k = convertToInteger(s.substr(rangeseparator[0], rangeseparator[1] - rangeseparator[0] + 1));
163-
b = convertToInteger(s.substr(rangeseparator[1], y - rangeseparator[1] + 1));
151+
a = convertToInteger(s.substring(x, rangeseparator[0] + 1));
152+
k = convertToInteger(s.substring(rangeseparator[0], rangeseparator[1]));
153+
b = convertToInteger(s.substring(rangeseparator[1], y + 1));
164154
if (a == 0)
165155
{
166156
a = 1;
@@ -177,9 +167,9 @@ std::vector<int> ListSliceParser::parseStringIntoRange(std::string textBoxInfo,i
177167
{
178168
continue;
179169
}
180-
finalList.push_back(a - 1);
181-
finalList.push_back(b - 1);
182-
finalList.push_back(k);
170+
finalList.add(a - 1);
171+
finalList.add(b - 1);
172+
finalList.add(k);
183173
}
184174
}
185175
return finalList;

Source/Processors/Editors/ListSliceParser.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ The range can be of one of the following type:
3838
class ListSliceParser
3939
{
4040
public:
41-
ListSliceParser(std::string s);
42-
~ListSliceParser();
43-
std::vector<int> parseStringIntoRange(std::string textBoxInfo,int rangeValue);
41+
//ListSliceParser();
42+
//~ListSliceParser();
43+
static Array<int> parseStringIntoRange(String textBoxInfo,int rangeValue);
4444
private:
45-
std::string defaultString;
46-
int convertToInteger(std::string s); //Changes string to int. Make this public if you want to use it outside this class.
45+
static int convertToInteger(String s); //Changes string to int. Make this public if you want to use it outside this class.
4746
};
4847

4948

0 commit comments

Comments
 (0)