parse static method

PathInfo parse(
  1. String source
)

Retrieves path information, including pairs of segments and an ending.

Implementation

static PathInfo parse(String source) {
  final path = source.startsWith("/") ? source.substring(1) : source;
  final isValid = path.isNotEmpty && RegExp(_pathRegs).hasMatch(path);
  if (isValid) {
    var segments = path.split("/");
    int length = segments.length;
    String? end = length.isOdd ? segments.last : null;
    List<String> x = [];
    List<String> y = [];
    List.generate(length.isOdd ? length - 1 : length, (i) {
      i.isEven ? x.add(segments[i]) : y.add(segments[i]);
    });
    return PathInfo(
      source: source,
      ending: end,
      collections: x,
      documents: y,
      pairs: List.generate(x.length, (index) {
        return PathPair(x[index], y[index]);
      }),
    );
  }
  return PathInfo(source: source, invalid: true);
}