charToZChar static method

int charToZChar(
  1. String c
)

Converts char c into an equivalent Z-Character.

Implementation

static int charToZChar(String c) {
  if (c.isEmpty || c.length != 1) {
    throw GameException('String must be length of 1.  Found ${c.length} in $c.');
  }

  if (c == '\t') {
    return 9;
  } else if (c == '\n') {
    return 13;
  } else {
    final cc = c.codeUnitAt(0);
    if (cc >= 32 && cc <= 126) {
      return cc;
    } else if (cc >= 155 && cc <= 223) {
      return cc;
    }
  }

  throw GameException('Could not convert from char to ZChar.');
}