Fix TwoWaySearcher to work when used with periodic needles.

There is a check in TwoWaySearcher::new to determine whether the needle is periodic. This is needed because during searching when a match fails, we cannot advance the position by the entire length of the needle when it is periodic, but can only advance by the length of the period.

The reason "bananas".contains("nana") (and similar searches) were returning false was because the periodicity check was wrong.

Closes #16589

Also, thanks to @Gankro, who came up with many buggy examples.
Good idea. I've done this in my latest commit.