addEdges static method
Implementation
static void addEdges(
Input input,
List<List<Edge?>> edges,
int from,
Edge? previous,
) {
if (input.isECI(from)) {
addEdge(edges, Edge(input, Mode.ascii, from, 1, previous));
return;
}
final ch = input.charAt(from);
if (previous == null || previous.endMode != Mode.edf) {
//not possible to unlatch a full EDF edge to something
//else
if (HighLevelEncoder.isDigit(ch) &&
input.haveNCharacters(from, 2) &&
HighLevelEncoder.isDigit(input.charAt(from + 1))) {
// two digits ASCII encoded
addEdge(edges, Edge(input, Mode.ascii, from, 2, previous));
} else {
// one ASCII encoded character or an extended character via Upper Shift
addEdge(edges, Edge(input, Mode.ascii, from, 1, previous));
}
final modes = [Mode.c40, Mode.text];
for (Mode mode in modes) {
final characterLength = [0];
if (getNumberOfC40Words(
input,
from,
mode == Mode.c40,
characterLength,
) >
0) {
addEdge(edges, Edge(input, mode, from, characterLength[0], previous));
}
}
if (input.haveNCharacters(from, 3) &&
HighLevelEncoder.isNativeX12(input.charAt(from)) &&
HighLevelEncoder.isNativeX12(input.charAt(from + 1)) &&
HighLevelEncoder.isNativeX12(input.charAt(from + 2))) {
addEdge(edges, Edge(input, Mode.x12, from, 3, previous));
}
addEdge(edges, Edge(input, Mode.b256, from, 1, previous));
}
//We create 4 EDF edges, with 1, 2 3 or 4 characters length. The fourth normally doesn't have a latch to ASCII
//unless it is 2 characters away from the end of the input.
int i;
for (i = 0; i < 3; i++) {
final pos = from + i;
if (input.haveNCharacters(pos, 1) &&
HighLevelEncoder.isNativeEDIFACT(input.charAt(pos))) {
addEdge(edges, Edge(input, Mode.edf, from, i + 1, previous));
} else {
break;
}
}
if (i == 3 &&
input.haveNCharacters(from, 4) &&
HighLevelEncoder.isNativeEDIFACT(input.charAt(from + 3))) {
addEdge(edges, Edge(input, Mode.edf, from, 4, previous));
}
}