encode method

String encode (
  1. dynamic income
)

income String or List

Implementation

static String encode(dynamic income) {
  final characters = <String>[];
  final List<int> data = (income is String) ? income.codeUnits : income;
  int i;
  int index;

  for (i = 0; i + 3 <= data.length; i += 3) {
    var value = 0;
    value |= data[i + 2];
    value |= data[i + 1] << 8;
    value |= data[i] << 16;
    for (var j = 0; j < 4; j++) {
      index = (value >> ((3 - j) * 6)) & ((1 << 6) - 1);
      characters.add(_encodingTable[index]);
    }
  }
  // Remainders.
  if (i + 2 == data.length) {
    var value = 0;
    value |= data[i + 1] << 8;
    value |= data[i] << 16;
    for (var j = 0; j < 3; j++) {
      index = (value >> ((3 - j) * 6)) & ((1 << 6) - 1);
      characters.add(_encodingTable[index]);
    }
    characters.add('=');
  } else if (i + 1 == data.length) {
    var value = 0;
    value |= data[i] << 16;
    for (var j = 0; j < 2; j++) {
      index = (value >> ((3 - j) * 6)) & ((1 << 6) - 1);
      characters.add(_encodingTable[index]);
    }
    characters..add('=')..add('=');
  }

  final output = StringBuffer();
  for (i = 0; i < characters.length; i++) {
//      if (i > 0 && i % 76 == 0) {
//        output.write("\r\n");
//      }
    output.write(characters[i]);
  }
  return output.toString();
}