parseNodeProperty method

dynamic parseNodeProperty(
  1. dynamic line,
  2. dynamic property,
  3. String contentLine
)

Implementation

parseNodeProperty(line, property, String contentLine) {
  var regExp = RegExp(r'^"');
  var regExp2 = RegExp(r'"$');

  var propName = property[1].replaceFirst(regExp, '').replaceFirst(regExp2, '').trim();
  var propValue = property[2].replaceFirst(regExp, '').replaceFirst(regExp2, '').trim();

  // for special case: base64 image data follows "Content: ," line
  //	Content: ,
  //	 "/9j/4RDaRXhpZgAATU0A..."
  if (propName == 'Content' && propValue == ',') {
    propValue = contentLine.replaceAll(RegExp(r'"'), '').replaceFirst(RegExp(r',$'), '').trim();
  }

  var currentNode = getCurrentNode();
  var parentName = currentNode.name;

  if (parentName == 'Properties70') {
    parseNodeSpecialProperty(line, propName, propValue);
    return;
  }

  // Connections
  if (propName == 'C') {
    var connProps = propValue.split(',').slice(1);
    var from = int.parse(connProps[0]);
    var to = int.parse(connProps[1]);

    var rest = propValue.split(',').slice(3);

    rest = rest.map((elem) {
      return elem.trim().replace(RegExp(r'^"'), '');
    }).toList();

    propName = 'connections';
    propValue = [from, to];
    append(propValue, rest);

    if (currentNode[propName] == null) {
      currentNode[propName] = [];
    }
  }

  // Node
  if (propName == 'Node') currentNode.id = propValue;

  // connections
  if (currentNode.keys.contains(propName) && currentNode[propName] is List) {
    currentNode[propName].add(propValue);
  } else {
    if (propName != 'a') {
      currentNode[propName] = propValue;
    } else {
      currentNode.a = propValue;
    }
  }

  setCurrentProp(currentNode, propName);

  // convert string to array, unless it ends in ',' in which case more will be added to it
  if (propName == 'a' && propValue.slice(-1) != ',') {
    currentNode.a = parseNumberArray(propValue);
  }
}