langtool: improve insertion of missing sections (logging, empty line)

This commit is contained in:
Henrik Rydgård 2022-12-12 10:23:27 +01:00
parent c1c5c6cb86
commit 4802e7810b
2 changed files with 10 additions and 1 deletions

View File

@ -111,6 +111,10 @@ impl IniFile {
}
}
// Reached the end for some reason? Add it.
// Also add an empty line to the previous section.
if let Some(last) = self.sections.last_mut() {
last.lines.push("".into());
}
self.sections.push(section.clone());
true
}

View File

@ -47,6 +47,10 @@ fn copy_missing_lines(reference_ini: &IniFile, target_ini: &mut IniFile) -> io::
//target_section.remove_lines_if_not_in(reference_section);
target_section.comment_out_lines_if_not_in(reference_section);
}
} else {
// Note: insert_section_if_missing will copy the entire section,
// no need to loop over the lines here.
println!("Inserted missing section: {}", reference_section.name);
}
}
Ok(())
@ -114,7 +118,8 @@ fn main() {
let root = "../../assets/lang";
let reference_ini_filename = "en_US.ini";
let mut reference_ini = IniFile::parse(&format!("{}/{}", root, reference_ini_filename)).unwrap();
let mut reference_ini =
IniFile::parse(&format!("{}/{}", root, reference_ini_filename)).unwrap();
if filenames.is_empty() {
// Grab them all.