convertToExtended static method

String convertToExtended(
  1. String contents
)

Implementation

static String convertToExtended(String contents) {
  final length = contents.length;
  final extCont = StringBuffer();
  for (int i = 0; i < length; i++) {
    final character = contents.codeUnitAt(i);
    // ($)=a, (%)=b, (/)=c, (+)=d. see Code93Reader.ALPHABET_STRING
    if (character == 0) {
      // NUL: (%)U
      extCont.write('bU');
    } else if (character <= 26) {
      // SOH - SUB: ($)A - ($)Z
      extCont.write('a');
      extCont.writeCharCode(65 /* A */ + character - 1);
    } else if (character <= 31) {
      // ESC - US: (%)A - (%)E
      extCont.write('b');
      extCont.writeCharCode(65 /* A */ + character - 27);
    } else if (character == 32 /*   */ ||
        character == 36 /* $ */ ||
        character == 37 /* % */ ||
        character == 43 /* + */) {
      // space $ % +
      extCont.writeCharCode(character);
    } else if (character <= 44 /* , */) {
      // ! " # & ' ( ) * ,: (/)A - (/)L
      extCont.write('c');
      extCont.writeCharCode(65 /* A */ + character - 33 /* ! */);
    } else if (character <= 57 /* 9 */) {
      extCont.writeCharCode(character);
    } else if (character == 58 /* : */) {
      // :: (/)Z
      extCont.write('cZ');
    } else if (character <= 63 /* ? */) {
      // ; - ?: (%)F - (%)J
      extCont.write('b');
      extCont.writeCharCode(70 /* F */ + character - 59 /* ; */);
    } else if (character == 64 /* @ */) {
      // @: (%)V
      extCont.write('bV');
    } else if (character <= 90 /* Z */) {
      // A - Z
      extCont.writeCharCode(character);
    } else if (character <= 95 /* _ */) {
      // [ - _: (%)K - (%)O
      extCont.write('b');
      extCont.writeCharCode(75 /* K */ + character - 91 /* [ */);
    } else if (character == 96 /* ` */) {
      // `: (%)W
      extCont.write('bW');
    } else if (character <= 122 /* z */) {
      // a - z: (*)A - (*)Z
      extCont.writeCharCode(100 /* d */);
      extCont.writeCharCode(65 /* A */ + character - 97 /* a */);
    } else if (character <= 127) {
      // { - DEL: (%)P - (%)T
      extCont.write('b');
      extCont.writeCharCode(80 /* P */ + character - 123 /* { */);
    } else {
      throw ArgumentError(
        "Requested content contains a non-encodable character: 'chr($character)'",
      );
    }
  }
  return extCont.toString();
}