Warning, /firebird/firebird-ng/src/app/utils/wildcard.ts is written in an unsupported language. File is not indexed.
0001
0002 export function wildCardCheck(source: string, pattern: string): boolean {
0003 let cp = 0;
0004 let mp = 0;
0005 let patternIndex = 0;
0006 let sourceIndex = 0;
0007
0008 while (sourceIndex < source.length && pattern[patternIndex] !== '*') {
0009 if (pattern[patternIndex] !== source[sourceIndex] && pattern[patternIndex] !== '?') {
0010 return false;
0011 }
0012 patternIndex++;
0013 sourceIndex++;
0014 }
0015
0016 while (sourceIndex < source.length) {
0017 if (pattern[patternIndex] === '*') {
0018 if (++patternIndex === pattern.length) {
0019 return true;
0020 }
0021 mp = patternIndex;
0022 cp = sourceIndex + 1;
0023 } else if (pattern[patternIndex] === source[sourceIndex] || pattern[patternIndex] === '?') {
0024 patternIndex++;
0025 sourceIndex++;
0026 } else {
0027 if (cp > source.length) return false; // Avoid accessing source out of bounds
0028 patternIndex = mp;
0029 sourceIndex = cp++;
0030 }
0031 }
0032
0033 while (patternIndex < pattern.length && pattern[patternIndex] === '*') {
0034 patternIndex++;
0035 }
0036
0037 return patternIndex === pattern.length;
0038 }