From c4c7f3014b51280932244d5c132031f23642cf79 Mon Sep 17 00:00:00 2001 From: jtmoon79 <815261+jtmoon79@users.noreply.github.com> Date: Sun, 8 Jan 2023 23:41:51 -0800 Subject: [PATCH] datetime.rs more precise regexp for ReportingEvents.log, others --- src/data/datetime.rs | 14 +++++++++----- src/tests/datetime_tests.rs | 25 +++++++++++++++++-------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/data/datetime.rs b/src/data/datetime.rs index 96ba644d..bae6a2b0 100644 --- a/src/data/datetime.rs +++ b/src/data/datetime.rs @@ -1220,6 +1220,8 @@ pub const CGP_SECOND: &CaptureGroupPattern = r"(?P[012345][[:digit:]]|60 /// function `captures_to_buffer_bytes`. Then it is parsed by /// `datetime_parse_from_str` using `%f` specifier. pub const CGP_FRACTIONAL: &CaptureGroupPattern = r"(?P[[:digit:]]{1,9})"; +/// Like [`CGP_FRACTIONAL`] but only matches 3 digits, `%3f`. +pub const CGP_FRACTIONAL3: &CaptureGroupPattern = r"(?P[[:digit:]]{3})"; /// Regex capture group pattern for dmesg uptime fractional seconds in logs //pub const CGP_UPTIME: &CaptureGroupPattern = r"(?P[[:digit:]]{1,9}\.[[:digit:]]{3,9})"; @@ -1333,16 +1335,16 @@ pub(crate) const CGP_TZ_ALL: &[&CaptureGroupPattern] = &[ ]; /// no alphabetic or line end, helper to `CGP_TZZ` -const RP_NOALPHA: &RegexPattern = r"([^[[:alpha:]]]|$)"; +const RP_NOALPHA: &RegexPattern = r"([^[[:alpha:]]]|$|^)"; /// no alphanumeric or line end, helper to `CGP_TZZ` and and `CGP_YEAR` -const RP_NOALNUM: &RegexPattern = r"([^[[:alnum:]]]|$)"; +const RP_NOALNUM: &RegexPattern = r"([^[[:alnum:]]]|$|^)"; /// no alphanumeric plus minus or line end, helper to `CGP_TZZ` and `CGP_YEAR` -const RP_NOALNUMpm: &RegexPattern = r"([^[[:alnum:]]\+\-]|$)"; +const RP_NOALNUMpm: &RegexPattern = r"([^[[:alnum:]]\+\-]|$|^)"; /// no numeric or line end, helper to `CGP_TZZ` and `CGP_YEAR` -const RP_NODIGIT: &RegexPattern = r"([^[[:digit:]]]|$)"; +const RP_NODIGIT: &RegexPattern = r"([^[[:digit:]]]|$|^)"; /// All named timezone abbreviations, maps all chrono strftime `%Z` values /// (e.g. `"EDT"`) to equivalent `%:z` value (e.g. `"-04:00"`). @@ -2895,6 +2897,7 @@ pub const DATETIME_PARSE_DATAS: [DateTimeParseInstr; DATETIME_PARSE_DATAS_LEN] = // ERROR: apport (pid 9) Thu Feb 27 00:33:59 2020: called for pid 8581, signal 24, core limit 0, dump mode 1 // ERROR: apport (pid 9) Thu Feb 27 00:33:59 2020 -0700: called for pid 8581, signal 24, core limit 0, dump mode 1 // ERROR: apport (pid 9) Thu Feb 27 00:33:59 2020 -07:00: called for pid 8581, signal 24, core limit 0, dump mode 1 + // ERROR: apport (pid 9) Thu Feb 20 00:59:59 2020: executable: /usr/lib/firefox/firefox (command line "/usr/lib/firefox/firefox" // DTPD!( concatcp!("^", RP_LEVELS, "[:]?", RP_ANYp, RP_BLANK, CGP_DAYa, RP_BLANK, CGP_MONTHb, RP_BLANK, CGP_DAYde, RP_BLANK, CGP_HOUR, D_T, CGP_MINUTE, D_T, CGP_SECOND, RP_BLANKS, CGP_YEAR, RP_BLANKS, CGP_TZzc, RP_NODIGIT), @@ -2938,6 +2941,7 @@ pub const DATETIME_PARSE_DATAS: [DateTimeParseInstr; DATETIME_PARSE_DATAS_LEN] = &[ (22, 46, "ERROR: apport (pid 9) Thu Feb 27 00:33:59 2020 called for pid 8581, signal 24, core limit 0, dump mode 1"), (27, 51, r#"ERROR: apport (pid 529343) Sat Aug 13 08:48:03 2022: executable: /mnt/Projects/super-speedy-syslog-searcher/target/release/s4 (command line "./target/release/s4 -s -wp /dev")"#), + (25, 49, r#"ERROR: apport (pid 9359) Thu Feb 20 00:59:59 2020: executable: /usr/lib/firefox/firefox (command line "/usr/lib/firefox/firefox"#) ], line!(), ), @@ -3186,7 +3190,7 @@ pub const DATETIME_PARSE_DATAS: [DateTimeParseInstr; DATETIME_PARSE_DATAS_LEN] = // very similar to next DTPD!, but with different second-to-fractional divider ":" // DTPD!( - concatcp!(CGP_YEAR, D_Dq, CGP_MONTHm, D_Dq, CGP_DAYde, D_DHcdq, CGP_HOUR, D_T, CGP_MINUTE, D_T, CGP_SECOND, ":", CGP_FRACTIONAL, RP_BLANKq, CGP_TZz, RP_NODIGIT), + concatcp!(RP_NODIGIT, CGP_YEAR, D_Dq, CGP_MONTHm, D_Dq, CGP_DAYde, D_DHcdq, CGP_HOUR, D_T, CGP_MINUTE, D_T, CGP_SECOND, ":", CGP_FRACTIONAL3, RP_BLANKq, CGP_TZz, RP_NODIGIT), DTFSS_YmdHMSfz, 0, 1024, CGN_YEAR, CGN_TZ, &[ (40, 68, r"{5F45546A-691D-4519-810C-9B159EA7A24F} 2022-10-12 09:26:44:980-0700 1 181 [AGENT_INSTALLING_STARTED] 101 {ADF3720E-8453-44C7-82EF-F9F5DA2D8551} 1 0 Update;ScanForUpdates Success Content Download Download succeeded. te2D3dMIjE2PeNSM.86.3.1.0.0.85.0") diff --git a/src/tests/datetime_tests.rs b/src/tests/datetime_tests.rs index 35c64ecd..ba9668e7 100644 --- a/src/tests/datetime_tests.rs +++ b/src/tests/datetime_tests.rs @@ -11,14 +11,16 @@ use crate::tests::common::{TZO_0, TZO_E1, TZO_W8}; use crate::data::datetime::{ bytes_to_regex_to_datetime, datetime_from_str_workaround_Issue660, datetime_parse_from_str, dt_after_or_before, dt_pass_filters, DTFSSet, DTFS_Tz, - DateTimeL, DateTimeLOpt, Duration, + DateTimeL, DateTimeLOpt, Duration, FixedOffset, DateTimeParseInstr, DateTimePattern_str, DateTimeRegex_str, - FixedOffset, MAP_TZZ_TO_TZz, Result_Filter_DateTime1, Result_Filter_DateTime2, TimeZone, Year, DATETIME_PARSE_DATAS_LEN, DATETIME_PARSE_DATAS, - CGN_ALL, CGP_DAY_ALL, CGP_FRACTIONAL, CGP_HOUR, CGP_MINUTE, CGP_MONTH_ALL, - CGP_SECOND, CGP_TZZ, CGP_TZ_ALL, CGP_YEAR, CGP_YEARy, - DTP_ALL, RP_LB, RP_RB, TZZ_LIST_LOWER, TZZ_LIST_UPPER, TZZ_LOWER_TO_UPPER, + CGP_HOUR, CGP_MINUTE, CGP_SECOND, CGP_FRACTIONAL, CGP_FRACTIONAL3, + CGP_MONTH_ALL, CGN_ALL, CGP_DAY_ALL, CGP_YEAR, CGP_YEARy, + CGP_TZZ, CGP_TZ_ALL, + TZZ_LIST_LOWER, TZZ_LIST_UPPER, TZZ_LOWER_TO_UPPER, MAP_TZZ_TO_TZz, + RP_LB, RP_RB, + DTP_ALL, }; use crate::debug::printers::buffer_to_String_noraw; @@ -160,7 +162,7 @@ pub fn regex_pattern_has_second(pattern: &DateTimeRegex_str) -> bool { /// does regex pattern have a fractional second? pub fn regex_pattern_has_fractional(pattern: &DateTimeRegex_str) -> bool { - pattern.contains(CGP_FRACTIONAL) + pattern.contains(CGP_FRACTIONAL) || pattern.contains(CGP_FRACTIONAL3) } /// does regex pattern have a timezone? @@ -517,7 +519,7 @@ fn test_DATETIME_PARSE_DATAS_test_cases(index: usize) { let dp_ss = dt_pattern_has_second(dtpat); assert_eq!( rp_ss, dp_ss, - "regex_pattern has second {}, datetime pattern has second {}; they must agree; declared at line {}\n regex pattern: {:?}\n dt_pattern {:?}", + "regex_pattern has second {}, datetime pattern has second {}; they must agree; declared at line {}\n regex pattern: {:?}\n dt_pattern {:?}\n", rp_ss, dp_ss, dtpd._line_num, regpat, @@ -526,7 +528,14 @@ fn test_DATETIME_PARSE_DATAS_test_cases(index: usize) { // check fractional (optional but must agree) let rp_ss = regex_pattern_has_fractional(regpat); let dp_ss = dt_pattern_has_fractional(dtpat); - assert_eq!(rp_ss, dp_ss, "regex pattern fractional {}, datetime pattern fractional {}; they must agree; declared at line {}", rp_ss, dp_ss, dtpd._line_num); + assert_eq!( + rp_ss, dp_ss, + "regex_pattern has fractional {}, datetime pattern has fractional {}; they must agree; declared at line {}\n regex pattern: {:?}\n dt_pattern {:?}\n", + rp_ss, dp_ss, + dtpd._line_num, + regpat, + dtpat, + ); // check timezone if dtfs.has_tz() { assert!(