endMode property

Mode 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;
}