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

Function rfind

rust/stringzilla.rs:1371–1389  ·  view source on GitHub ↗
(haystack: H, needle: N)

Source from the content-addressed store, hash-verified

1369/// within `haystack` if found, otherwise `None`.
1370#[inline(always)]
1371pub fn rfind<H, N>(haystack: H, needle: N) -> Option<usize>
1372where
1373 H: AsRef<[u8]>,
1374 N: AsRef<[u8]>,
1375{
1376 let haystack_ref = haystack.as_ref();
1377 let needle_ref = needle.as_ref();
1378 let haystack_pointer = haystack_ref.as_ptr() as _;
1379 let haystack_length = haystack_ref.len();
1380 let needle_pointer = needle_ref.as_ptr() as _;
1381 let needle_length = needle_ref.len();
1382 let result = unsafe { sz_rfind(haystack_pointer, haystack_length, needle_pointer, needle_length) };
1383
1384 if result.is_null() {
1385 None
1386 } else {
1387 Some(unsafe { result.offset_from(haystack_pointer) }.try_into().unwrap())
1388 }
1389}
1390
1391/// Finds the index of the first character in `haystack` that is also present in `needles`.
1392/// This function is particularly useful for parsing and tokenization tasks where a set of

Callers 5

try_replace_allFunction · 0.85
findMethod · 0.85
sz_rfindMethod · 0.85
rfindMethod · 0.85
rpartition_Method · 0.85

Calls 3

as_ptrMethod · 0.80
lenMethod · 0.80
sz_rfindFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…