Skip to content
Myr

Use regex::bytes::* instead of regex::*

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by David Peter · parent 2545aaa · Browse files · 4 files+39 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+39 added−16 removed

  • other:+39 added−16 removed

4 files+39 added−16 removed

modified:src/internal/mod.rs+19 added-1 removed
4 unmodified lines
5// at your option. All files in the project carrying such6// notice may not be copied, modified, or distributed except7// according to those terms.89use std::borrow::Cow;10use std::ffi::{OsStr, OsString};1112use regex_syntax::hir::Hir;13use regex_syntax::Parser;11use std::ffi::OsString;1415pub use self::file_types::FileTypes;1617mod file_types;
10 unmodified lines
28 ::std::process::exit(1);29 };30}3132#[cfg(any(unix, target_os = "redox"))]33pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> {34 use std::os::unix::ffi::OsStrExt;35 Cow::Borrowed(input.as_bytes())36}3738#[cfg(windows)]39pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> {40 let string = input.to_string_lossy();4142 match string {43 Cow::Owned(string) => Cow::Owned(string.into_bytes()),44 Cow::Borrowed(string) => Cow::Borrowed(string.as_bytes()),45 }46}4748/// Determine if a regex pattern contains a literal uppercase character.49pub fn pattern_has_uppercase_char(pattern: &str) -> bool {50 Parser::new()51 .parse(pattern)
140 unmodified lines
modified:src/internal/opts.rs+1 added-1 removed
2 unmodified lines
3 filter::{SizeFilter, TimeFilter},4 FileTypes,5};6use lscolors::LsColors;7use regex::RegexSet;7use regex::bytes::RegexSet;8use std::{path::PathBuf, sync::Arc, time::Duration};910/// Configuration options for *fd*.11pub struct FdOptions {
70 unmodified lines
modified:src/main.rs+1 added-1 removed
23 unmodified lines
24use std::time;2526use atty::Stream;27use lscolors::LsColors;28use regex::{RegexBuilder, RegexSetBuilder};28use regex::bytes::{RegexBuilder, RegexSetBuilder};2930use crate::exec::CommandTemplate;31use crate::internal::{32 filter::{SizeFilter, TimeFilter},
237 unmodified lines
modified:src/walk.rs+18 added-13 removed
7 unmodified lines
89use crate::exec;10use crate::exit_codes::ExitCode;11use crate::fshelper;12use crate::internal::{opts::FdOptions, MAX_BUFFER_LENGTH};12use crate::internal::{opts::FdOptions, osstr_to_bytes, MAX_BUFFER_LENGTH};13use crate::output;1415use std::borrow::Cow;16use std::error::Error;17use std::ffi::OsStr;18use std::io;19use std::path::PathBuf;20use std::process;21use std::sync::atomic::{AtomicBool, Ordering};
3 unmodified lines
25use std::time;2627use ignore::overrides::OverrideBuilder;28use ignore::{self, WalkBuilder};27use regex::Regex;29use regex::bytes::Regex;3031/// The receiver thread can either be buffering results or directly streaming to the console.32enum ReceiverMode {33 /// Receiver is still buffering in order to sort the results, if the search finishes fast
246 unmodified lines
280 return ignore::WalkState::Continue;281 }282283 // Check the name first, since it doesn't require metadata282284 let entry_path = entry.path();285285 let search_str_o = if config.search_full_path {286 let search_str: Cow<OsStr> = if config.search_full_path {287 match fshelper::path_absolute_form(entry_path) {287 Ok(path_abs_buf) => Some(path_abs_buf.to_string_lossy().into_owned().into()),288 Ok(path_abs_buf) => Cow::Owned(path_abs_buf.as_os_str().to_os_string()),289 Err(_) => {290 print_error_and_exit!("Unable to retrieve absolute path.");291 }292 }293 } else {293 entry_path.file_name().map(|f| f.to_string_lossy())294 match entry_path.file_name() {295 Some(filename) => Cow::Borrowed(filename),296 None => unreachable!(297 "Encountered file system entry without a file name. This should only \298 happen for paths like 'foo/bar/..' or '/' which are not supposed to \299 appear in a file system traversal."300 ),301 }302 };303296 if let Some(search_str) = search_str_o {297 if !pattern.is_match(&*search_str) {298 return ignore::WalkState::Continue;304 if !pattern.is_match(&osstr_to_bytes(search_str.as_ref())) {305 return ignore::WalkState::Continue;299 }306 }307308 // Filter out unwanted extensions.309 if let Some(ref exts_regex) = config.extensions {304 if let Some(path_str) = entry_path.file_name().and_then(|s| s.to_str()) {305 if !exts_regex.is_match(path_str) {310 if let Some(path_str) = entry_path.file_name() {311 if !exts_regex.is_match(&osstr_to_bytes(path_str)) {312 return ignore::WalkState::Continue;313 }314 } else {315 return ignore::WalkState::Continue;316 }317 }318319 // Filter out unwanted file types.314320 if let Some(ref file_types) = config.file_types {321 if let Some(ref entry_type) = entry.file_type() {322 if (!file_types.files && entry_type.is_file())323 || (!file_types.directories && entry_type.is_dir())
68 unmodified lines