Skip to content

Commit

Permalink
doc: tweak docs for 'shortest_match'
Browse files Browse the repository at this point in the history
The name is somewhat unfortunate, but it's actually kind of difficult to
capture the right semantics in the name. The key bit is that the
function returns the offset at the point at which a match is known, and
that point might vary depending on which internal regex engine was used.

Fixes #747
  • Loading branch information
BurntSushi committed Mar 6, 2023
1 parent 81f54f6 commit 6597802
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/re_bytes.rs
Expand Up @@ -549,7 +549,14 @@ impl Regex {
/// This method may have the same performance characteristics as
/// `is_match`, except it provides an end location for a match. In
/// particular, the location returned *may be shorter* than the proper end
/// of the leftmost-first match.
/// of the leftmost-first match that you would find via `Regex::find`.
///
/// Note that it is not guaranteed that this routine finds the shortest or
/// "earliest" possible match. Instead, the main idea of this API is that
/// it returns the offset at the point at which the internal regex engine
/// has determined that a match has occurred. This may vary depending on
/// which internal regex engine is used, and thus, the offset itself may
/// change.
///
/// # Example
///
Expand Down
17 changes: 12 additions & 5 deletions src/re_unicode.rs
Expand Up @@ -607,7 +607,14 @@ impl Regex {
/// This method may have the same performance characteristics as
/// `is_match`, except it provides an end location for a match. In
/// particular, the location returned *may be shorter* than the proper end
/// of the leftmost-first match.
/// of the leftmost-first match that you would find via `Regex::find`.
///
/// Note that it is not guaranteed that this routine finds the shortest or
/// "earliest" possible match. Instead, the main idea of this API is that
/// it returns the offset at the point at which the internal regex engine
/// has determined that a match has occurred. This may vary depending on
/// which internal regex engine is used, and thus, the offset itself may
/// change.
///
/// # Example
///
Expand All @@ -627,12 +634,12 @@ impl Regex {
self.shortest_match_at(text, 0)
}

/// Returns the same as shortest_match, but starts the search at the given
/// offset.
/// Returns the same as `shortest_match`, but starts the search at the
/// given offset.
///
/// The significance of the starting point is that it takes the surrounding
/// context into consideration. For example, the `\A` anchor can only
/// match when `start == 0`.
/// context into consideration. For example, the `\A` anchor can only match
/// when `start == 0`.
pub fn shortest_match_at(
&self,
text: &str,
Expand Down

0 comments on commit 6597802

Please sign in to comment.