* Checks if the given string matches a namespace template, honoring * asterisks as wildcards. * * @param {String} search * @param {String} template * @return {Boolean}
(search, template)
| 190 | * @return {Boolean} |
| 191 | */ |
| 192 | function matchesTemplate(search, template) { |
| 193 | let searchIndex = 0; |
| 194 | let templateIndex = 0; |
| 195 | let starIndex = -1; |
| 196 | let matchIndex = 0; |
| 197 | |
| 198 | while (searchIndex < search.length) { |
| 199 | if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) { |
| 200 | // Match character or proceed with wildcard |
| 201 | if (template[templateIndex] === '*') { |
| 202 | starIndex = templateIndex; |
| 203 | matchIndex = searchIndex; |
| 204 | templateIndex++; // Skip the '*' |
| 205 | } else { |
| 206 | searchIndex++; |
| 207 | templateIndex++; |
| 208 | } |
| 209 | } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition |
| 210 | // Backtrack to the last '*' and try to match more characters |
| 211 | templateIndex = starIndex + 1; |
| 212 | matchIndex++; |
| 213 | searchIndex = matchIndex; |
| 214 | } else { |
| 215 | return false; // No match |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // Handle trailing '*' in template |
| 220 | while (templateIndex < template.length && template[templateIndex] === '*') { |
| 221 | templateIndex++; |
| 222 | } |
| 223 | |
| 224 | return templateIndex === template.length; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Disable debug output. |
no outgoing calls
no test coverage detected
searching dependent graphs…