diff --git a/src/main.rs b/src/main.rs index 7c990d1..50d60d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -115,13 +115,13 @@ fn parse_file(file: impl io::Read) -> Result<json::JsonValue, Box<std::error::Er // ignore empty lines let line_str = String::from(line.unwrap().trim()); let line_s = &line_str; - if 0 == line_s.len() { + if line_s.is_empty() { continue; } // find keywords match patterns .iter() - .find(|&&pattern| line_s.starts_with(pattern) && line_s.ends_with(":")) + .find(|&&pattern| line_s.starts_with(pattern) && line_s.ends_with(':')) { Some(pattern) => { use KeywordType::*; @@ -129,14 +129,11 @@ fn parse_file(file: impl io::Read) -> Result<json::JsonValue, Box<std::error::Er ctx.last_keyword_type = ctx.cur_keyword_type; ctx.last_tag = ctx.cur_tag.clone(); ctx.cur_keyword_type = Some(keyword_type(&pattern)); - ctx.cur_tag = pattern.replace(" ", "").replace(":", ""); + ctx.cur_tag = pattern.replace(' ', "").replace(':', ""); // remember question id - match ctx.cur_keyword_type { - Some(QuestionStart) => { - ctx.cur_question_pre["id"] = line_s.replace(":", "").as_str().into(); - } - _ => (), + if let Some(QuestionStart) = ctx.cur_keyword_type { + ctx.cur_question_pre["id"] = line_s.replace(':', "").as_str().into(); }; // apply accumulated content when new keyword found @@ -222,9 +219,6 @@ fn main() -> Result<(), Box<std::error::Error>> { let mut outfile = fs::File::create(outfilename)?; data.write_pretty(&mut outfile, 1)?; - //data.write(&mut outfile)?; - //debug - break; } Ok(()) }