parseTrackName static method

Map<String, dynamic> parseTrackName(
  1. String trackName
)

Implementation

static Map<String, dynamic> parseTrackName(String trackName) {
  final matches = _trackRe.firstMatch(trackName);

  if (matches == null) {
    throw ('PropertyBinding: Cannot parse trackName: $trackName');
  }

  final results = {
    // directoryName: matches[ 1 ], // (tschw) currently unused
    "nodeName": matches.group(2),
    "objectName": matches.group(3),
    "objectIndex": matches.group(4),
    "propertyName": matches.group(5), // required
    "propertyIndex": matches.group(6)
  };

  String? nodeName = results["nodeName"];

  int? lastDot;

  if (nodeName != null) {
    lastDot = nodeName.lastIndexOf('.');
  }

  if (lastDot != null && lastDot != -1) {
    final objectName = results["nodeName"]!.substring(lastDot + 1);

    // Object names must be checked against an allowlist. Otherwise, there
    // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
    // 'bar' could be the objectName, or part of a nodeName (which can
    // include '.' characters).
    if (_supportedObjectNames.contains(objectName)) {
      results["nodeName"] = results["nodeName"]!.substring(0, lastDot);
      results["objectName"] = objectName;
    }
  }

  if (results["propertyName"] == null || results["propertyName"]!.isEmpty) {
    throw ('PropertyBinding: can not parse propertyName from trackName: $trackName');
  }

  return results;
}