1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-06-25 14:22:54 +02:00

Update to regex 0.2.

This commit is contained in:
Andrew Gallant
2016-12-30 16:24:09 -05:00
parent d58236fbdc
commit 163e00677a
14 changed files with 335 additions and 61 deletions

View File

@ -473,7 +473,7 @@ impl<'a> ArgMatches<'a> {
/// unchanged.
fn literal_pattern(&self, pat: String) -> String {
if self.is_present("fixed-strings") {
regex::quote(&pat)
regex::escape(&pat)
} else {
pat
}

View File

@ -210,15 +210,20 @@ impl<W: WriteColor> Printer<W> {
let column =
if self.column {
Some(re.find(&buf[start..end])
.map(|(s, _)| s).unwrap_or(0) as u64)
.map(|m| m.start()).unwrap_or(0) as u64)
} else {
None
};
return self.write_match(
re, path, buf, start, end, line_number, column);
}
for (s, _) in re.find_iter(&buf[start..end]) {
let column = if self.column { Some(s as u64) } else { None };
for m in re.find_iter(&buf[start..end]) {
let column =
if self.column {
Some(m.start() as u64)
} else {
None
};
self.write_match(
re, path.as_ref(), buf, start, end, line_number, column);
}
@ -265,12 +270,12 @@ impl<W: WriteColor> Printer<W> {
return;
}
let mut last_written = 0;
for (s, e) in re.find_iter(buf) {
self.write(&buf[last_written..s]);
for m in re.find_iter(buf) {
self.write(&buf[last_written..m.start()]);
let _ = self.wtr.set_color(self.colors.matched());
self.write(&buf[s..e]);
self.write(&buf[m.start()..m.end()]);
let _ = self.wtr.reset();
last_written = e;
last_written = m.end();
}
self.write(&buf[last_written..]);
}