1 /// Converts unsigned integers into a string representation with some base.
2 /// Bases up to and including 36 can be used for case-insensitive things.
9 pub const MAX_BASE: usize = 64;
10 pub const ALPHANUMERIC_ONLY: usize = 62;
11 pub const CASE_INSENSITIVE: usize = 36;
13 const BASE_64: &[u8; MAX_BASE as usize] =
14 b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";
17 pub fn push_str(mut n: u128, base: usize, output: &mut String) {
18 debug_assert!(base >= 2 && base <= MAX_BASE);
19 let mut s = [0u8; 128];
22 let base = base as u128;
25 s[index] = BASE_64[(n % base) as usize];
33 s[0..index].reverse();
35 output.push_str(str::from_utf8(&s[0..index]).unwrap());
39 pub fn encode(n: u128, base: usize) -> String {
40 let mut s = String::new();
41 push_str(n, base, &mut s);