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,
      ),
    );
  }
}