Skip to main content

nova_rt_str_index_of

Function nova_rt_str_index_of 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nova_rt_str_index_of( haystack: *const NovaStr, needle: *const NovaStr, ) -> i64
Expand description

The character index of the first occurrence of needle in haystack, or -1: the body of std/strings’ String.index_of and String.contains. An empty needle occurs at 0.

A byte search finds the same first match a character-by-character one would. Both strings are valid UTF-8, and no character starts with a continuation byte, so a byte match can only begin on a character boundary. The characters before the match are then counted to turn its byte offset into a character index. Nothing here allocates, and a miss counts nothing. The Nova-level search this replaces built a [Char] for each string first.

§Safety

haystack and needle must be valid NovaStr pointers.