mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2024-12-12 19:18:24 +02:00
grep-matcher: add LineTerminator::is_suffix
This centralizes the logic for checking whether a line has a line terminator or not.
This commit is contained in:
parent
b8f619d16e
commit
56e8864426
@ -266,6 +266,16 @@ impl LineTerminator {
|
||||
LineTerminatorImp::CRLF => &[b'\r', b'\n'],
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if and only if the given slice ends with this line
|
||||
/// terminator.
|
||||
///
|
||||
/// If this line terminator is `CRLF`, then this only checks whether the
|
||||
/// last byte is `\n`.
|
||||
#[inline]
|
||||
pub fn is_suffix(&self, slice: &[u8]) -> bool {
|
||||
slice.last().map_or(false, |&b| b == self.as_byte())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for LineTerminator {
|
||||
|
@ -1396,7 +1396,7 @@ impl<'a, M: Matcher, W: WriteColor> StandardImpl<'a, M, W> {
|
||||
}
|
||||
|
||||
fn has_line_terminator(&self, buf: &[u8]) -> bool {
|
||||
buf.last() == Some(&self.searcher.line_terminator().as_byte())
|
||||
self.searcher.line_terminator().is_suffix(buf)
|
||||
}
|
||||
|
||||
fn is_context(&self) -> bool {
|
||||
|
Loading…
Reference in New Issue
Block a user