Browse Source

refactoring: move tokenization to own function

main
fdai7381 2 years ago
parent
commit
63a2375bfa
  1. 11
      src/parse.rs

11
src/parse.rs

@ -1,9 +1,16 @@
pub fn parse_line(line: &str) -> (&str, Vec<&str>) {
let tokens = line.trim().split(' ').collect::<Vec<&str>>();
let mut args: Vec<&str> = Vec::new();
let tokens = tokenize(line);
let command = tokens[0];
let mut args: Vec<&str> = Vec::new();
if tokens.len() > 1 {
args = tokens[1..].to_vec();
}
(command, args)
}
fn tokenize(line: &str) -> Vec<&str> {
line.trim().split(' ').collect::<Vec<&str>>()
}
Loading…
Cancel
Save