Skip to content

Commit

Permalink
doc: add examples using an empty byteset
Browse files Browse the repository at this point in the history
This doesn't change any behavior (I was wrong in #87), but instead
clarifies that empty bytesets are valid and never match anything.

Fixes #87
  • Loading branch information
BurntSushi committed Jul 6, 2022
1 parent 0661cd5 commit 3d6e49f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ext_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,14 +929,17 @@ pub trait ByteSlice: Sealed {
/// assert_eq!(b"foo bar baz".find_byteset(b"zr"), Some(6));
/// assert_eq!(b"foo baz bar".find_byteset(b"bzr"), Some(4));
/// assert_eq!(None, b"foo baz bar".find_byteset(b"\t\n"));
/// // The empty byteset never matches.
/// assert_eq!(None, b"abc".find_byteset(b""));
/// assert_eq!(None, b"".find_byteset(b""));
/// ```
#[inline]
fn find_byteset<B: AsRef<[u8]>>(&self, byteset: B) -> Option<usize> {
byteset::find(self.as_bytes(), byteset.as_ref())
}

/// Returns the index of the first occurrence of a byte that is not a member
/// of the provided set.
/// Returns the index of the first occurrence of a byte that is not a
/// member of the provided set.
///
/// The `byteset` may be any type that can be cheaply converted into a
/// `&[u8]`. This includes, but is not limited to, `&str` and `&[u8]`, but
Expand Down Expand Up @@ -966,6 +969,10 @@ pub trait ByteSlice: Sealed {
/// assert_eq!(b"foo bar baz".find_not_byteset(b"fo "), Some(4));
/// assert_eq!(b"\t\tbaz bar".find_not_byteset(b" \t\r\n"), Some(2));
/// assert_eq!(b"foo\nbaz\tbar".find_not_byteset(b"\t\n"), Some(0));
/// // The negation of the empty byteset matches everything.
/// assert_eq!(Some(0), b"abc".find_not_byteset(b""));
/// // But an empty string never contains anything.
/// assert_eq!(None, b"".find_not_byteset(b""));
/// ```
#[inline]
fn find_not_byteset<B: AsRef<[u8]>>(&self, byteset: B) -> Option<usize> {
Expand Down

0 comments on commit 3d6e49f

Please sign in to comment.