| 12335 | |
| 12336 | |
| 12337 | LPTSTR RegExMatch(LPTSTR aHaystack, LPTSTR aNeedleRegEx) |
| 12338 | // Returns NULL if no match. Otherwise, returns the address where the pattern was found in aHaystack. |
| 12339 | { |
| 12340 | pcret_extra *extra; |
| 12341 | pcret *re; |
| 12342 | |
| 12343 | // Compile the regex or get it from cache. |
| 12344 | if ( !(re = get_compiled_regex(aNeedleRegEx, extra, NULL, NULL)) ) // Compiling problem. |
| 12345 | return NULL; // Our callers just want there to be "no match" in this case. |
| 12346 | |
| 12347 | // Set up the offset array, which consists of int-pairs containing the start/end offset of each match. |
| 12348 | // For simplicity, use a fixed size because even if it's too small (unlikely for our types of callers), |
| 12349 | // PCRE will still operate properly (though it returns 0 to indicate the too-small condition). |
| 12350 | #define RXM_INT_COUNT 30 // Should be a multiple of 3. |
| 12351 | int offset[RXM_INT_COUNT]; |
| 12352 | |
| 12353 | // Execute the regex. |
| 12354 | int captured_pattern_count = pcret_exec(re, extra, aHaystack, (int)_tcslen(aHaystack), 0, 0, offset, RXM_INT_COUNT); |
| 12355 | if (captured_pattern_count < 0) // PCRE_ERROR_NOMATCH or some kind of error. |
| 12356 | return NULL; |
| 12357 | |
| 12358 | // Otherwise, captured_pattern_count>=0 (it's 0 when offset[] was too small; but that's harmless in this case). |
| 12359 | return aHaystack + offset[0]; // Return the position of the entire-pattern match. |
| 12360 | } |
| 12361 | |
| 12362 | |
| 12363 |
no test coverage detected