Skip to content
Snippets Groups Projects
Commit c1665986 authored by Priyanjit Dey's avatar Priyanjit Dey
Browse files

Modification of ListSliceParser

parent 1d4ff66e
No related branches found
No related tags found
No related merge requests found
......@@ -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)
{
......
......@@ -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;
......
......@@ -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.
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment