Line data Source code
1 : class EncodingUtils { 2 0 : static String getChars(Encoding encoding) { 3 0 : return _encodeMap[encoding]!; 4 : } 5 : 6 0 : static Map<String, int> getDecodeMap(Encoding encoding) { 7 0 : var map = _decodeMap[encoding]; 8 : if (map != null) { 9 : return map; 10 : } else { 11 0 : var chars = _encodeMap[encoding]!; 12 : // ignore: omit_local_variable_types 13 0 : Map<String, int> map = {}; 14 0 : for (var i = 0; i < 32; i++) { 15 0 : map[chars[i]] = i; 16 : } 17 0 : _decodeMap[encoding] = map; 18 : return map; 19 : } 20 : } 21 : 22 0 : static RegExp getRegex(Encoding encoding) { 23 0 : return _regexMap[encoding]!; 24 : } 25 : 26 0 : static bool getPadded(Encoding encoding) { 27 0 : return _padded[encoding]!; 28 : } 29 : 30 0 : static final _regexMap = { 31 0 : Encoding.standardRFC4648: RegExp(r'^[A-Z2-7=]+$'), 32 0 : Encoding.nonStandardRFC4648Lower: RegExp(r'^[a-z2-7=]+$'), 33 0 : Encoding.base32Hex: RegExp(r'^[0-9A-V=]+$'), 34 0 : Encoding.crockford: RegExp(r'^[0123456789ABCDEFGHJKMNPQRSTVWXYZ-]+$'), 35 0 : Encoding.zbase32: RegExp(r'^[ybndrfg8ejkmcpqxot1uwisza345h769]+$'), 36 0 : Encoding.geohash: RegExp(r'^[0123456789bcdefghjkmnpqrstuvwxyz=]+$') 37 : }; 38 0 : static final _encodeMap = { 39 : Encoding.standardRFC4648: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', 40 : Encoding.nonStandardRFC4648Lower: 'abcdefghijklmnopqrstuvwxyz234567', 41 : Encoding.base32Hex: '0123456789ABCDEFGHIJKLMNOPQRSTUV', 42 : Encoding.crockford: '0123456789ABCDEFGHJKMNPQRSTVWXYZ', 43 : Encoding.zbase32: 'ybndrfg8ejkmcpqxot1uwisza345h769', 44 : Encoding.geohash: '0123456789bcdefghjkmnpqrstuvwxyz' 45 : }; 46 : 47 0 : static final Map<Encoding, Map<String, int>> _decodeMap = {}; 48 : 49 0 : static final _padded = {Encoding.standardRFC4648: true, Encoding.nonStandardRFC4648Lower: true, Encoding.base32Hex: true, Encoding.crockford: false, Encoding.zbase32: false, Encoding.geohash: true}; 50 : } 51 : 52 : enum Encoding { standardRFC4648, base32Hex, crockford, zbase32, geohash, nonStandardRFC4648Lower }