use anyhow::{Context, Error};
use regex::bytes::{RegexSet, RegexSetBuilder};
use std::path::Path;
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
pub fn build_regex_set(
patterns: Option<&Vec<String>>,
case_insensitive: bool,
) -> Result<RegexSet, Error> {
RegexSetBuilder::new(patterns.map_or(&Vec::new(), |v| v))
.case_insensitive(case_insensitive)
.build()
.context("Unable to parse and build regular expression set")
}
#[cfg(unix)]
#[inline]
pub fn path_to_bytes<P: AsRef<Path> + ?Sized>(path: &P) -> &[u8] {
path.as_ref().as_os_str().as_bytes()
}
#[cfg(not(unix))]
#[inline]
pub fn path_to_bytes<P: AsRef<Path> + ?Sized>(path: &P) -> &[u8] {
path.as_ref().as_os_str().to_str().unwrap_or("").as_bytes()
}