From 08a18531f04a395a556444ecba149356eeddf9d7 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sun, 6 Dec 2020 01:01:19 -0800 Subject: Grouping primitive in the library --- lib/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/src') diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 4913cbb..0272485 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -36,6 +36,25 @@ pub fn read_lines_file(filename: &str) -> Result> { Ok(input) } +pub fn group_lines_by_blanks(lines: Vec) -> Result>> { + let mut all_groups = Vec::new(); + let mut current_group = Vec::new(); + + for line in lines { + if line.trim().len() == 0 { + all_groups.push(current_group); + current_group = Vec::new(); + } else { + current_group.push(line); + } + } + + if current_group.len() > 0 { + all_groups.push(current_group); + } + + Ok(all_groups) +} pub fn read_int_file(filename: &str) -> Result> { let file = File::open(filename)?; -- cgit 1.4.1