Skip to content

Commit

Permalink
langtool: Run fmt, remove wrong comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Sep 3, 2022
1 parent 759dc25 commit af54ff7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Tools/langtool/src/inifile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};
use std::io::{self, Write};
use std::fs::File;
use std::io::{self, Write};
use std::path::{Path, PathBuf};

use crate::section::Section;

Expand Down
42 changes: 22 additions & 20 deletions Tools/langtool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ enum Command {
CopyMissingLines {},
CommentUnknownLines {},
RemoveUnknownLines {},
MoveKey { old: String, new: String, key: String },
RemoveKey { section: String, key: String },
MoveKey {
old: String,
new: String,
key: String,
},
RemoveKey {
section: String,
key: String,
},
}

fn copy_missing_lines(reference_ini: &IniFile, target_ini: &mut IniFile) -> io::Result<()> {
// Insert any missing full sections.
for reference_section in &reference_ini.sections {
// Insert any missing full sections.
if !target_ini.insert_section_if_missing(reference_section) {
if let Some(target_section) = target_ini.get_section_mut(&reference_section.name) {
for line in &reference_section.lines {
Expand All @@ -44,7 +51,6 @@ fn deal_with_unknown_lines(
target_ini: &mut IniFile,
remove: bool,
) -> io::Result<()> {
// Insert any missing full sections.
for reference_section in &reference_ini.sections {
if let Some(target_section) = target_ini.get_section_mut(&reference_section.name) {
if remove {
Expand All @@ -57,13 +63,7 @@ fn deal_with_unknown_lines(
Ok(())
}

fn move_key(
target_ini: &mut IniFile,
old: &str,
new: &str,
key: &str,
) -> io::Result<()> {
// Insert any missing full sections.
fn move_key(target_ini: &mut IniFile, old: &str, new: &str, key: &str) -> io::Result<()> {
if let Some(old_section) = target_ini.get_section_mut(old) {
if let Some(line) = old_section.remove_line(key) {
if let Some(new_section) = target_ini.get_section_mut(new) {
Expand All @@ -80,12 +80,7 @@ fn move_key(
Ok(())
}

fn remove_key(
target_ini: &mut IniFile,
section: &str,
key: &str,
) -> io::Result<()> {
// Insert any missing full sections.
fn remove_key(target_ini: &mut IniFile, section: &str, key: &str) -> io::Result<()> {
if let Some(old_section) = target_ini.get_section_mut(section) {
let _ = old_section.remove_line(key);
} else {
Expand Down Expand Up @@ -142,10 +137,17 @@ fn main() {
Command::RemoveUnknownLines {} => {
deal_with_unknown_lines(&reference_ini, &mut target_ini, true).unwrap();
}
Command::MoveKey { ref old, ref new,ref key, } => {
move_key(&mut target_ini, &old, &new, &key).unwrap();
Command::MoveKey {
ref old,
ref new,
ref key,
} => {
move_key(&mut target_ini, &old, &new, &key).unwrap();
}
Command::RemoveKey { ref section, ref key } => {
Command::RemoveKey {
ref section,
ref key,
} => {
remove_key(&mut target_ini, section, key).unwrap();
}
}
Expand Down

0 comments on commit af54ff7

Please sign in to comment.