Fix panic when input is empty string

This commit is contained in:
Kasper 2021-04-08 00:45:52 +02:00
parent c59918b080
commit 5d08f59083
2 changed files with 4 additions and 3 deletions

View File

@ -91,9 +91,6 @@ It's pretty fast and scales well. In my case, it usually runs in under 0.1ms. Th
To see how fast it is, you can pass the `--debug` flag in CLI, or the `debug` argument to `eval()`. To see how fast it is, you can pass the `--debug` flag in CLI, or the `debug` argument to `eval()`.
## Errors
cpc returns `Result`s with basic strings as errors. Just to be safe, you may want to handle panics (You can do that using `std::panic::catch_unwind`).
## Dev Instructions ## Dev Instructions
### Get started ### Get started

View File

@ -21,6 +21,10 @@ pub const fn is_alphabetic_extended(input: &char) -> bool {
/// Lex an input string and return a [`TokenVector`] /// Lex an input string and return a [`TokenVector`]
pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> Result<TokenVector, String> { 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 let mut input = input.replace(",", ""); // ignore commas
input = input.to_lowercase(); input = input.to_lowercase();