complex files

This commit is contained in:
breel
2026-03-11 21:29:04 -06:00
parent cd9c34cb3e
commit faca56e9df
4 changed files with 42 additions and 9 deletions

View File

@@ -11,14 +11,30 @@ fn from_string(s: String) -> String {
reader
.read_to_string(&mut content)
.expect(format!("failed to read {}", s).as_ref());
content.split_whitespace().collect::<Vec<_>>().join(" ")
content
.split("\n")
.map(|x| x.split_whitespace().collect::<Vec<_>>().join(" "))
.collect::<Vec<_>>()
.join("\n")
}
Err(_) => s,
}
}
fn parse(s: String) -> Vec<String> {
vec![s]
let mut channels = vec![];
let lines = s.split("\n").collect::<Vec<_>>();
let mut j = 0;
for i in 0..lines.len() {
while channels.len() <= j {
channels.push("".to_string());
}
match lines[i] {
"" => { j = 0; },
_ => channels[{ let tmp = j; j += 1; tmp }] += &(" ".to_string() + lines[i]),
};
}
channels.iter().map(|x| x.split_whitespace().collect::<Vec<_>>().join(" ")).collect()
}
#[cfg(test)]
@@ -41,7 +57,23 @@ mod test {
fn test_two_channels_one_bar() {
assert_eq!(
super::new("src/testdata/two_channels_one_bar.txt")[0],
"a b c".to_string()
"2a 2b 2c".to_string()
);
assert_eq!(
super::new("src/testdata/two_channels_one_bar.txt")[1],
". a5 . b5 . c5".to_string()
);
}
#[test]
fn test_two_channels_two_bars() {
assert_eq!(
super::new("src/testdata/two_channels_two_bars.txt")[0],
"a b c d e f".to_string()
);
assert_eq!(
super::new("src/testdata/two_channels_two_bars.txt")[1],
"2a 2b 2c 2d 2e 2f".to_string()
);
}
}

View File

@@ -92,10 +92,6 @@ impl Seq {
changed = true;
}
let tone = self._pop();
eprintln!(
" popped ({:?}, {}): had_more={}, beats={:?} eof={} from {}",
tone, changed, self.had_more, self.beats, self.eof, eof_before,
);
(tone, changed)
}

View File

@@ -1,2 +1,2 @@
a b c
a5 b5 c5
2a 2b 2c
. a5 . b5 . c5

View File

@@ -0,0 +1,5 @@
a b c
2a 2b 2c
d e f
2d 2e 2f