diff --git a/Cargo.lock b/Cargo.lock index 3eaec063..6091c4d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -739,7 +739,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hl" -version = "0.20.0-beta.14.8.2" +version = "0.20.0-beta.14.9" dependencies = [ "atoi", "bincode", diff --git a/Cargo.toml b/Cargo.toml index eabdec70..b96e4061 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ categories = ["command-line-utilities"] description = "Utility for viewing json-formatted log files." keywords = ["cli", "human", "log"] name = "hl" -version = "0.20.0-beta.14.8.2" +version = "0.20.0-beta.14.9" edition = "2021" build = "build.rs" diff --git a/src/model.rs b/src/model.rs index ba20be36..4a85b680 100644 --- a/src/model.rs +++ b/src/model.rs @@ -323,18 +323,11 @@ impl<'a> KeyMatcher<'a> { } pub fn match_key<'b>(&'b self, key: &str) -> Option> { - let norm = |b: u8| { - if b == b'_' { - b'-' - } else { - b.to_ascii_lowercase() - } - }; let bytes = self.key.as_bytes(); if bytes .iter() .zip(key.as_bytes().iter()) - .position(|(&x, &y)| norm(x) != norm(y)) + .position(|(&x, &y)| Self::norm(x.into()) != Self::norm(y.into())) .is_some() { return None; @@ -352,6 +345,14 @@ impl<'a> KeyMatcher<'a> { None } } + + fn norm(c: char) -> char { + if c == '_' { + '-' + } else { + c.to_ascii_lowercase() + } + } } // --- @@ -413,7 +414,7 @@ impl FieldFilter { let (key, match_policy, op) = Self::parse_mp_op(key, value)?; let flat_key = key.as_bytes().iter().position(|&x| x == b'.').is_none(); Ok(Self { - key: key.into(), + key: key.chars().map(KeyMatcher::norm).collect(), match_policy, op, flat_key,