feat: read from stdin if argument missing
This commit is contained in:
parent
da960610f4
commit
877ae39d23
2 changed files with 14 additions and 3 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -1,7 +1,18 @@
|
|||
use std::env;
|
||||
use std::{
|
||||
env,
|
||||
io::{self, Read},
|
||||
};
|
||||
|
||||
mod parse;
|
||||
|
||||
fn main() {
|
||||
println!("{:.3}", parse::parse(env::args().nth(1).unwrap().as_ref()));
|
||||
let input = match env::args().nth(1) {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
let mut buf = String::new();
|
||||
io::stdin().read_to_string(&mut buf).unwrap();
|
||||
buf
|
||||
}
|
||||
};
|
||||
println!("{:.3}", parse::parse(&input));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ fn nodes_from_str(s: &str) -> Result<Vec<Node>, Error> {
|
|||
let mut nodes = Vec::new();
|
||||
let mut state = ParsingState::default();
|
||||
|
||||
let is_ignored_char = |c: &char| !matches!(c, ' ' | '&');
|
||||
let is_ignored_char = |c: &char| !matches!(c, ' ' | '&' | '\n');
|
||||
|
||||
let filtered_string: String = s.chars().filter(is_ignored_char).collect();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue