@@ -4,6 +4,7 @@ use crate::columns::*;
44use crate :: config:: * ;
55use crate :: opt:: { ArgColorMode , ArgPagerMode } ;
66use crate :: process:: collect_proc;
7+ use crate :: search_regex:: SearchRegex ;
78use crate :: style:: { apply_color, apply_style, color_to_column_style} ;
89use crate :: term_info:: TermInfo ;
910use crate :: util:: {
@@ -13,7 +14,6 @@ use crate::util::{
1314use anyhow:: { Error , bail} ;
1415#[ cfg( not( target_os = "windows" ) ) ]
1516use pager:: Pager ;
16- use regex:: RegexBuilder ;
1717use std:: collections:: HashMap ;
1818use std:: time:: Duration ;
1919
@@ -52,10 +52,8 @@ impl View {
5252
5353 // Adding the sort column to inserts if not already present
5454 match ( & opt. sorta , & opt. sortd ) {
55- ( _, Some ( col) ) | ( Some ( col) , _) => {
56- if !opt. insert . contains ( col) {
57- opt. insert . push ( col. clone ( ) ) ;
58- }
55+ ( _, Some ( col) ) | ( Some ( col) , _) if !opt. insert . contains ( col) => {
56+ opt. insert . push ( col. clone ( ) ) ;
5957 }
6058 _ => { }
6159 }
@@ -263,9 +261,7 @@ impl View {
263261 ConfigSearchCase :: Insensitive => true ,
264262 ConfigSearchCase :: Sensitive => false ,
265263 } ;
266- let regex = RegexBuilder :: new ( pattern)
267- . case_insensitive ( ignore_case)
268- . build ( ) ?;
264+ let regex = SearchRegex :: new ( pattern, ignore_case) ?;
269265 Some ( regex)
270266 } else {
271267 None
@@ -316,7 +312,7 @@ impl View {
316312 } else if opt. keyword . is_empty ( ) {
317313 true
318314 } else if let Some ( regex) = & regex {
319- View :: search_regex ( * pid, cols_searchable. as_slice ( ) , regex)
315+ View :: search_regex ( * pid, cols_searchable. as_slice ( ) , regex) ?
320316 } else {
321317 View :: search (
322318 * pid,
@@ -714,8 +710,13 @@ impl View {
714710 }
715711 }
716712
717- fn search_regex ( pid : i32 , cols : & [ & dyn Column ] , regex : & regex:: Regex ) -> bool {
718- cols. iter ( ) . any ( |c| regex. is_match ( & c. display_json ( pid) ) )
713+ fn search_regex ( pid : i32 , cols : & [ & dyn Column ] , regex : & SearchRegex ) -> Result < bool , Error > {
714+ for c in cols {
715+ if regex. is_match ( & c. display_json ( pid) ) ? {
716+ return Ok ( true ) ;
717+ }
718+ }
719+ Ok ( false )
719720 }
720721
721722 #[ cfg( not( any( target_os = "windows" , any( target_os = "linux" , target_os = "android" ) ) ) ) ]
0 commit comments