fromString static method

DotNotation? fromString(
  1. String? string
)

Implementation

static DotNotation? fromString(String? string) {
  if (string == null) return null;

  DotNotation? dotnotation;

  // build sub-properties (name and offset) list
  List<String> parts = string.split(".");
  if (parts.isNotEmpty) {
    dotnotation = DotNotation(string);
    for (String part in parts) {
      // split by name:offset
      List<String> subparts = part.split(":");

      NotationSegment property = NotationSegment();

      // set name
      if (subparts.isNotEmpty) {
        property.name = subparts[0].trim();
        subparts.removeAt(0);
      }

      // set offset
      if (subparts.isNotEmpty) {
        String offset = subparts[0].trim();
        if (offset == "*") offset = "-1";
        property.offset = toInt(offset) ?? 0;
        subparts.removeAt(0);
      }

      // add to the list
      dotnotation.add(property);
    }
  }
  return dotnotation;
}