From 5d08f59083f61d6af22c1f18163979c3405fa807 Mon Sep 17 00:00:00 2001 From: Kasper Date: Thu, 8 Apr 2021 00:45:52 +0200 Subject: [PATCH] Fix panic when input is empty string --- README.md | 3 --- src/lexer.rs | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a580c6b..95f52a5 100644 --- a/README.md +++ b/README.md @@ -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()`. -## 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 ### Get started diff --git a/src/lexer.rs b/src/lexer.rs index a11dba0..f6c6f5d 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -21,6 +21,10 @@ 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 { + if input == "" { + return Err(format!("Input was empty")) + } + let mut input = input.replace(",", ""); // ignore commas input = input.to_lowercase();