diff options
author | Irene Knapp <ireneista@gmail.com> | 2020-12-06 01:01:19 -0800 |
---|---|---|
committer | Irene Knapp <ireneista@gmail.com> | 2020-12-06 01:01:19 -0800 |
commit | 08a18531f04a395a556444ecba149356eeddf9d7 (patch) | |
tree | 0b46438741947d7971fc62e139c580a8ed61842d /lib | |
parent | 6a3b945f0a4cdf2a27adf915e8a237077fef9f30 (diff) |
Grouping primitive in the library
Diffstat (limited to 'lib')
-rw-r--r-- | lib/src/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
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<Vec<String>> { Ok(input) } +pub fn group_lines_by_blanks(lines: Vec<String>) -> Result<Vec<Vec<String>>> { + 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<Vec<i64>> { let file = File::open(filename)?; |