parseTrackName static method

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

Implementation

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

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

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

  var results = <String, String?>{
    // 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) {
    var 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;
}