splitGenericParameters function

List<String> splitGenericParameters(
  1. String str, [
  2. (String, String) genericSeparators = ('<', '>')
])

Implementation

List<String> splitGenericParameters(
	String str,
	[(String, String) genericSeparators = ('<', '>')]
) {
	final (left, right) = genericSeparators;
	final tok = <String>[];
	String word = '';
	int nestedAngleBrackets = 0;

	for (int i = 0; i < str.length; i++) {
		final char = str[i];
		if (char == left) {
			nestedAngleBrackets++;
		}
		if (char == right) {
			nestedAngleBrackets--;
		}
		if (nestedAngleBrackets == 0 && char == ',') {
			tok.add(word.trim());
			word = '';
			continue;
		}
		word += char;
	}

	tok.add(word.trim());

	return tok;
}