1
0
mirror of https://github.com/jht5945/finding.git synced 2026-01-12 03:50:04 +08:00

Compare commits

..

2 Commits

Author SHA1 Message Date
c03ab9ff4c fix clippy 2020-01-11 11:43:10 +08:00
1d079d1d88 fix clipy 2020-01-11 11:34:09 +08:00

View File

@@ -26,12 +26,11 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
const GIT_HASH: &str = env!("GIT_HASH");
fn print_version() {
print!(r#"finding {} - {}
println!(r#"finding {} - {}
Copyright (C) 2019 Hatter Jiang.
License MIT <https://opensource.org/licenses/MIT>
Written by Hatter Jiang
"#, VERSION, &GIT_HASH[0..7]);
Written by Hatter Jiang"#, VERSION, &GIT_HASH[0..7]);
}
fn find_huge_files(options: &Options, dir_path: &Path) {
@@ -43,10 +42,9 @@ fn find_huge_files(options: &Options, dir_path: &Path) {
match p.metadata() {
Err(err) => {
if options.verbose {
let p_str = p.to_str();
if p_str.is_some() {
if let Some(p_str) = p.to_str() {
print_lastline("");
print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str.unwrap(), err));
print_message(MessageType::WARN, &format!("Read file {} meta failed: {}", p_str, err));
}
}
return;
@@ -105,7 +103,7 @@ impl MatchLine {
}
}
fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
fn match_lines(tag: &str, content: &str, options: &Options) -> bool {
let search_text = &options.search_text;
let lines = content.lines();
let mut match_lines_vec = vec![];
@@ -127,7 +125,7 @@ fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
false => ln.contains(the_search_text),
};
let mut matches_line_content = true;
if options.filter_line_content.len() > 0 {
if !options.filter_line_content.is_empty(){
if ! ln.contains(options.filter_line_content.as_str()) {
matches_line_content = false;
}
@@ -139,7 +137,7 @@ fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
}
let mut matches_any = false;
if match_lines_vec.len() > 0 {
if !match_lines_vec.is_empty() {
print_lastline("");
print_message(MessageType::OK, &format!("Find in {}:", tag));
for i in 0..match_lines_vec.len() {
@@ -164,7 +162,7 @@ fn match_lines(tag: &str, content: &String, options: &Options) -> bool {
}
fn find_text_files(options: &Options, dir_path: &Path) {
if options.search_text.len() < 1 {
if options.search_text.is_empty() {
print_message(MessageType::ERROR, "Param search_text cannot be empty.");
return;
}
@@ -174,7 +172,7 @@ fn find_text_files(options: &Options, dir_path: &Path) {
let file_exts = match options.file_ext.as_str() {
"" => vec![],
ext => {
ext.split(",").map(|s| s.trim()).filter(|s| s.len() > 0).map(|s| String::from(".") + s).collect()
ext.split(',').map(|s| s.trim()).filter(|s| !s.is_empty()).map(|s| String::from(".") + s).collect()
},
};
let total_file_count_cell = RefCell::new(0u64);
@@ -188,10 +186,10 @@ fn find_text_files(options: &Options, dir_path: &Path) {
None => return,
Some(s) => s,
};
if file_exts.len() > 0 {
if !file_exts.is_empty() {
let mut file_ext_matches = false;
for i in 0..file_exts.len() {
if p_str.to_lowercase().ends_with(&file_exts[i]) {
for file_ext in &file_exts {
if p_str.to_lowercase().ends_with(file_ext) {
file_ext_matches = true;
break;
}
@@ -200,7 +198,7 @@ fn find_text_files(options: &Options, dir_path: &Path) {
return;
}
}
if options.filter_file_name.len() > 0 {
if !options.filter_file_name.is_empty() {
if ! p_str.contains(options.filter_file_name.as_str()) {
return;
}