Skip to content

Commit 81f54f6

Browse files
committed
api: add Match::{is_empty, len}
Adding these methods has almost no cost and they can be convenient to have in some cases. Closes #810
1 parent 1b38db8 commit 81f54f6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/re_bytes.rs

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ impl<'t> Match<'t> {
3737
self.end
3838
}
3939

40+
/// Returns true if and only if this match has a length of zero.
41+
#[inline]
42+
pub fn is_empty(&self) -> bool {
43+
self.start == self.end
44+
}
45+
46+
/// Returns the length, in bytes, of this match.
47+
#[inline]
48+
pub fn len(&self) -> usize {
49+
self.end - self.start
50+
}
51+
4052
/// Returns the range over the starting and ending byte offsets of the
4153
/// match in the haystack.
4254
#[inline]

src/re_unicode.rs

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ impl<'t> Match<'t> {
4545
self.end
4646
}
4747

48+
/// Returns true if and only if this match has a length of zero.
49+
#[inline]
50+
pub fn is_empty(&self) -> bool {
51+
self.start == self.end
52+
}
53+
54+
/// Returns the length, in bytes, of this match.
55+
#[inline]
56+
pub fn len(&self) -> usize {
57+
self.end - self.start
58+
}
59+
4860
/// Returns the range over the starting and ending byte offsets of the
4961
/// match in the haystack.
5062
#[inline]

0 commit comments

Comments
 (0)