use crate::{
codec::alphabet::{Alphabet, DecodeStep, EncodeStep},
misc::int_conv::u8i16,
};
use core::range::RangeInclusive;
#[derive(Debug)]
pub(crate) struct Url;
impl Alphabet for Url {
const BASE: u8 = b'A';
const DECODER: &'static [DecodeStep] = DECODER;
const ENCODER: &'static [EncodeStep] = ENCODER;
const PAD: Option<u8> = Some(b'=');
}
#[derive(Debug)]
pub(crate) struct UrlNoPad;
impl Alphabet for UrlNoPad {
const BASE: u8 = b'A';
const DECODER: &'static [DecodeStep] = DECODER;
const ENCODER: &'static [EncodeStep] = ENCODER;
const PAD: Option<u8> = None;
}
const DECODER: &[DecodeStep] = &[
DecodeStep::Range(RangeInclusive { start: b'A', last: b'Z' }, -64),
DecodeStep::Range(RangeInclusive { start: b'a', last: b'z' }, -70),
DecodeStep::Range(RangeInclusive { start: b'0', last: b'9' }, 5),
DecodeStep::Eq(b'-', 63),
DecodeStep::Eq(b'_', 64),
];
const ENCODER: &[EncodeStep] = &[
EncodeStep::Diff(25, 6),
EncodeStep::Diff(51, -75),
EncodeStep::Diff(61, -(u8i16(b'-') - 0x20)),
EncodeStep::Diff(62, u8i16(b'_') - u8i16(b'-') - 1),
];