Match against reference instead of value
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Hang Qian · committed by David Peter · parent bbd8c78 · Browse files · 1 file·+10 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+10 added−10 removed
- other:+10 added−10 removed
Provenance
- Commit
3f6ff2c- Tree
8e57835- Author
Hang Qian <hangqian90@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
bbd8c78
1 file changed+10 added−10 removed
modified:src/regex_helper.rs+10 added-10 removed
13 unmodified lines14 /// Determine if a regex expression contains a literal uppercase character.15 fn hir_has_uppercase_char(hir: &Hir) -> bool {16 use regex_syntax::hir::*;17 18- match *hir.kind() {18+ match hir.kind() {19 HirKind::Literal(Literal::Unicode(c)) => c.is_uppercase(),20- HirKind::Literal(Literal::Byte(b)) => char::from(b).is_uppercase(),21- HirKind::Class(Class::Unicode(ref ranges)) => ranges20+ HirKind::Literal(Literal::Byte(b)) => char::from(*b).is_uppercase(),21+ HirKind::Class(Class::Unicode(ranges)) => ranges22 .iter()23 .any(|r| r.start().is_uppercase() || r.end().is_uppercase()),24- HirKind::Class(Class::Bytes(ref ranges)) => ranges24+ HirKind::Class(Class::Bytes(ranges)) => ranges25 .iter()26 .any(|r| char::from(r.start()).is_uppercase() || char::from(r.end()).is_uppercase()),27- HirKind::Group(Group { ref hir, .. }) | HirKind::Repetition(Repetition { ref hir, .. }) => {27+ HirKind::Group(Group { hir, .. }) | HirKind::Repetition(Repetition { hir, .. }) => {28 hir_has_uppercase_char(hir)29 }30- HirKind::Concat(ref hirs) | HirKind::Alternation(ref hirs) => {30+ HirKind::Concat(hirs) | HirKind::Alternation(hirs) => {31 hirs.iter().any(hir_has_uppercase_char)32 }33 _ => false,34 }16 unmodified lines51 // Note: this only really detects the simplest case where a regex starts with52 // "^\\.", i.e. a start text anchor and a literal dot character. There are a lot53 // of other patterns that ONLY match hidden files, e.g. ^(\\.foo|\\.bar) which are54 // not (yet) detected by this algorithm.55- match *hir.kind() {56- HirKind::Concat(ref hirs) => {55+ match hir.kind() {56+ HirKind::Concat(hirs) => {57 let mut hirs = hirs.iter();58 if let Some(hir) = hirs.next() {59- if *hir.kind() != HirKind::Anchor(Anchor::StartText) {59+ if hir.kind() != &HirKind::Anchor(Anchor::StartText) {60 return false;61 }62 } else {63 return false;64 }65 66 if let Some(hir) = hirs.next() {67- *hir.kind() == HirKind::Literal(Literal::Unicode('.'))67+ hir.kind() == &HirKind::Literal(Literal::Unicode('.'))68 } else {69 false70 }71 }29 unmodified lines