decode method

String decode (String data)

Implementation

static String decode(String data) {
  int char;
  int charCount = 0;
  int padCount = 0;
  final List<int> result = <int>[];
  int value = 0;

  for (int i = 0; i < data.length; i++) {
    char = data.codeUnitAt(i);
    if (65 <= char && char <= 90) {
      // "A" - "Z".
      value = (value << 6) | char - 65;
      charCount++;
    } else if (97 <= char && char <= 122) {
      // "a" - "z".
      value = (value << 6) | char - 97 + 26;
      charCount++;
    } else if (48 <= char && char <= 57) {
      // "0" - "9".
      value = (value << 6) | char - 48 + 52;
      charCount++;
    } else if (char == 43) {
      // "+".
      value = (value << 6) | 62;
      charCount++;
    } else if (char == 47) {
      // "/".
      value = (value << 6) | 63;
      charCount++;
    } else if (char == 61) {
      // "=".
      value = value << 6;
      charCount++;
      padCount++;
    }
    if (charCount == 4) {
      result.add((value & 0xFF0000) >> 16);
      if (padCount < 2) {
        result.add((value & 0xFF00) >> 8);
      }
      if (padCount == 0) {
        result.add(value & 0xFF);
      }
      charCount = 0;
      value = 0;
    }
  }

  return String.fromCharCodes(result);
}