Skip to content

Commit

Permalink
PR comments: remove named arguments, match expression
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarschik committed Mar 18, 2022
1 parent 7820bfd commit 6e8dd3a
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions atuin-client/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,8 @@ impl Database for Sqlite {
SearchMode::Fuzzy => {
let split_regex = Regex::new(r" +").unwrap();
let terms: Vec<&str> = split_regex.split(query.as_str()).collect();
let num_terms = terms.len();
let mut query_sql = "".to_string();
let mut query_params = std::vec::Vec::with_capacity(num_terms);
let mut query_sql = std::string::String::new();
let mut query_params = Vec::with_capacity(terms.len());
let mut was_or = false;
for (i, query_part) in terms.into_iter().enumerate() {
// TODO smart case mode could be made configurable like in fzf
Expand All @@ -304,10 +303,9 @@ impl Database for Sqlite {
} else {
("like", '%')
};
let (is_inverse, query_part) = if query_part.starts_with('!') {
(true, query_part.strip_prefix('!').unwrap())
} else {
(false, query_part)
let (is_inverse, query_part) = match query_part.strip_prefix('!') {
Some(stripped) => (true, stripped),
None => (false, query_part),
};
match query_part {
"|" => {
Expand All @@ -316,29 +314,24 @@ impl Database for Sqlite {
was_or = true;
continue;
} else {
query_params.push(format!("{glob}|{glob}", glob = glob));
query_params.push(format!("{glob}|{glob}"));
}
}
exact_prefix if query_part.starts_with('^') => query_params.push(format!(
"{term}{glob}",
term = exact_prefix.strip_prefix('^').unwrap(),
glob = glob
term = exact_prefix.strip_prefix('^').unwrap()
)),
exact_suffix if query_part.ends_with('$') => query_params.push(format!(
"{glob}{term}",
term = exact_suffix.strip_suffix('$').unwrap(),
glob = glob
term = exact_suffix.strip_suffix('$').unwrap()
)),
exact if query_part.starts_with('\'') => query_params.push(format!(
"{glob}{term}{glob}",
term = exact.strip_prefix('\'').unwrap(),
glob = glob
)),
exact if is_inverse => query_params.push(format!(
"{glob}{term}{glob}",
term = exact,
glob = glob
term = exact.strip_prefix('\'').unwrap()
)),
exact if is_inverse => {
query_params.push(format!("{glob}{term}{glob}", term = exact))
}
_ => {
query_params.push(query_part.split("").join(glob.to_string().as_str()))
}
Expand Down

0 comments on commit 6e8dd3a

Please sign in to comment.