Skip to content

Commit

Permalink
api: add Match::{is_empty, len}
Browse files Browse the repository at this point in the history
Adding these methods has almost no cost and they can be convenient to
have in some cases.

Closes #810
  • Loading branch information
BurntSushi committed Mar 15, 2023
1 parent aa54f99 commit 2eb17fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/re_bytes.rs
Expand Up @@ -37,6 +37,18 @@ impl<'t> Match<'t> {
self.end
}

/// Returns true if and only if this match has a length of zero.
#[inline]
pub fn is_empty(&self) -> bool {
self.start == self.end
}

/// Returns the length, in bytes, of this match.
#[inline]
pub fn len(&self) -> usize {
self.end - self.start
}

/// Returns the range over the starting and ending byte offsets of the
/// match in the haystack.
#[inline]
Expand Down
12 changes: 12 additions & 0 deletions src/re_unicode.rs
Expand Up @@ -45,6 +45,18 @@ impl<'t> Match<'t> {
self.end
}

/// Returns true if and only if this match has a length of zero.
#[inline]
pub fn is_empty(&self) -> bool {
self.start == self.end
}

/// Returns the length, in bytes, of this match.
#[inline]
pub fn len(&self) -> usize {
self.end - self.start
}

/// Returns the range over the starting and ending byte offsets of the
/// match in the haystack.
#[inline]
Expand Down

0 comments on commit 2eb17fc

Please sign in to comment.