Fix panic when input contains only whitespace and/or commas

This commit is contained in:
Kasper 2021-04-21 21:06:02 +02:00
parent d9a08b0b85
commit 6585366b0d

View File

@ -21,10 +21,6 @@ pub const fn is_alphabetic_extended(input: &char) -> bool {
/// Lex an input string and return a [`TokenVector`]
pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> Result<TokenVector, String> {
if input == "" {
return Err(format!("Input was empty"))
}
let mut input = input.replace(",", ""); // ignore commas
input = input.to_lowercase();
@ -399,8 +395,6 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
}
}
}
},
'.' | '0'..='9' => {
let start_index = byte_index;
@ -455,6 +449,10 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) ->
}
}
if tokens.len() == 0 {
return Err(format!("Input was empty"))
}
let mut token_index = 0;
loop {
match tokens[token_index] {