From 4802e7810b78f26e7c20c47e816f85a6b14385f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 12 Dec 2022 10:23:27 +0100 Subject: [PATCH] langtool: improve insertion of missing sections (logging, empty line) --- Tools/langtool/src/inifile.rs | 4 ++++ Tools/langtool/src/main.rs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Tools/langtool/src/inifile.rs b/Tools/langtool/src/inifile.rs index ac109af0f7..c70f4636ec 100644 --- a/Tools/langtool/src/inifile.rs +++ b/Tools/langtool/src/inifile.rs @@ -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 } diff --git a/Tools/langtool/src/main.rs b/Tools/langtool/src/main.rs index 7b59706822..99107fff3a 100644 --- a/Tools/langtool/src/main.rs +++ b/Tools/langtool/src/main.rs @@ -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.