isSingleVarFunction method

bool isSingleVarFunction(
  1. String v
)

Implementation

bool isSingleVarFunction(String v) {
  int i = 0;
  final s = v.trimLeft();
  // Must begin with 'var('
  if (!s.startsWith('var(')) return false;
  // Find the position of the opening '(' after 'var'
  int start = s.indexOf('(');
  int depth = 0;
  for (i = start; i < s.length; i++) {
    final ch = s.codeUnitAt(i);
    if (ch == 40) { // '('
      depth++;
    } else if (ch == 41) { // ')'
      depth--;
      if (depth == 0) {
        // i is the matching closing ')'. Ensure the rest is only whitespace.
        final rest = s.substring(i + 1).trim();
        return rest.isEmpty;
      }
    }
  }
  return false;
}