From fcf6b3cd54a8be24fae8bd2923c2b2482d564472 Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Tue, 17 Jan 2023 09:40:38 +0100 Subject: [PATCH] refactoring: move tokenization to own function --- src/parse.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/parse.rs b/src/parse.rs index cda4f05..ceef7e8 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,9 +1,16 @@ pub fn parse_line(line: &str) -> (&str, Vec<&str>) { - let tokens = line.trim().split(' ').collect::>(); - 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::>() +} \ No newline at end of file