encode method

List<int> encode(
  1. String s
)

Encode a string to a list of int ids. Unknown chars → 0.

Implementation

List<int> encode(String s) {
  final out = List<int>.filled(s.length, 0);
  for (int i = 0; i < s.length; i++) {
    out[i] = _stoi[s[i]] ?? 0;
  }
  return out;
}