Compare commits
1 commit
c2cf27e601
...
00ea19c59b
Author | SHA1 | Date | |
---|---|---|---|
00ea19c59b |
1 changed files with 4 additions and 4 deletions
|
@ -76,8 +76,8 @@ impl<'a> BagRules<'a> {
|
||||||
|
|
||||||
fn parse_bag_rule_line(line: &'a str) -> (Bag<'a>, Vec<Bag<'a>>) {
|
fn parse_bag_rule_line(line: &'a str) -> (Bag<'a>, Vec<Bag<'a>>) {
|
||||||
let mut splitted = line.splitn(2, " bags contain ");
|
let mut splitted = line.splitn(2, " bags contain ");
|
||||||
let key = splitted.next().unwrap();
|
let key = splitted.next().expect("invalid bag rule line: missing key");
|
||||||
let values = splitted.next().unwrap();
|
let values = splitted.next().expect("invalid bag rule line: missing value");
|
||||||
|
|
||||||
if values == "no other bags." {
|
if values == "no other bags." {
|
||||||
return (key, vec![]);
|
return (key, vec![]);
|
||||||
|
@ -85,7 +85,7 @@ impl<'a> BagRules<'a> {
|
||||||
|
|
||||||
let values: Vec<&str> = values
|
let values: Vec<&str> = values
|
||||||
.strip_suffix(".")
|
.strip_suffix(".")
|
||||||
.unwrap()
|
.expect("invalid bag rule line: not terminated with `.`")
|
||||||
.split(',')
|
.split(',')
|
||||||
.flat_map(BagRules::parse_bag_content)
|
.flat_map(BagRules::parse_bag_content)
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -99,7 +99,7 @@ impl<'a> BagRules<'a> {
|
||||||
let bag = bag
|
let bag = bag
|
||||||
.strip_suffix(" bags")
|
.strip_suffix(" bags")
|
||||||
.or(bag.strip_suffix(" bag"))
|
.or(bag.strip_suffix(" bag"))
|
||||||
.unwrap();
|
.expect("invalid bag content: no bag(s) suffix");
|
||||||
let count = count.trim().parse::<usize>().unwrap();
|
let count = count.trim().parse::<usize>().unwrap();
|
||||||
vec![bag.trim(); count]
|
vec![bag.trim(); count]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue