Skip to content

Commit 9cc85cd

Browse files
committed
doc: tweak docs for 'shortest_match'
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
1 parent b27b143 commit 9cc85cd

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Diff for: src/re_bytes.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,14 @@ impl Regex {
549549
/// This method may have the same performance characteristics as
550550
/// `is_match`, except it provides an end location for a match. In
551551
/// particular, the location returned *may be shorter* than the proper end
552-
/// of the leftmost-first match.
552+
/// of the leftmost-first match that you would find via `Regex::find`.
553+
///
554+
/// Note that it is not guaranteed that this routine finds the shortest or
555+
/// "earliest" possible match. Instead, the main idea of this API is that
556+
/// it returns the offset at the point at which the internal regex engine
557+
/// has determined that a match has occurred. This may vary depending on
558+
/// which internal regex engine is used, and thus, the offset itself may
559+
/// change.
553560
///
554561
/// # Example
555562
///

Diff for: src/re_unicode.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,14 @@ impl Regex {
607607
/// This method may have the same performance characteristics as
608608
/// `is_match`, except it provides an end location for a match. In
609609
/// particular, the location returned *may be shorter* than the proper end
610-
/// of the leftmost-first match.
610+
/// of the leftmost-first match that you would find via `Regex::find`.
611+
///
612+
/// Note that it is not guaranteed that this routine finds the shortest or
613+
/// "earliest" possible match. Instead, the main idea of this API is that
614+
/// it returns the offset at the point at which the internal regex engine
615+
/// has determined that a match has occurred. This may vary depending on
616+
/// which internal regex engine is used, and thus, the offset itself may
617+
/// change.
611618
///
612619
/// # Example
613620
///
@@ -627,12 +634,12 @@ impl Regex {
627634
self.shortest_match_at(text, 0)
628635
}
629636

630-
/// Returns the same as shortest_match, but starts the search at the given
631-
/// offset.
637+
/// Returns the same as `shortest_match`, but starts the search at the
638+
/// given offset.
632639
///
633640
/// The significance of the starting point is that it takes the surrounding
634-
/// context into consideration. For example, the `\A` anchor can only
635-
/// match when `start == 0`.
641+
/// context into consideration. For example, the `\A` anchor can only match
642+
/// when `start == 0`.
636643
pub fn shortest_match_at(
637644
&self,
638645
text: &str,

0 commit comments

Comments
 (0)