splitCommands function
- String command
It splits a string into a list of strings, where each string is a command
Args: command (String): The command to be split.
Returns: A list of strings that are the commands.
Implementation
List<String> splitCommands(String command) {
final String modified = command.replaceAll("\n", " ").toLowerCase().trim();
final List<String> collection = <String>[];
int open = 0;
int start = 0;
bool found = false;
for (int i = 0; i < modified.length; i++) {
if (modified[i] == "(" && !found) {
found = !found;
open++;
} else if (modified[i] == "(") {
open++;
} else if (modified[i] == ")") {
open--;
} else if (!_validCharacters.hasMatch(modified[i]) && open == 0) {
start++;
continue;
}
if (found && open == 0) {
found = !found;
collection.add(modified.substring(start, i + 1));
start = i + 1;
}
}
return collection.where((String element) => element.isNotEmpty).toList();
}