use crate::models::{LineInfo, SyllableItem};
pub fn standardize_yrc_lyrics(lines: &mut [LineInfo]) {
for line in lines.iter_mut() {
standardize_yrc_lyrics_line(line);
}
}
pub fn standardize_yrc_lyrics_line(line: &mut LineInfo) {
let Some(syllables) = line.syllables_mut() else {
return;
};
while syllables.last().is_some_and(|item| item.text() == " ") {
syllables.pop();
}
let mut i = 0;
while i < syllables.len() {
let text = syllables[i].text();
if text.is_empty() {
syllables.remove(i);
continue;
}
if text == " " {
if i > 0 {
append_text(&mut syllables[i - 1], &text);
}
syllables.remove(i);
continue;
}
if i > 0
&& text.chars().count() <= 2
&& matches!(text.chars().next(), Some(',' | '.' | '?' | '!' | '"'))
{
append_text(&mut syllables[i - 1], &text);
syllables.remove(i);
continue;
}
i += 1;
}
}
fn append_text(item: &mut SyllableItem, text: &str) {
match item {
SyllableItem::Syllable(syllable) => syllable.text.push_str(text),
SyllableItem::Full(full) => {
if let Some(last) = full.sub_items_mut().last_mut() {
last.text.push_str(text);
}
}
}
}