endMode property
Mode
get
endMode
Returns Mode.ASCII in case that:
- Mode is EDIFACT and characterLength is less than 4 or the remaining characters can be encoded in at most 2 ASCII bytes.
- Mode is C40, TEXT or X12 and the remaining characters can be encoded in at most 1 ASCII byte. Returns mode in all other cases.
Implementation
Mode get endMode {
if (mode == Mode.edf) {
if (characterLength < 4) {
return Mode.ascii;
}
final lastASCII = getLastASCII(); // see 5.2.8.2 EDIFACT encodation Rules
if (lastASCII > 0 &&
getCodewordsRemaining(cachedTotalSize + lastASCII) <= 2 - lastASCII) {
return Mode.ascii;
}
}
if (mode == Mode.c40 || mode == Mode.text || mode == Mode.x12) {
// see 5.2.5.2 C40 encodation rules and 5.2.7.2 ANSI X12 encodation rules
if (fromPosition + characterLength >= input.length &&
getCodewordsRemaining(cachedTotalSize) == 0) {
return Mode.ascii;
}
final lastASCII = getLastASCII();
if (lastASCII == 1 && getCodewordsRemaining(cachedTotalSize + 1) == 0) {
return Mode.ascii;
}
}
return mode;
}