mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-11 14:30:24 +02:00
search: migrate to bstr
This is an initial attempt at migrating grep-searcher to use the new bstr crate (not yet published). This is mostly an improvement, although a significant problem is that the grep-matcher crate controls the `Index` impls for the `Match` type, which we use quite heavily. Thus, in order to impl `Index` for `BStr`, we need add bstr as a public dependency to grep-matcher. This is really bad news because grep-matcher is supposed to be a light-weight core crate that defines a matcher interface, which is itself intended to be a public dependency. Thus, a semver bump on bstr will have very undesirable ripple effects thoughout ripgrep's library crates. This would be something we could stomach if bstr was solid at 1.0 and committed to avoiding breaking changes. But it's not there yet.
This commit is contained in:
@ -13,8 +13,11 @@ keywords = ["regex", "pattern", "trait"]
|
||||
license = "Unlicense/MIT"
|
||||
autotests = false
|
||||
|
||||
[dependencies]
|
||||
memchr = "2.1"
|
||||
[dependencies.bstr]
|
||||
version = "*"
|
||||
path = "/home/andrew/rust/bstr"
|
||||
default-features = false
|
||||
features = ["std"]
|
||||
|
||||
[dev-dependencies]
|
||||
regex = "1.1"
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::str;
|
||||
|
||||
use memchr::memchr;
|
||||
use bstr::B;
|
||||
|
||||
/// Interpolate capture references in `replacement` and write the interpolation
|
||||
/// result to `dst`. References in `replacement` take the form of $N or $name,
|
||||
@ -22,7 +22,7 @@ pub fn interpolate<A, N>(
|
||||
N: FnMut(&str) -> Option<usize>
|
||||
{
|
||||
while !replacement.is_empty() {
|
||||
match memchr(b'$', replacement) {
|
||||
match B(replacement).find_byte(b'$') {
|
||||
None => break,
|
||||
Some(i) => {
|
||||
dst.extend(&replacement[..i]);
|
||||
|
@ -38,13 +38,15 @@ implementations.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
extern crate memchr;
|
||||
extern crate bstr;
|
||||
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::ops;
|
||||
use std::u64;
|
||||
|
||||
use bstr::BStr;
|
||||
|
||||
use interpolate::interpolate;
|
||||
|
||||
mod interpolate;
|
||||
@ -180,6 +182,22 @@ impl ops::IndexMut<Match> for [u8] {
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Index<Match> for BStr {
|
||||
type Output = BStr;
|
||||
|
||||
#[inline]
|
||||
fn index(&self, index: Match) -> &BStr {
|
||||
&self[index.start..index.end]
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::IndexMut<Match> for BStr {
|
||||
#[inline]
|
||||
fn index_mut(&mut self, index: Match) -> &mut BStr {
|
||||
&mut self[index.start..index.end]
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Index<Match> for str {
|
||||
type Output = str;
|
||||
|
||||
|
Reference in New Issue
Block a user