This will look for the next series of charaters (given by the null terminated w) If it finds the string, it will highlight/select it and move the caret to the beginning of the word returns true if it found the string else false
| 225 | // returns true if it found the string |
| 226 | // else false |
| 227 | bool CScriptEditorDlg::FindNext(char *w) { |
| 228 | int index, max; |
| 229 | bool word_found; |
| 230 | bool new_word; |
| 231 | static int start = 0; |
| 232 | |
| 233 | word_found = false; |
| 234 | |
| 235 | // See if this is a new word to look for (as compared to the last searched word) |
| 236 | if (m_LastWord != w) { |
| 237 | m_LastWord = w; |
| 238 | start = 0; |
| 239 | new_word = true; |
| 240 | } else |
| 241 | new_word = false; |
| 242 | |
| 243 | // This will update the m_sScript string so it has the current script in it |
| 244 | UpdateData(); |
| 245 | |
| 246 | // Make a copy of the script to work with |
| 247 | char *text; |
| 248 | text = (char *)mem_malloc(GetScriptLength()); |
| 249 | strcpy(text, GetScript()); |
| 250 | max = GetScriptLength(); |
| 251 | |
| 252 | // Make sure we aren't gonna try to go past the end of the buffer, start at 0 if we are |
| 253 | if (start + (signed)strlen(w) >= max - 1) |
| 254 | start = 0; |
| 255 | |
| 256 | // Here we begin the search |
| 257 | for (index = start; index < max; index++) { |
| 258 | // check the character it's at in the buffer to the first character of the find string, if they are the same |
| 259 | // it's a possibility, so Check the word |
| 260 | if (toupper(text[index]) == toupper(w[0])) |
| 261 | if (CheckWord(index, text, w)) { |
| 262 | // We got a match, so move the caret, and select the word |
| 263 | SetCurrentIndex(index); |
| 264 | SetSelection(index, strlen(w)); |
| 265 | word_found = true; |
| 266 | // adjust start so on the next FindNext() it will start from the next character |
| 267 | start = index + 1; |
| 268 | index = max; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | if (text) |
| 273 | mem_free(text); |
| 274 | |
| 275 | if (!word_found) { |
| 276 | // This can mean 2 things. We searched to the end of the file and either never found a word, or we did at one time |
| 277 | |
| 278 | // either way, start back at the beginning next time |
| 279 | start = 0; |
| 280 | |
| 281 | // if it was a new word then we never found it |
| 282 | if (new_word) { |
| 283 | OutrageMessageBox("Word Not Found!"); |
| 284 | m_LastWord = " "; |
nothing calls this directly
no test coverage detected