#string #overlap #str #intersection

no-std str_overlap

Methods for finding the overlap between two string slices

7 unstable releases (3 breaking)

Uses old Rust 2015

0.4.3 Feb 4, 2021
0.4.2 Feb 4, 2021
0.4.1 Jan 31, 2021
0.3.0 Jan 28, 2021
0.1.1 Oct 17, 2020

#1221 in Text processing

Download history 109/week @ 2024-07-20 177/week @ 2024-07-27 72/week @ 2024-08-03 89/week @ 2024-08-10 86/week @ 2024-08-17 68/week @ 2024-08-24 233/week @ 2024-08-31 56/week @ 2024-09-07 46/week @ 2024-09-14 43/week @ 2024-09-21 73/week @ 2024-09-28 54/week @ 2024-10-05 97/week @ 2024-10-12 130/week @ 2024-10-19 134/week @ 2024-10-26 98/week @ 2024-11-02

462 downloads per month
Used in 3 crates

MIT/Apache

13KB
127 lines

str_overlap

GitHub Workflow Status codecov.io Crates.io Docs.rs MSRV License

This crate provides methods for finding the overlap between two string slices.

An overlap is here defined as the largest substring contained both at the end of one string slice and the beginning of another string slice.

Usage

To use this crate, bring the Overlap trait into scope. This will provide strs with two methods:

  • overlap_start - Finds the overlap at the start of the string slice and the end of another.
  • overlap_end - Finds the overlap at the end of the string slice and the start of another.
use str_overlap::Overlap;

assert_eq!("bcd".overlap_start("abc"), "bc");
assert_eq!("abc".overlap_end("bcd"), "bc");

The return value of these methods is a string slice, borrowed from the string the method is called on. The two methods allows the caller to choose who owns the resulting string slice.

To use this crate, call the provided overlap function with two string slices in the left and right positions.

use str_overlap::overlap;

assert_eq!(overlap("abc", "bcd"), "bc");

Note that the positions of the string slices matter. The overlap found is the largest substring at both the end of the left string slice and the beginning of the right string slice.

Performance

The overlap function has temporal complexity O(n) in the worst case (where no overlap is found), where n is the length of the first string parameter.

Minimum Supported Rust Version

This crate is guaranteed to compile on stable rustc 1.0.0 and up.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps