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.
8 pub const MAX_BASE: usize = 64;
9 pub const ALPHANUMERIC_ONLY: usize = 62;
10 pub const CASE_INSENSITIVE: usize = 36;
12 const BASE_64: &[u8; MAX_BASE as usize] =
13 b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";
16 pub fn push_str(mut n: u128, base: usize, output: &mut String) {
17 debug_assert!(base >= 2 && base <= MAX_BASE);
18 let mut s = [0u8; 128];
21 let base = base as u128;
24 s[index] = BASE_64[(n % base) as usize];
32 s[0..index].reverse();
34 output.push_str(str::from_utf8(&s[0..index]).unwrap());
38 pub fn encode(n: u128, base: usize) -> String {
39 let mut s = String::new();
40 push_str(n, base, &mut s);