Crate naive_opt[−][src]
The optimized naive string-search algorithm.
- Enhanced with 1-byte search like the libc++ and the libstd++ string::find
- Specializing in UTF-8 strings, which is a feature of rust
- Support the zero overhead trait.
Examples
Example function:
use naive_opt::{string_search, string_rsearch}; use naive_opt::{string_search_indices, string_rsearch_indices}; let haystack = "111 a 111b"; let needle = "a"; let r = string_search(haystack, needle); assert_eq!(r, Some(4)); assert_eq!(string_search(haystack, "1"), Some(0)); assert_eq!(string_rsearch(haystack, "1"), Some(8)); let v: Vec<_> = string_search_indices("abc345abc901abc", "abc").collect(); assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); let v: Vec<_> = string_rsearch_indices("abc345abc901abc", "abc").collect(); assert_eq!(v, [(12, "abc"), (6, "abc"), (0, "abc")]);
Example trait: Search
use naive_opt::Search; let haystack = "111 a 111b"; let needle = "a"; let r = haystack.search(needle); assert_eq!(r, Some(4)); assert_eq!(haystack.search("1"), Some(0)); assert_eq!(haystack.rsearch("1"), Some(8)); let v: Vec<_> = "abc345abc901abc".search_indices("abc").collect(); assert_eq!(v, [(0, "abc"), (6, "abc"), (12, "abc")]); let v: Vec<_> = "abc345abc901abc".rsearch_indices("abc").collect(); assert_eq!(v, [(12, "abc"), (6, "abc"), (0, "abc")]);
Example trait: SearchIn
use naive_opt::SearchIn; let haystack = "111 a 111b"; let needle = "a"; let r = needle.search_in(haystack); assert_eq!(r, Some(4)); assert_eq!("1".search_in(haystack), Some(0)); assert_eq!("1".rsearch_in(haystack), Some(8));
Structs
RevSearchIndices | Created with the method Search::rsearch_indices(). |
RevSearchIndicesBytes | |
SearchIndices | Created with the method Search::search_indices(). |
SearchIndicesBytes |
Traits
Search | search the needle |
SearchBytes | |
SearchIn | search in the haystack |
SearchInBytes |
Functions
string_rsearch | reverse search the needle in the haystack |
string_rsearch_bytes | reverse search the needle in the haystack bytes |
string_rsearch_indices | An reverse search iterator over the matches of the needle in the haystack. |
string_rsearch_indices_bytes | |
string_search | search the needle in the haystack |
string_search_bytes | search the needle in the haystack bytes |
string_search_indices | An iterator over the matches of the needle in the haystack. |
string_search_indices_bytes |