You are writing a simple text editor, and one of the features you need to implement is a text search. Given a pattern, the search mechanism should return the position of its first occurrence, starting from the current position, or indicate that the pattern cannot be found. Searches are case sensitive, and do not wrap. The search dialog contains a text box and a checkbox labeled "Whole Word". When the "Whole Word" option is selected, the matched sequence must either be preceded by a space to its left or be at the very beginning of the text. Similarly, it must also either be followed by a space to its right or be at the very end of the text.
You are given a String text consisting of letters and spaces.
You are also given a String search, a sequence of letters representing the search pattern, and a String wholeWord, which is either "Y" or "N", indicating whether or not the "Whole Word" option is checked. An int start represents the current position in the text from where you start searching.
Return the index of the first match, or -1 if there is none. The index of the match here means the index of its first character. Both the starting index and the return index are zero based.