feat: add string indexOf with startIndex parameter and update wrenStringFind signature

Add a new primitive `string_indexOf_with_startIndex` that accepts a second integer argument to specify the starting position for the search. Modify the existing `wrenStringFind` function to accept a `startIndex` parameter, updating its Boyer-Moore-Horspool algorithm to begin scanning from the given offset. Update the `string_contains` primitive to pass `0` as the start index. Register the new overloaded method as `indexOf(_,_)` on the string class and add test cases covering boundary conditions and out-of-range start indices.
This commit is contained in:
underscorediscovery
2016-07-14 03:53:01 +00:00
parent 4d1215697e
commit 0b1a3cc3e5
4 changed files with 31 additions and 9 deletions
+6
View File
@@ -5,6 +5,12 @@ System.print("abcd".indexOf("abcd")) // expect: 0
System.print("abcd".indexOf("abcde")) // expect: -1
System.print("abab".indexOf("ab")) // expect: 0
System.print("abcd".indexOf("cd", 0)) // expect: 2
System.print("abcd".indexOf("cd", 1)) // expect: 2
System.print("abcd".indexOf("cd", 2)) // expect: 2
System.print("abcd".indexOf("cd", 3)) // expect: -1
System.print("abcd".indexOf("cd", 10)) // expect: -1
// More complex cases.
System.print("abcdefabcdefg".indexOf("defg")) // expect: 9
System.print("abcdabcdabcd".indexOf("dab")) // expect: 3