Fixed suggested by @djmattyg007

This commit is contained in:
Kasper 2021-07-06 17:59:07 +02:00
parent e30810c997
commit 1973c7281f

View File

@ -13,13 +13,6 @@ use crate::units::Unit;
use crate::units::Unit::*; use crate::units::Unit::*;
use unicode_segmentation::{Graphemes, UnicodeSegmentation}; use unicode_segmentation::{Graphemes, UnicodeSegmentation};
pub const fn is_alphabetic_extended(input: &char) -> bool {
match input {
'A'..='Z' | 'a'..='z' | 'Ω' | 'Ω' | 'µ' | 'μ' | 'π' => true,
_ => false,
}
}
pub fn is_alphabetic_extended_str(input: &str) -> bool { pub fn is_alphabetic_extended_str(input: &str) -> bool {
let x = match input { let x = match input {
value if value.chars().all(|c| ('a'..='z').contains(&c)) => true, value if value.chars().all(|c| ('a'..='z').contains(&c)) => true,
@ -61,7 +54,7 @@ pub fn read_word(first_c: &str, lexer: &mut Lexer) -> String {
// skip whitespace // skip whitespace
while let Some(current_char) = chars.peek() { while let Some(current_char) = chars.peek() {
if current_char.trim().is_empty() { if current_char.trim().is_empty() {
chars.next(); chars.next();
} else { } else {
break; break;
} }
@ -316,7 +309,7 @@ pub fn parse_word(word: &str, lexer: &mut Lexer) -> Result<(), String> {
"pt" | "pint" | "pints" => Token::Unit(Pint), "pt" | "pint" | "pints" => Token::Unit(Pint),
"qt" | "quart" | "quarts" => Token::Unit(Quart), "qt" | "quart" | "quarts" => Token::Unit(Quart),
"gal" | "gallon" | "gallons" => Token::Unit(Gallon), "gal" | "gallon" | "gallons" => Token::Unit(Gallon),
"bbl" | "oil barrel" | "oil barrels" => Token::Unit(OilBarrel), "bbl" => Token::Unit(OilBarrel),
"oil" => { "oil" => {
match read_word("", lexer).as_str() { match read_word("", lexer).as_str() {
"barrel" | "barrels" => Token::Unit(OilBarrel), "barrel" | "barrels" => Token::Unit(OilBarrel),
@ -596,7 +589,6 @@ pub struct Lexer<'a> {
pub fn lex(input: &str, remove_trailing_operator: bool, default_degree: Unit) -> Result<Vec<Token>, String> { pub fn lex(input: &str, remove_trailing_operator: bool, default_degree: Unit) -> Result<Vec<Token>, String> {
let mut input = input.replace(",", ""); // ignore commas let mut input = input.replace(",", ""); // ignore commas
input = input.to_lowercase(); input = input.to_lowercase();
if remove_trailing_operator { if remove_trailing_operator {
@ -678,7 +670,7 @@ pub fn lex(input: &str, remove_trailing_operator: bool, default_degree: Unit) ->
}, },
} }
}, },
// decide if " is inch or inch of mercury // decide if " is 'inch' or 'inch of mercury'
Token::LexerKeyword(DoubleQuotes) => { Token::LexerKeyword(DoubleQuotes) => {
match tokens.get(token_index + 1) { match tokens.get(token_index + 1) {
Some(Token::LexerKeyword(Hg)) => { Some(Token::LexerKeyword(Hg)) => {