addEdges method

void addEdges(
  1. Version version,
  2. List<List<List<Edge?>>> edges,
  3. int from,
  4. Edge? previous,
)

Implementation

void addEdges(
  Version version,
  List<List<List<Edge?>>> edges,
  int from,
  Edge? previous,
) {
  int start = 0;
  int end = encoders.length;
  final priorityEncoderIndex = encoders.priorityEncoderIndex;
  if (priorityEncoderIndex >= 0 &&
      encoders.canEncode(
        stringToEncode.codeUnitAt(from),
        priorityEncoderIndex,
      )) {
    start = priorityEncoderIndex;
    end = priorityEncoderIndex + 1;
  }

  for (int i = start; i < end; i++) {
    if (encoders.canEncode(stringToEncode.codeUnitAt(from), i)) {
      addEdge(
        edges,
        from,
        Edge(Mode.byte, from, i, 1, previous, version, this),
      );
    }
  }

  if (canEncode(Mode.kanji, stringToEncode.codeUnitAt(from))) {
    addEdge(
      edges,
      from,
      Edge(Mode.kanji, from, 0, 1, previous, version, this),
    );
  }

  final inputLength = stringToEncode.length;
  if (canEncode(Mode.alphanumeric, stringToEncode.codeUnitAt(from))) {
    addEdge(
      edges,
      from,
      Edge(
        Mode.alphanumeric,
        from,
        0,
        from + 1 >= inputLength ||
                !canEncode(
                  Mode.alphanumeric,
                  stringToEncode.codeUnitAt(from + 1),
                )
            ? 1
            : 2,
        previous,
        version,
        this,
      ),
    );
  }

  if (canEncode(Mode.numeric, stringToEncode.codeUnitAt(from))) {
    addEdge(
      edges,
      from,
      Edge(
        Mode.numeric,
        from,
        0,
        from + 1 >= inputLength ||
                !canEncode(
                  Mode.numeric,
                  stringToEncode.codeUnitAt(from + 1),
                )
            ? 1
            : from + 2 >= inputLength ||
                    !canEncode(
                      Mode.numeric,
                      stringToEncode.codeUnitAt(from + 2),
                    )
                ? 2
                : 3,
        previous,
        version,
        this,
      ),
    );
  }
}