splitCommand function
- String command
It splits a string into a list of strings, but it ignores commas and parentheses that are inside curly braces
Args: command (String): The command to be split.
Returns: A list of strings.
Implementation
List<String> splitCommand(String command) {
final List<String> splitted = <String>[];
int start = 0;
int open = 0;
bool square = false;
for (int i = 0; i < command.length; i++) {
if (open == 0) {
square = false;
}
if ((command[i] == "(" || command[i] == ")" || command[i] == ",") &&
!square) {
splitted.add(command.substring(start, i).trim());
start = i + 1;
}
if (command[i] == "{") {
open++;
square = true;
} else if (command[i] == "}") {
open--;
}
}
return splitted.where((String element) => element.isNotEmpty).toList();
}