toNumber static method

int toNumber(
  1. String value
)

toNumber converts a String defined in the LayrzNumber system to a int number.

Implementation

static int toNumber(String value) {
  assert(value.isNotEmpty, 'The value must not be empty.');

  int result = 0;
  int baseSystem = equivalences.length;
  List<String> chars = value.toUpperCase().split('');

  for (int i = 0; i < chars.length; i++) {
    int exp = chars.length - (i + 1);
    result += (equivalences.indexOf(chars[i]) * pow(baseSystem, exp)).toInt();
  }

  return result;
}