feat: add negative start support and validate index in String.indexOf(_,_)
Simplify arithmetic in wrenStringFind by removing startIndex offset from loop range and using start directly as the initial index. Rename internal primitives to string_indexOf1 and string_indexOf2 for clarity. Add validateIndex helper to clamp negative start values and reject out-of-bounds indices. Update documentation to describe the new start parameter behavior. Add comprehensive test suite for indexOf with start, including negative offsets, edge cases, and error conditions.
This commit is contained in:
@@ -120,6 +120,15 @@ Returns the index of the first byte matching `search` in the string or `-1` if
|
||||
|
||||
It is a runtime error if `search` is not a string.
|
||||
|
||||
### **indexOf**(search, start)
|
||||
|
||||
Returns the index of the first byte matching `search` in the string or `-1` if
|
||||
`search` was not found, starting a byte offset `start`. The start can be
|
||||
negative to count backwards from the end of the string.
|
||||
|
||||
It is a runtime error if `search` is not a string or `start` is not an integer
|
||||
index within the string's byte length.
|
||||
|
||||
### **iterate**(iterator), **iteratorValue**(iterator)
|
||||
|
||||
Implements the [iterator protocol](../../control-flow.html#the-iterator-protocol)
|
||||
|
||||
Reference in New Issue
Block a user