* Checks if the given string matches a namespace template, honoring * asterisks as wildcards. * * @param {String} search * @param {String} template * @return {Boolean}
(search, template)
| 2697 | * @return {Boolean} |
| 2698 | */ |
| 2699 | function matchesTemplate(search, template) { |
| 2700 | var searchIndex = 0; |
| 2701 | var templateIndex = 0; |
| 2702 | var starIndex = -1; |
| 2703 | var matchIndex = 0; |
| 2704 | while (searchIndex < search.length) { |
| 2705 | if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) { |
| 2706 | // Match character or proceed with wildcard |
| 2707 | if (template[templateIndex] === '*') { |
| 2708 | starIndex = templateIndex; |
| 2709 | matchIndex = searchIndex; |
| 2710 | templateIndex++; // Skip the '*' |
| 2711 | } else { |
| 2712 | searchIndex++; |
| 2713 | templateIndex++; |
| 2714 | } |
| 2715 | } else if (starIndex !== -1) { |
| 2716 | // eslint-disable-line no-negated-condition |
| 2717 | // Backtrack to the last '*' and try to match more characters |
| 2718 | templateIndex = starIndex + 1; |
| 2719 | matchIndex++; |
| 2720 | searchIndex = matchIndex; |
| 2721 | } else { |
| 2722 | return false; // No match |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | // Handle trailing '*' in template |
| 2727 | while (templateIndex < template.length && template[templateIndex] === '*') { |
| 2728 | templateIndex++; |
| 2729 | } |
| 2730 | return templateIndex === template.length; |
| 2731 | } |
| 2732 | |
| 2733 | /** |
| 2734 | * Disable debug output. |