| 665 | } |
| 666 | |
| 667 | bool Token::Match(const Token *tok, const char pattern[], nonneg int varid) |
| 668 | { |
| 669 | if (!(*pattern)) |
| 670 | return true; |
| 671 | |
| 672 | const char *p = pattern; |
| 673 | while (true) { |
| 674 | // Skip spaces in pattern.. |
| 675 | while (*p == ' ') |
| 676 | ++p; |
| 677 | |
| 678 | // No token => Success! |
| 679 | if (*p == '\0') |
| 680 | break; |
| 681 | |
| 682 | if (!tok) { |
| 683 | // If we have no tokens, pattern "!!else" should return true |
| 684 | if (p[0] == '!' && p[1] == '!' && p[2] != '\0') { |
| 685 | while (*p && *p != ' ') |
| 686 | ++p; |
| 687 | continue; |
| 688 | } |
| 689 | |
| 690 | return false; |
| 691 | } |
| 692 | |
| 693 | // [.. => search for a one-character token.. |
| 694 | if (p[0] == '[' && chrInFirstWord(p, ']')) { |
| 695 | if (tok->str().length() != 1) |
| 696 | return false; |
| 697 | |
| 698 | const char *temp = p+1; |
| 699 | bool chrFound = false; |
| 700 | int count = 0; |
| 701 | while (*temp && *temp != ' ') { |
| 702 | if (*temp == ']') { |
| 703 | ++count; |
| 704 | } |
| 705 | |
| 706 | else if (*temp == tok->str()[0]) { |
| 707 | chrFound = true; |
| 708 | break; |
| 709 | } |
| 710 | |
| 711 | ++temp; |
| 712 | } |
| 713 | |
| 714 | if (count > 1 && tok->str()[0] == ']') |
| 715 | chrFound = true; |
| 716 | |
| 717 | if (!chrFound) |
| 718 | return false; |
| 719 | |
| 720 | p = temp; |
| 721 | } |
| 722 | |
| 723 | // Parse "not" options. Token can be anything except the given one |
| 724 | else if (p[0] == '!' && p[1] == '!' && p[2] != '\0') { |
nothing calls this directly
no test coverage detected