Skip to main content

str_offset

Function str_offset 

Source
pub fn str_offset(source: &str, substr: &str) -> Option<u32>
Expand description

Return the byte offset of substr within source, or None if not found.

Uses pointer arithmetic when substr is a true sub-slice of source (i.e. arena-allocated names pointing into the same backing string). Falls back to a content search when the pointers differ — this handles tests and callers that pass a differently-allocated copy of the source.

When falling back, prefers matches that are preceded and followed by non-identifier characters (word boundaries), to avoid matching name parts (e.g., finding “B” in “Base” when searching for a class named “B”).