MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / rfind_byteset

Function rfind_byteset

rust/stringzilla.rs:1434–1448  ·  view source on GitHub ↗

Finds the index of the last character in `haystack` that is also present in `needles`. This can be used to find the last occurrence of any character from a specified set, useful in parsing scenarios such as finding the last delimiter in a string. # Arguments `haystack`: The byte slice to search. `needles`: The set of bytes to search for within the haystack. # Returns An `Option ` represe

(haystack: H, needles: Byteset)

Source from the content-addressed store, hash-verified

1432/// An `Option<usize>` representing the index of the last occurrence of any byte from
1433/// `needles` within `haystack`, if found, otherwise `None`.
1434pub fn rfind_byteset<H>(haystack: H, needles: Byteset) -> Option<usize>
1435where
1436 H: AsRef<[u8]>,
1437{
1438 let haystack_ref = haystack.as_ref();
1439 let haystack_pointer = haystack_ref.as_ptr() as _;
1440 let haystack_length = haystack_ref.len();
1441
1442 let result = unsafe { sz_rfind_byteset(haystack_pointer, haystack_length, &needles as *const _ as *const c_void) };
1443 if result.is_null() {
1444 None
1445 } else {
1446 Some(unsafe { result.offset_from(haystack_pointer) }.try_into().unwrap())
1447 }
1448}
1449
1450/// Finds the index of the first character in `haystack` that is also present in `needles`.
1451/// This function is particularly useful for parsing and tokenization tasks where a set of

Callers 3

rfind_byte_fromFunction · 0.85
rfind_byte_not_fromFunction · 0.85
try_replace_all_bytesetFunction · 0.85

Calls 3

as_ptrMethod · 0.80
lenMethod · 0.80
sz_rfind_bytesetFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…