Base62 would be more useful (and encompass base60.) For bases upto 36 one can be case insensitive. Beyond, one must decide whether lower- or uppercase letters come first. Alas there is no universal concensus on that. Wikipedia gives them in Ascii order. But most discussions around major languages and the doc for from_str_radix
shows lower- before uppercase letters. So I had hoped it would use that order beyond 36. Instead (like many languages) it falls over after 36. If this flies, Rust would need to decide on an order, maybe inspired by what the mentioned doc implies! That would then be the default for from_str_radix
(with maybe a companion function for the opposite order.) That’s what Shell does:
$ declare -i a=36#a b=36#A c=37#a d=37#A e=64#a f=64#A; echo 36: $a $b / 37: $c $d / 64: $e $f
36: 10 10 / 37: 10 36 / 64: 10 36
Base64 would of course be great. Now we have the mess that (unlike the name suggests) it mostly uses a completely different order than hex, base36 and base62. Why are some standards hell bent on making life hard? So these should certainly not have a prefix of 0r64r…
(which should be 0-9a-zA-Z…), maybe 0s…
for internet base Sixty four (A-Za-z0-9….)
In Thor’s day and age and upto the 15th century, base 12 was somewhat used. With 52 letters that would have given us the necessary 64 digits cleanly. But now, being two digits short, we have various sets of two random extra characters (['+', '/']
, ['+', ',']
, ['@', '_']
or ['-', '_']
). All of these variants collide with special characters somewhere. When generating, one must choose a variant. But parsers should ideally accept them all, i.e. three different input digits each for 62 and 63.
To have these annoying digits in a Rust number, one must mask them. This could be 0-based 0r64r1\+2\/3 == 0r64r"1+2/3" == 33042371
or internet A-based 0s1\+2\/3 == 0s"1+2/3" == 905670647
(mathematically transitive equals.)
Or we create yet another variant, choosing the two extra digits from characters that won’t collide with anything, i.e. two of ['#', '$', '@']
, where Shell precedent suggests '@' == 62
. However we can’t have '_' == 63
as underscore is ignored in numbers. Instead we could have 0r64r1@2$3 == 33042371
and 0s1@2$3 == 905670647
.