}
impl States {
- fn next_state(&self, read_symbol: char) -> Result<States, super::Bolt11ParseError> {
+ fn next_state(&self, read_byte: u8) -> Result<States, super::Bolt11ParseError> {
+ let read_symbol = match char::from_u32(read_byte.into()) {
+ Some(symb) if symb.is_ascii() => symb,
+ _ => return Err(super::Bolt11ParseError::MalformedHRP),
+ };
match *self {
States::Start => {
if read_symbol == 'l' {
*range = Some(new_range);
}
- fn step(&mut self, c: char) -> Result<(), super::Bolt11ParseError> {
+ fn step(&mut self, c: u8) -> Result<(), super::Bolt11ParseError> {
let next_state = self.state.next_state(c)?;
match next_state {
States::ParseCurrencyPrefix => {
pub fn parse_hrp(input: &str) -> Result<(&str, &str, &str), super::Bolt11ParseError> {
let mut sm = StateMachine::new();
- for c in input.chars() {
+ for c in input.bytes() {
sm.step(c)?;
}