diff options
author | Andrew Gallant <jamslam@gmail.com> | 2019-06-26 16:47:33 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2019-06-26 16:47:33 -0400 |
commit | b93762ea7a397b54e9ccf589a45a2c6ad91bc390 (patch) | |
tree | 54152ae9fb21c14f95ceefcb35e2d5b2f86295b1 /globset | |
parent | 34677d262246462ce3027ee57be1869a9dc7730a (diff) |
bstr: update everything to bstr 0.2
Diffstat (limited to 'globset')
-rw-r--r-- | globset/Cargo.toml | 2 | ||||
-rw-r--r-- | globset/src/glob.rs | 4 | ||||
-rw-r--r-- | globset/src/lib.rs | 14 | ||||
-rw-r--r-- | globset/src/pathutil.rs | 18 |
4 files changed, 19 insertions, 19 deletions
diff --git a/globset/Cargo.toml b/globset/Cargo.toml index ce9637e3..1b541258 100644 --- a/globset/Cargo.toml +++ b/globset/Cargo.toml @@ -20,7 +20,7 @@ bench = false [dependencies] aho-corasick = "0.7.3" -bstr = { version = "0.1.2", default-features = false, features = ["std"] } +bstr = { version = "0.2.0", default-features = false, features = ["std"] } fnv = "1.0.6" log = "0.4.5" regex = "1.1.5" diff --git a/globset/src/glob.rs b/globset/src/glob.rs index 5e635a20..eccfb2d3 100644 --- a/globset/src/glob.rs +++ b/globset/src/glob.rs @@ -120,7 +120,7 @@ impl GlobMatcher { /// Tests whether the given path matches this pattern or not. pub fn is_match_candidate(&self, path: &Candidate) -> bool { - self.re.is_match(path.path.as_bytes()) + self.re.is_match(&path.path) } } @@ -145,7 +145,7 @@ impl GlobStrategic { /// Tests whether the given path matches this pattern or not. fn is_match_candidate(&self, candidate: &Candidate) -> bool { - let byte_path = candidate.path.as_bytes(); + let byte_path = &*candidate.path; match self.strategy { MatchStrategy::Literal(ref lit) => lit.as_bytes() == byte_path, diff --git a/globset/src/lib.rs b/globset/src/lib.rs index 6b3ca85c..0b3b7b6c 100644 --- a/globset/src/lib.rs +++ b/globset/src/lib.rs @@ -119,7 +119,7 @@ use std::path::Path; use std::str; use aho_corasick::AhoCorasick; -use bstr::{B, BStr, BString}; +use bstr::{B, ByteSlice, ByteVec}; use regex::bytes::{Regex, RegexBuilder, RegexSet}; use pathutil::{file_name, file_name_ext, normalize_path}; @@ -490,15 +490,15 @@ impl GlobSetBuilder { /// path against multiple globs or sets of globs. #[derive(Clone, Debug)] pub struct Candidate<'a> { - path: Cow<'a, BStr>, - basename: Cow<'a, BStr>, - ext: Cow<'a, BStr>, + path: Cow<'a, [u8]>, + basename: Cow<'a, [u8]>, + ext: Cow<'a, [u8]>, } impl<'a> Candidate<'a> { /// Create a new candidate for matching from the given path. pub fn new<P: AsRef<Path> + ?Sized>(path: &'a P) -> Candidate<'a> { - let path = normalize_path(BString::from_path_lossy(path.as_ref())); + let path = normalize_path(Vec::from_path_lossy(path.as_ref())); let basename = file_name(&path).unwrap_or(Cow::Borrowed(B(""))); let ext = file_name_ext(&basename).unwrap_or(Cow::Borrowed(B(""))); Candidate { @@ -508,7 +508,7 @@ impl<'a> Candidate<'a> { } } - fn path_prefix(&self, max: usize) -> &BStr { + fn path_prefix(&self, max: usize) -> &[u8] { if self.path.len() <= max { &*self.path } else { @@ -516,7 +516,7 @@ impl<'a> Candidate<'a> { } } - fn path_suffix(&self, max: usize) -> &BStr { + fn path_suffix(&self, max: usize) -> &[u8] { if self.path.len() <= max { &*self.path } else { diff --git a/globset/src/pathutil.rs b/globset/src/pathutil.rs index 6c2fb1e9..6b4609e8 100644 --- a/globset/src/pathutil.rs +++ b/globset/src/pathutil.rs @@ -1,15 +1,15 @@ use std::borrow::Cow; -use bstr::BStr; +use bstr::{ByteSlice, ByteVec}; /// The final component of the path, if it is a normal file. /// /// If the path terminates in ., .., or consists solely of a root of prefix, /// file_name will return None. -pub fn file_name<'a>(path: &Cow<'a, BStr>) -> Option<Cow<'a, BStr>> { +pub fn file_name<'a>(path: &Cow<'a, [u8]>) -> Option<Cow<'a, [u8]>> { if path.is_empty() { return None; - } else if path.last() == Some(b'.') { + } else if path.last_byte() == Some(b'.') { return None; } let last_slash = path.rfind_byte(b'/').map(|i| i + 1).unwrap_or(0); @@ -39,7 +39,7 @@ pub fn file_name<'a>(path: &Cow<'a, BStr>) -> Option<Cow<'a, BStr>> { /// a pattern like `*.rs` is obviously trying to match files with a `rs` /// extension, but it also matches files like `.rs`, which doesn't have an /// extension according to std::path::Path::extension. -pub fn file_name_ext<'a>(name: &Cow<'a, BStr>) -> Option<Cow<'a, BStr>> { +pub fn file_name_ext<'a>(name: &Cow<'a, [u8]>) -> Option<Cow<'a, [u8]>> { if name.is_empty() { return None; } @@ -60,7 +60,7 @@ pub fn file_name_ext<'a>(name: &Cow<'a, BStr>) -> Option<Cow<'a, BStr>> { /// Normalizes a path to use `/` as a separator everywhere, even on platforms /// that recognize other characters as separators. #[cfg(unix)] -pub fn normalize_path(path: Cow<BStr>) -> Cow<BStr> { +pub fn normalize_path(path: Cow<[u8]>) -> Cow<[u8]> { // UNIX only uses /, so we're good. path } @@ -68,7 +68,7 @@ pub fn normalize_path(path: Cow<BStr>) -> Cow<BStr> { /// Normalizes a path to use `/` as a separator everywhere, even on platforms /// that recognize other characters as separators. #[cfg(not(unix))] -pub fn normalize_path(mut path: Cow<BStr>) -> Cow<BStr> { +pub fn normalize_path(mut path: Cow<[u8]>) -> Cow<[u8]> { use std::path::is_separator; for i in 0..path.len() { @@ -84,7 +84,7 @@ pub fn normalize_path(mut path: Cow<BStr>) -> Cow<BStr> { mod tests { use std::borrow::Cow; - use bstr::{B, BString}; + use bstr::{B, ByteVec}; use super::{file_name_ext, normalize_path}; @@ -92,7 +92,7 @@ mod tests { ($name:ident, $file_name:expr, $ext:expr) => { #[test] fn $name() { - let bs = BString::from($file_name); + let bs = Vec::from($file_name); let got = file_name_ext(&Cow::Owned(bs)); assert_eq!($ext.map(|s| Cow::Borrowed(B(s))), got); } @@ -109,7 +109,7 @@ mod tests { ($name:ident, $path:expr, $expected:expr) => { #[test] fn $name() { - let bs = BString::from_slice($path); + let bs = Vec::from_slice($path); let got = normalize_path(Cow::Owned(bs)); assert_eq!($expected.to_vec(), got.into_owned()); } |