I might be missing something, but it looks like you are always initializing `this.index_` with 0 and then just increment/decrement it. What if the first match that you find is in the middle of the document? (It can happen since we start from the cursor position.)