Byte Search
- vernamveil.find(haystack, needle, start=0, end=None)
Finds the first occurrence of needle in haystack[start:end] using the fast C byte search, or Python fallback.
- Return type:
int
- Parameters:
haystack (bytes or bytearray or memoryview) – The bytes object to search within.
needle (bytes or bytearray or memoryview) – The bytes object to search for.
start (int) – The starting index to search from. Defaults to 0.
end (int, optional) – The ending index (exclusive) to search to. Defaults to None (end of haystack).
- Returns:
The 0-based starting index of the first occurrence, or -1 if not found.
- Return type:
int
- vernamveil.find_all(haystack, needle)
Finds all occurrences of needle in haystack using a fast byte search algorithm.
- Return type:
list
[int
]- Parameters:
haystack (bytes or bytearray or memoryview) – The bytes object to search within.
needle (bytes or bytearray or memoryview) – The bytes object to search for.
- Returns:
- A list of 0-based starting indices of all occurrences. Returns an empty list if
no occurrences are found or if the pattern is empty or longer than the text.
- Return type:
list[int]