| 2536 | */ |
| 2537 | |
| 2538 | bool String::Match(const char* pattern) const |
| 2539 | { |
| 2540 | if (m_sharedString->size == 0 || !pattern) |
| 2541 | return false; |
| 2542 | |
| 2543 | // Par Jack Handy - akkhandy@hotmail.com |
| 2544 | // From : http://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing |
| 2545 | const char* str = m_sharedString->string.get(); |
| 2546 | while (*str && *pattern != '*') |
| 2547 | { |
| 2548 | if (*pattern != *str && *pattern != '?') |
| 2549 | return false; |
| 2550 | |
| 2551 | pattern++; |
| 2552 | str++; |
| 2553 | } |
| 2554 | |
| 2555 | const char* cp = nullptr; |
| 2556 | const char* mp = nullptr; |
| 2557 | while (*str) |
| 2558 | { |
| 2559 | if (*pattern == '*') |
| 2560 | { |
| 2561 | if (!*++pattern) |
| 2562 | return true; |
| 2563 | |
| 2564 | mp = pattern; |
| 2565 | cp = str+1; |
| 2566 | } |
| 2567 | else if (*pattern == *str || *pattern == '?') |
| 2568 | { |
| 2569 | pattern++; |
| 2570 | str++; |
| 2571 | } |
| 2572 | else |
| 2573 | { |
| 2574 | pattern = mp; |
| 2575 | str = cp++; |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | while (*pattern == '*') |
| 2580 | pattern++; |
| 2581 | |
| 2582 | return !*pattern; |
| 2583 | } |
| 2584 | |
| 2585 | /*! |
| 2586 | * \brief Checks whether the string matches the pattern |
no outgoing calls
no test coverage detected