@@ -37,8 +37,8 @@ ChannelSelector::ChannelSelector(bool createButtons, Font& titleFont_) :
3737{
3838
3939 // initialize buttons
40- audioButton = new EditorButton (" AUDIO" , titleFont);
41- audioButton->addListener (this );
40+ audioButton = new EditorButton (" AUDIO" , titleFont);
41+ audioButton->addListener (this );
4242 addAndMakeVisible (audioButton);
4343 if (!createButtons)
4444 audioButton->setState (false );
@@ -1238,22 +1238,22 @@ int ChannelSelectorBox::convertToInteger(std::string s)
12381238{
12391239 char ar[20 ];
12401240 int i,j,k=0 ;
1241- for (i = 0 ; i < s.size (); i++)
1242- {
1243- if ((int )s[i] != 32 )
1244- {
1245- break ;
1246- }
1247- }
1248- for (j = s.size () - 1 ; j >= 0 ; j--)
1249- {
1250- if ((int )s[j] != 32 )
1251- {
1252- break ;
1253- }
1254- }
1255-
1256- for (; i <= j; i++)
1241+ for (i = 0 ; i < s.size (); i++) // trim whitespace from front
1242+ {
1243+ if ((int )s[i] != 32 )
1244+ {
1245+ break ;
1246+ }
1247+ }
1248+ for (j = s.size () - 1 ; j >= 0 ; j--) // trim whitespaces from end
1249+ {
1250+ if ((int )s[j] != 32 )
1251+ {
1252+ break ;
1253+ }
1254+ }
1255+
1256+ for (; i <= j; i++)
12571257 {
12581258 if (s[i] >= 48 && s[i] <= 57 )
12591259 {
@@ -1279,100 +1279,105 @@ std::vector<int> ChannelSelectorBox::getBoxInfo(int len)
12791279 std::vector<std::string> parsed;
12801280 std::vector<int > finalList,colonNum,boxList;
12811281 finalList.clear ();
1282- int i, j, k, a, otherChar = 0 , b, x;
1283-
1284- for (i = 0 ; i < s.size (); i++)
1285- {
1286- if (s[i] == ' [' )
1287- {
1288- boxList.push_back (i);
1289- j = i + 1 ;
1290- for (; j < s.size (); j++)
1291- {
1292- if (s[j] == ' ]' )
1293- {
1294- boxList.push_back (j); break ;
1295- }
1296- }
1297- i = j;
1298- }
1299- }
1300-
1301- if (boxList.size () % 2 != 0 )
1302- {
1303- boxList.pop_back ();
1304- }
1305-
1306- for (i = 0 ; i < boxList.size (); i+=2 )
1307- {
1308- colonNum.clear (); otherChar = 0 ;
1309- for (x = boxList[i] + 1 ; x < boxList[i + 1 ]; x++)
1310- {
1311- if (s[x] == ' :' )
1312- {
1313- colonNum.push_back (x);
1314- }
1315- else if ((int )s[x] == 32 )
1316- {
1317- continue ;
1318- }
1319- else if (((int )s[x] < 48 || (int )s[x]>57 ))
1320- {
1321- otherChar++;
1322- }
1323- }
1324- if (colonNum.size ()>2 || colonNum.size () < 1 || otherChar > 0 )
1325- {
1326- continue ;
1327- }
1328-
1329- if (colonNum.size () == 1 )
1330- {
1331- a = convertToInteger (s.substr (boxList[i], colonNum[0 ] - boxList[i] + 1 ));
1332- b = convertToInteger (s.substr (colonNum[0 ], boxList[i+1 ] - colonNum[0 ] + 1 ));
1333- if (a == 0 )
1334- {
1335- a = 1 ;
1336- }
1337- if (b == 0 )
1338- {
1339- b = len;
1340- }
1341- if (a > len || b > len || a > b)
1342- {
1343- continue ;
1344- }
1345- finalList.push_back (a - 1 );
1346- finalList.push_back (b - 1 );
1347- finalList.push_back (1 );
1348- }
1349- else if (colonNum.size () == 2 )
1350- {
1351- a = convertToInteger (s.substr (boxList[i], colonNum[0 ] - boxList[i] + 1 ));
1352- k = convertToInteger (s.substr (colonNum[0 ], colonNum[1 ] - colonNum[0 ] + 1 ));
1353- b = convertToInteger (s.substr (colonNum[1 ], boxList[i+1 ] - colonNum[1 ] + 1 ));
1354- if (k == 0 )
1355- {
1356- k = 1 ;
1357- }
1358- if (a == 0 )
1359- {
1360- a = 1 ;
1361- }
1362- if (b == 0 )
1363- {
1364- b = len;
1365- }
1366-
1367- if (a > len || b > len || a > b)
1368- {
1369- continue ;
1370- }
1371- finalList.push_back (a - 1 );
1372- finalList.push_back (b - 1 );
1373- finalList.push_back (k);
1374- }
1375- }
1282+ int i, j, k, a, otherChar = 0 , b, x;
1283+
1284+ for (i = 0 ; i < s.size (); i++) // fetch all valid ranges from text box
1285+ {
1286+ if (s[i] == ' [' )
1287+ {
1288+ boxList.push_back (i);
1289+ j = i + 1 ;
1290+ for (; j < s.size (); j++)
1291+ {
1292+ if (s[j] == ' ]' )
1293+ {
1294+ boxList.push_back (j);
1295+ break ;
1296+ }
1297+ }
1298+ i = j;
1299+ }
1300+ }
1301+
1302+ if (boxList.size () % 2 != 0 )
1303+ {
1304+ boxList.pop_back ();
1305+ }
1306+
1307+ /*
1308+ for each valid ranges fetch the start value, end value, common difference.
1309+ */
1310+ for (i = 0 ; i < boxList.size (); i+=2 )
1311+ {
1312+ colonNum.clear ();
1313+ otherChar = 0 ;
1314+ for (x = boxList[i] + 1 ; x < boxList[i + 1 ]; x++)
1315+ {
1316+ if (s[x] == ' :' )
1317+ {
1318+ colonNum.push_back (x);
1319+ }
1320+ else if ((int )s[x] == 32 )
1321+ {
1322+ continue ;
1323+ }
1324+ else if (((int )s[x] < 48 || (int )s[x]>57 ))
1325+ {
1326+ otherChar++;
1327+ }
1328+ }
1329+ if (colonNum.size ()>2 || colonNum.size () < 1 || otherChar > 0 )
1330+ {
1331+ continue ;
1332+ }
1333+
1334+ if (colonNum.size () == 1 ) // when range is of form [x:y]
1335+ {
1336+ a = convertToInteger (s.substr (boxList[i], colonNum[0 ] - boxList[i] + 1 ));
1337+ b = convertToInteger (s.substr (colonNum[0 ], boxList[i+1 ] - colonNum[0 ] + 1 ));
1338+ if (a == 0 )
1339+ {
1340+ a = 1 ;
1341+ }
1342+ if (b == 0 )
1343+ {
1344+ b = len;
1345+ }
1346+ if (a > len || b > len || a > b)
1347+ {
1348+ continue ;
1349+ }
1350+ finalList.push_back (a - 1 );
1351+ finalList.push_back (b - 1 );
1352+ finalList.push_back (1 );
1353+ }
1354+ else if (colonNum.size () == 2 ) // when range is of form [x:k:y]
1355+ {
1356+ a = convertToInteger (s.substr (boxList[i], colonNum[0 ] - boxList[i] + 1 ));
1357+ k = convertToInteger (s.substr (colonNum[0 ], colonNum[1 ] - colonNum[0 ] + 1 ));
1358+ b = convertToInteger (s.substr (colonNum[1 ], boxList[i+1 ] - colonNum[1 ] + 1 ));
1359+ if (k == 0 )
1360+ {
1361+ k = 1 ;
1362+ }
1363+ if (a == 0 )
1364+ {
1365+ a = 1 ;
1366+ }
1367+ if (b == 0 )
1368+ {
1369+ b = len;
1370+ }
1371+
1372+ if (a > len || b > len || a > b)
1373+ {
1374+ continue ;
1375+ }
1376+ finalList.push_back (a - 1 );
1377+ finalList.push_back (b - 1 );
1378+ finalList.push_back (k);
1379+ }
1380+ }
13761381
13771382 return finalList;
13781383}
0 commit comments