diff --git a/Cargo.lock b/Cargo.lock index 63e5d615..9d3b7616 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,7 +38,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bstr" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -145,7 +145,7 @@ name = "globset" version = "0.4.3" dependencies = [ "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -171,7 +171,7 @@ name = "grep-cli" version = "0.1.2" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "globset 0.4.3", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -202,7 +202,7 @@ name = "grep-printer" version = "0.1.2" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "grep-matcher 0.1.2", "grep-regex 0.1.3", "grep-searcher 0.1.4", @@ -229,7 +229,7 @@ dependencies = [ name = "grep-searcher" version = "0.1.4" dependencies = [ - "bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "encoding_rs 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)", "encoding_rs_io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -533,7 +533,7 @@ dependencies = [ name = "ripgrep" version = "11.0.1" dependencies = [ - "bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "grep 0.2.4", "ignore 0.4.7", @@ -726,7 +726,7 @@ dependencies = [ "checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" -"checksum bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "59604ece62a407dc9164732e5adea02467898954c3a5811fd2dc140af14ef15b" +"checksum bstr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b30b9697835ce3dd7f4c6f6d0952bbb64cdcd6fed2f29dc16fc0ffc39c684cd" "checksum bytecount 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be0fdd54b507df8f22012890aadd099979befdba27713c767993f8380112ca7c" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" diff --git a/Cargo.toml b/Cargo.toml index 7bd62d4f..84b0ab85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ members = [ ] [dependencies] -bstr = "0.1.2" +bstr = "0.2.0" grep = { version = "0.2.4", path = "grep" } ignore = { version = "0.4.7", path = "ignore" } lazy_static = "1.1.0" 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 + ?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> { +pub fn file_name<'a>(path: &Cow<'a, [u8]>) -> Option> { 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> { /// 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> { +pub fn file_name_ext<'a>(name: &Cow<'a, [u8]>) -> Option> { if name.is_empty() { return None; } @@ -60,7 +60,7 @@ pub fn file_name_ext<'a>(name: &Cow<'a, BStr>) -> Option> { /// 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) -> Cow { +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) -> Cow { /// 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) -> Cow { +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) -> Cow { 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()); } diff --git a/grep-cli/Cargo.toml b/grep-cli/Cargo.toml index eecba548..00f5f76d 100644 --- a/grep-cli/Cargo.toml +++ b/grep-cli/Cargo.toml @@ -14,7 +14,7 @@ license = "Unlicense/MIT" [dependencies] atty = "0.2.11" -bstr = "0.1.2" +bstr = "0.2.0" globset = { version = "0.4.3", path = "../globset" } lazy_static = "1.1.0" log = "0.4.5" diff --git a/grep-cli/src/escape.rs b/grep-cli/src/escape.rs index 6b4d2d3c..bf0d5b4f 100644 --- a/grep-cli/src/escape.rs +++ b/grep-cli/src/escape.rs @@ -1,7 +1,7 @@ use std::ffi::OsStr; use std::str; -use bstr::{BStr, BString}; +use bstr::{ByteSlice, ByteVec}; /// A single state in the state machine used by `unescape`. #[derive(Clone, Copy, Eq, PartialEq)] @@ -38,7 +38,6 @@ enum State { /// assert_eq!(r"foo\nbar\xFFbaz", escape(b"foo\nbar\xFFbaz")); /// ``` pub fn escape(bytes: &[u8]) -> String { - let bytes = BStr::new(bytes); let mut escaped = String::new(); for (s, e, ch) in bytes.char_indices() { if ch == '\u{FFFD}' { @@ -56,7 +55,7 @@ pub fn escape(bytes: &[u8]) -> String { /// /// This is like [`escape`](fn.escape.html), but accepts an OS string. pub fn escape_os(string: &OsStr) -> String { - escape(BString::from_os_str_lossy(string).as_bytes()) + escape(Vec::from_os_str_lossy(string).as_bytes()) } /// Unescapes a string. diff --git a/grep-cli/src/pattern.rs b/grep-cli/src/pattern.rs index 2855857e..eb5e7311 100644 --- a/grep-cli/src/pattern.rs +++ b/grep-cli/src/pattern.rs @@ -161,7 +161,7 @@ pub fn patterns_from_reader(rdr: R) -> io::Result> { let mut line_number = 0; io::BufReader::new(rdr).for_byte_line(|line| { line_number += 1; - match pattern_from_bytes(line.as_bytes()) { + match pattern_from_bytes(line) { Ok(pattern) => { patterns.push(pattern.to_string()); Ok(true) diff --git a/grep-printer/Cargo.toml b/grep-printer/Cargo.toml index cc6dc8d7..79177bbd 100644 --- a/grep-printer/Cargo.toml +++ b/grep-printer/Cargo.toml @@ -19,7 +19,7 @@ serde1 = ["base64", "serde", "serde_derive", "serde_json"] [dependencies] base64 = { version = "0.10.0", optional = true } -bstr = "0.1.2" +bstr = "0.2.0" grep-matcher = { version = "0.1.2", path = "../grep-matcher" } grep-searcher = { version = "0.1.4", path = "../grep-searcher" } termcolor = "1.0.4" diff --git a/grep-printer/src/standard.rs b/grep-printer/src/standard.rs index 92fae5ca..89f44ad4 100644 --- a/grep-printer/src/standard.rs +++ b/grep-printer/src/standard.rs @@ -5,7 +5,7 @@ use std::path::Path; use std::sync::Arc; use std::time::Instant; -use bstr::BStr; +use bstr::ByteSlice; use grep_matcher::{Match, Matcher}; use grep_searcher::{ LineStep, Searcher, @@ -1274,7 +1274,7 @@ impl<'a, M: Matcher, W: WriteColor> StandardImpl<'a, M, W> { ) -> io::Result<()> { if self.config().max_columns_preview { let original = line; - let end = BStr::new(&bytes[line]) + let end = bytes[line] .grapheme_indices() .map(|(_, end, _)| end) .take(self.config().max_columns.unwrap_or(0) as usize) @@ -1396,7 +1396,7 @@ impl<'a, M: Matcher, W: WriteColor> StandardImpl<'a, M, W> { } let remainder = format!( "after match (found {:?} byte around offset {})\n", - BStr::new(&[byte]), offset, + [byte].as_bstr(), offset, ); self.write(remainder.as_bytes())?; } else if let Some(byte) = bin.convert_byte() { @@ -1407,7 +1407,7 @@ impl<'a, M: Matcher, W: WriteColor> StandardImpl<'a, M, W> { } let remainder = format!( "matches (found {:?} byte around offset {})\n", - BStr::new(&[byte]), offset, + [byte].as_bstr(), offset, ); self.write(remainder.as_bytes())?; } diff --git a/grep-printer/src/util.rs b/grep-printer/src/util.rs index 7a20f3b7..d4a19eb7 100644 --- a/grep-printer/src/util.rs +++ b/grep-printer/src/util.rs @@ -4,7 +4,7 @@ use std::io; use std::path::Path; use std::time; -use bstr::{BStr, BString}; +use bstr::{ByteSlice, ByteVec}; use grep_matcher::{Captures, LineTerminator, Match, Matcher}; use grep_searcher::{ LineIter, @@ -263,12 +263,12 @@ impl<'a> Sunk<'a> { /// portability with a small cost: on Windows, paths that are not valid UTF-16 /// will not roundtrip correctly. #[derive(Clone, Debug)] -pub struct PrinterPath<'a>(Cow<'a, BStr>); +pub struct PrinterPath<'a>(Cow<'a, [u8]>); impl<'a> PrinterPath<'a> { /// Create a new path suitable for printing. pub fn new(path: &'a Path) -> PrinterPath<'a> { - PrinterPath(BString::from_path_lossy(path)) + PrinterPath(Vec::from_path_lossy(path)) } /// Create a new printer path from the given path which can be efficiently @@ -289,7 +289,7 @@ impl<'a> PrinterPath<'a> { /// path separators that are both replaced by `new_sep`. In all other /// environments, only `/` is treated as a path separator. fn replace_separator(&mut self, new_sep: u8) { - let transformed_path: BString = self.0.bytes().map(|b| { + let transformed_path: Vec = self.0.bytes().map(|b| { if b == b'/' || (cfg!(windows) && b == b'\\') { new_sep } else { @@ -301,7 +301,7 @@ impl<'a> PrinterPath<'a> { /// Return the raw bytes for this path. pub fn as_bytes(&self) -> &[u8] { - self.0.as_bytes() + &self.0 } } diff --git a/grep-searcher/Cargo.toml b/grep-searcher/Cargo.toml index 9911c9d7..471d3dfe 100644 --- a/grep-searcher/Cargo.toml +++ b/grep-searcher/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["regex", "grep", "egrep", "search", "pattern"] license = "Unlicense/MIT" [dependencies] -bstr = { version = "0.1.2", default-features = false, features = ["std"] } +bstr = { version = "0.2.0", default-features = false, features = ["std"] } bytecount = "0.5" encoding_rs = "0.8.14" encoding_rs_io = "0.1.6" diff --git a/grep-searcher/examples/search-stdin.rs b/grep-searcher/examples/search-stdin.rs index 9d642973..9ce14915 100644 --- a/grep-searcher/examples/search-stdin.rs +++ b/grep-searcher/examples/search-stdin.rs @@ -17,7 +17,7 @@ fn main() { } } -fn example() -> Result<(), Box> { +fn example() -> Result<(), Box> { let pattern = match env::args().nth(1) { Some(pattern) => pattern, None => return Err(From::from(format!( diff --git a/grep-searcher/src/line_buffer.rs b/grep-searcher/src/line_buffer.rs index cc7dd578..4b75fa37 100644 --- a/grep-searcher/src/line_buffer.rs +++ b/grep-searcher/src/line_buffer.rs @@ -1,7 +1,7 @@ use std::cmp; use std::io; -use bstr::{BStr, BString}; +use bstr::ByteSlice; /// The default buffer capacity that we use for the line buffer. pub(crate) const DEFAULT_BUFFER_CAPACITY: usize = 8 * (1<<10); // 8 KB @@ -122,7 +122,7 @@ impl LineBufferBuilder { pub fn build(&self) -> LineBuffer { LineBuffer { config: self.config, - buf: BString::from(vec![0; self.config.capacity]), + buf: vec![0; self.config.capacity], pos: 0, last_lineterm: 0, end: 0, @@ -254,13 +254,14 @@ impl<'b, R: io::Read> LineBufferReader<'b, R> { /// Return the contents of this buffer. pub fn buffer(&self) -> &[u8] { - self.line_buffer.buffer().as_bytes() + self.line_buffer.buffer() } - /// Return the underlying buffer as a byte string. Used for tests only. + /// Return the buffer as a BStr, used for convenient equality checking + /// in tests only. #[cfg(test)] - fn bstr(&self) -> &BStr { - self.line_buffer.buffer() + fn bstr(&self) -> &::bstr::BStr { + self.buffer().as_bstr() } /// Consume the number of bytes provided. This must be less than or equal @@ -289,7 +290,7 @@ pub struct LineBuffer { /// The configuration of this buffer. config: Config, /// The primary buffer with which to hold data. - buf: BString, + buf: Vec, /// The current position of this buffer. This is always a valid sliceable /// index into `buf`, and its maximum value is the length of `buf`. pos: usize, @@ -352,13 +353,13 @@ impl LineBuffer { } /// Return the contents of this buffer. - fn buffer(&self) -> &BStr { + fn buffer(&self) -> &[u8] { &self.buf[self.pos..self.last_lineterm] } /// Return the contents of the free space beyond the end of the buffer as /// a mutable slice. - fn free_buffer(&mut self) -> &mut BStr { + fn free_buffer(&mut self) -> &mut [u8] { &mut self.buf[self.end..] } @@ -481,7 +482,7 @@ impl LineBuffer { } let roll_len = self.end - self.pos; - self.buf.copy_within(self.pos.., 0); + self.buf.copy_within_str(self.pos.., 0); self.pos = 0; self.last_lineterm = roll_len; self.end = roll_len; @@ -519,7 +520,7 @@ impl LineBuffer { /// Replaces `src` with `replacement` in bytes, and return the offset of the /// first replacement, if one exists. -fn replace_bytes(bytes: &mut BStr, src: u8, replacement: u8) -> Option { +fn replace_bytes(bytes: &mut [u8], src: u8, replacement: u8) -> Option { if src == replacement { return None; } @@ -542,7 +543,7 @@ fn replace_bytes(bytes: &mut BStr, src: u8, replacement: u8) -> Option { #[cfg(test)] mod tests { use std::str; - use bstr::BString; + use bstr::{ByteSlice, ByteVec}; use super::*; const SHERLOCK: &'static str = "\ @@ -563,7 +564,7 @@ and exhibited clearly, with a label attached.\ src: u8, replacement: u8, ) -> (String, Option) { - let mut dst = BString::from(slice); + let mut dst = Vec::from(slice); let result = replace_bytes(&mut dst, src, replacement); (dst.into_string().unwrap(), result) } @@ -677,12 +678,12 @@ and exhibited clearly, with a label attached.\ let mut linebuf = LineBufferBuilder::new().capacity(1).build(); let mut rdr = LineBufferReader::new(bytes.as_bytes(), &mut linebuf); - let mut got = BString::new(); + let mut got = vec![]; while rdr.fill().unwrap() { - got.push(rdr.buffer()); + got.push_str(rdr.buffer()); rdr.consume_all(); } - assert_eq!(bytes, got); + assert_eq!(bytes, got.as_bstr()); assert_eq!(rdr.absolute_byte_offset(), bytes.len() as u64); assert_eq!(rdr.binary_byte_offset(), None); } diff --git a/grep-searcher/src/lines.rs b/grep-searcher/src/lines.rs index a32f6b72..57680b40 100644 --- a/grep-searcher/src/lines.rs +++ b/grep-searcher/src/lines.rs @@ -2,7 +2,7 @@ A collection of routines for performing operations on lines. */ -use bstr::B; +use bstr::ByteSlice; use bytecount; use grep_matcher::{LineTerminator, Match}; @@ -85,7 +85,7 @@ impl LineStep { #[inline(always)] fn next_impl(&mut self, mut bytes: &[u8]) -> Option<(usize, usize)> { bytes = &bytes[..self.end]; - match B(&bytes[self.pos..]).find_byte(self.line_term) { + match bytes[self.pos..].find_byte(self.line_term) { None => { if self.pos < bytes.len() { let m = (self.pos, bytes.len()); @@ -135,14 +135,14 @@ pub fn locate( line_term: u8, range: Match, ) -> Match { - let line_start = B(&bytes[..range.start()]) + let line_start = bytes[..range.start()] .rfind_byte(line_term) .map_or(0, |i| i + 1); let line_end = if range.end() > line_start && bytes[range.end() - 1] == line_term { range.end() } else { - B(&bytes[range.end()..]) + bytes[range.end()..] .find_byte(line_term) .map_or(bytes.len(), |i| range.end() + i + 1) }; @@ -182,7 +182,7 @@ fn preceding_by_pos( pos -= 1; } loop { - match B(&bytes[..pos]).rfind_byte(line_term) { + match bytes[..pos].rfind_byte(line_term) { None => { return 0; } diff --git a/grep-searcher/src/searcher/core.rs b/grep-searcher/src/searcher/core.rs index dd621bba..d534b663 100644 --- a/grep-searcher/src/searcher/core.rs +++ b/grep-searcher/src/searcher/core.rs @@ -1,6 +1,6 @@ use std::cmp; -use bstr::B; +use bstr::ByteSlice; use grep_matcher::{LineMatchKind, Matcher}; use lines::{self, LineStep}; @@ -161,7 +161,7 @@ impl<'s, M: Matcher, S: Sink> Core<'s, M, S> { BinaryDetection::Convert(b) => b, _ => return Ok(false), }; - if let Some(i) = B(&buf[*range]).find_byte(binary_byte) { + if let Some(i) = buf[*range].find_byte(binary_byte) { let offset = range.start() + i; self.binary_byte_offset = Some(offset); if !self.binary_data(offset as u64)? { diff --git a/grep-searcher/src/testutil.rs b/grep-searcher/src/testutil.rs index 416e4e32..ec7e29ba 100644 --- a/grep-searcher/src/testutil.rs +++ b/grep-searcher/src/testutil.rs @@ -1,7 +1,7 @@ use std::io::{self, Write}; use std::str; -use bstr::B; +use bstr::ByteSlice; use grep_matcher::{ LineMatchKind, LineTerminator, Match, Matcher, NoCaptures, NoError, }; @@ -94,7 +94,7 @@ impl Matcher for RegexMatcher { } // Make it interesting and return the last byte in the current // line. - let i = B(haystack) + let i = haystack .find_byte(self.line_term.unwrap().as_byte()) .map(|i| i) .unwrap_or(haystack.len() - 1); diff --git a/grep/examples/simplegrep.rs b/grep/examples/simplegrep.rs index 85e2f778..37b6a0c4 100644 --- a/grep/examples/simplegrep.rs +++ b/grep/examples/simplegrep.rs @@ -21,7 +21,7 @@ fn main() { } } -fn try_main() -> Result<(), Box> { +fn try_main() -> Result<(), Box> { let mut args: Vec = env::args_os().collect(); if args.len() < 2 { return Err("Usage: simplegrep [ ...]".into()); @@ -32,7 +32,7 @@ fn try_main() -> Result<(), Box> { search(cli::pattern_from_os(&args[1])?, &args[2..]) } -fn search(pattern: &str, paths: &[OsString]) -> Result<(), Box> { +fn search(pattern: &str, paths: &[OsString]) -> Result<(), Box> { let matcher = RegexMatcher::new_line_matcher(&pattern)?; let mut searcher = SearcherBuilder::new() .binary_detection(BinaryDetection::quit(b'\x00')) diff --git a/src/config.rs b/src/config.rs index f0f7929c..3deade9a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,7 @@ use std::io; use std::ffi::OsString; use std::path::{Path, PathBuf}; -use bstr::io::BufReadExt; +use bstr::{io::BufReadExt, ByteSlice}; use log; use crate::Result;