diff --git a/src/lexer.rs b/src/lexer.rs index c917e52..95d406f 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -41,7 +41,7 @@ pub fn is_numeric_str(input: &str) -> bool { /// Read next characters as a word, otherwise return empty string. /// Returns an empty string if there's leading whitespace. pub fn read_word_plain(chars: &mut Peekable) -> String { - let mut word = "".to_string(); + let mut word = String::new(); while let Some(next_char) = chars.peek() { if is_alphabetic_extended_str(&next_char) { word += chars.next().unwrap(); @@ -63,7 +63,7 @@ pub fn read_word(chars: &mut Peekable) -> String { break; } } - let mut word = "".to_string(); + let mut word = String::new(); while let Some(next_char) = chars.peek() { if is_alphabetic_extended_str(&next_char) { word += chars.next().unwrap(); @@ -177,7 +177,7 @@ pub fn parse_word(tokens: &mut Vec, chars: &mut Peekable, defa "light" => { match read_word(chars).as_str() { "yr" | "yrs" | "year" | "years" => Token::Unit(LightYear), - "sec" | "secs" | "second" | "seconds" => Token::Unit(LightYear), + "sec" | "secs" | "second" | "seconds" => Token::Unit(LightSecond), string => return Err(format!("Invalid string: {}", string)), } } @@ -516,7 +516,7 @@ pub fn lex(input: &str, allow_trailing_operators: bool, default_degree: Unit) -> continue; }, value if is_numeric_str(value) => { - let mut number_string = "".to_string(); + let mut number_string = String::new(); while let Some(number_char) = chars.peek() { if is_numeric_str(number_char) { number_string += number_char;