parse all strings and strip comments whether file or not
This commit is contained in:
39
src/play.rs
39
src/play.rs
@@ -12,16 +12,31 @@ fn from_string(s: String) -> String {
|
||||
.read_to_string(&mut content)
|
||||
.expect(format!("failed to read {}", s).as_ref());
|
||||
content
|
||||
.split("\n")
|
||||
.map(|x| x.split_whitespace().collect::<Vec<_>>().join(" "))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
Err(_) => s,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(s: String) -> Vec<String> {
|
||||
let s = s
|
||||
.split("\n")
|
||||
.filter(|x: &&str| !x // doesnt start with #
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>()
|
||||
.join("")
|
||||
.starts_with("#")
|
||||
)
|
||||
.map(|x| x
|
||||
.split("#")
|
||||
.take(1) // drop after #
|
||||
.collect::<Vec<_>>()
|
||||
.join("")
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let mut channels = vec![];
|
||||
let lines = s.split("\n").collect::<Vec<_>>();
|
||||
let mut j = 0;
|
||||
@@ -76,4 +91,20 @@ mod test {
|
||||
"2a 2b 2c 2d 2e 2f".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_comment_lines() {
|
||||
assert_eq!(
|
||||
super::new("# hello\n # world\na b c")[0],
|
||||
"a b c".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_comment_trailer() {
|
||||
assert_eq!(
|
||||
super::new("a b c # hello world")[0],
|
||||
"a b c".to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
9
src/testdata/chord_progressions.txt
vendored
Normal file
9
src/testdata/chord_progressions.txt
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
CM0 CM3 CM4 CM0
|
||||
|
||||
.
|
||||
|
||||
CM1 CM4 CM0
|
||||
|
||||
.
|
||||
|
||||
CM0 CM4 CM5 CM3
|
||||
7
src/testdata/sandbox.txt
vendored
7
src/testdata/sandbox.txt
vendored
@@ -1,5 +1,4 @@
|
||||
. a . b . c
|
||||
2a2 2b2 2c2
|
||||
CM0 CM3 CM4 CM0
|
||||
|
||||
. d . e . f
|
||||
2d2 2e2 2f2
|
||||
#CM1 CM4 CM0
|
||||
#CM0 CM4 CM5 CM3
|
||||
|
||||
Reference in New Issue
Block a user