Fix panic when input is empty string
This commit is contained in:
parent
c59918b080
commit
5d08f59083
@ -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
|
||||||
|
|||||||
@ -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();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user