diff --git a/Cargo.lock b/Cargo.lock index f9ca0d97..28b32f1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -738,7 +738,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hl" -version = "0.27.0-beta.4.2" +version = "0.27.0-beta.4.3" dependencies = [ "atoi", "bincode", diff --git a/Cargo.toml b/Cargo.toml index 84f7e81d..8f53080c 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.27.0-beta.4.2" +version = "0.27.0-beta.4.3" edition = "2021" build = "build.rs" diff --git a/src/formatting.rs b/src/formatting.rs index c0e9ba52..b23c4506 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -214,7 +214,7 @@ impl RecordFormatter { fn format_message<'a, S: StylingPush>(&self, s: &mut S, value: RawValue<'a>) { match value.kind() { - ValueKind::QuotedString | ValueKind::String => { + ValueKind::String(_) => { s.element(Element::Message, |s| s.batch(|buf| value.format_as_str(buf))); } ValueKind::Number => { @@ -352,7 +352,7 @@ impl<'a> FieldFormatter<'a> { setting: IncludeExcludeSetting, ) { match value.kind() { - ValueKind::String | ValueKind::QuotedString => { + ValueKind::String(_) => { s.element(Element::String, |s| { s.batch(|buf| { value.format_as_str(buf); diff --git a/src/model.rs b/src/model.rs index f4d851d6..a668feb8 100644 --- a/src/model.rs +++ b/src/model.rs @@ -28,6 +28,7 @@ use crate::types::FieldKind; // --- pub use level::Level; +use ValueKindString::*; // --- @@ -47,7 +48,7 @@ impl<'a> RawValue<'a> { return ValueKind::Null; } match bytes[0] { - b'"' => ValueKind::QuotedString, + b'"' => ValueKind::String(Quoted), b'0'..=b'9' | b'-' | b'+' | b'.' => ValueKind::Number, b'{' => ValueKind::Object, b'[' => ValueKind::Array, @@ -74,7 +75,7 @@ impl<'a> RawValue<'a> { }; if !value.get().is_empty() && value.get().as_bytes()[0] == b'"' { - ValueKind::QuotedString + ValueKind::String(Quoted) } else if value.get() == "false" || value.get() == "true" { ValueKind::Boolean } else if value.get() == "null" { @@ -82,7 +83,7 @@ impl<'a> RawValue<'a> { } else if looks_like_number() { ValueKind::Number } else { - ValueKind::String + ValueKind::String(Unquoted) } } } @@ -237,8 +238,7 @@ impl<'a> From<&'a logfmt::raw::RawValue> for RawValue<'a> { #[derive(Clone, Debug, Copy, PartialEq, Eq)] pub enum ValueKind { - String, - QuotedString, + String(ValueKindString), Number, Object, Array, @@ -246,6 +246,12 @@ pub enum ValueKind { Null, } +#[derive(Clone, Debug, Copy, PartialEq, Eq)] +pub enum ValueKindString { + Quoted, + Unquoted, +} + // --- pub struct Record<'a> { @@ -671,7 +677,7 @@ impl FieldSettings { } Self::Level(i) => { let value = match value.kind() { - ValueKind::QuotedString => value.parse().ok().unwrap_or_else(|| value.raw_str()), + ValueKind::String(Quoted) => value.parse().ok().unwrap_or_else(|| value.raw_str()), _ => value.raw_str(), }; if let Some(level) = ps.level[i].0.get(value) { @@ -719,7 +725,7 @@ impl FieldSettings { *line = value.raw_str(); true } - ValueKind::String => { + ValueKind::String(Unquoted) => { if let Some(value) = value.parse().ok() { *line = value; true @@ -1294,7 +1300,7 @@ impl FieldFilter { continue; } Some(KeyMatch::Full) => { - return self.match_value(Some(v.raw_str()), v.kind() == ValueKind::String); + return self.match_value(Some(v.raw_str()), v.kind() == ValueKind::String(Unquoted)); } Some(KeyMatch::Partial(subkey)) => { return self.match_value_partial(subkey, *v); @@ -1344,7 +1350,7 @@ impl RecordFilter for FieldFilter { match self.match_custom_key(*k) { None => {} Some(KeyMatch::Full) => { - let escaped = v.kind() == ValueKind::QuotedString; + let escaped = v.kind() == ValueKind::String(Quoted); if self.match_value(Some(v.raw_str()), escaped) { return true; }