diff options
author | Andrew Gallant <jamslam@gmail.com> | 2018-09-07 11:56:30 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-09-07 12:06:04 -0400 |
commit | 56e8864426229de7b181c141baddf788c22b4925 (patch) | |
tree | b46d71c5ac47d185abdfc2d26058dba25b625a19 /grep-matcher | |
parent | b8f619d16ef82f2d9e77374f8db762318c0a2bf6 (diff) |
grep-matcher: add LineTerminator::is_suffix
This centralizes the logic for checking whether a line has a line
terminator or not.
Diffstat (limited to 'grep-matcher')
-rw-r--r-- | grep-matcher/src/lib.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/grep-matcher/src/lib.rs b/grep-matcher/src/lib.rs index 49d6358f..9a067efa 100644 --- a/grep-matcher/src/lib.rs +++ b/grep-matcher/src/lib.rs @@ -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 { |