numToString128 function
Encode a number into a string
Implementation
String numToString128(int value) {
/// ascii code:
/// 32: space /// 33: ! (first character except space)
/// 48: 0
/// 65: A /// 90: Z
/// 97: a /// 122
// const int charBase = 33;
//'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"#%&()*+,-./:;<=>?@[\\]^_`{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ';
const charBase =
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"#%&()*+,-./:;<=>?@[]^_`{|}~€‚ƒ„…†‡•–™¢£¤¥©®±µ¶º»¼½¾ÀÆÇÈÌÐÑÒ×ØÙÝÞßæç';
assert(charBase.length >= 128, 'numToString128 const charBase length < 128');
if (value == 0) {
return '#0';
}
var res = '#';
assert(value >= 0, 'numToString should provide positive value.');
// if (value < 0) {
// value = -value;
// res += '-';
// }
final list = <String>[];
while (value > 0) {
/// 64 group
// final remainder = value & 63;
// value = value >> 6; // == divide by 64
/// 128 group
final remainder = value & 127;
value = value >> 7; // == divide by 128
/// num to char, base on charBase
//final char = String.fromCharCode(remainder + charBase);
final char = charBase[remainder];
list.add(char);
}
for (var i = list.length - 1; i >= 0; i--) {
res += list[i];
}
return res;
}