MCPcopy Create free account
hub / github.com/ampproject/amphtml / handleMatch

Function handleMatch

third_party/inputmask/inputmask.js:851–1059  ·  view source on GitHub ↗
(match, loopNdx, quantifierRecurse)

Source from the content-addressed store, hash-verified

849 var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [ 0 ], matches = [], insertStop = false, latestMatch, cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "";
850 function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) {
851 function handleMatch(match, loopNdx, quantifierRecurse) {
852 function isFirstMatch(latestMatch, tokenGroup) {
853 var firstMatch = $.inArray(latestMatch, tokenGroup.matches) === 0;
854 if (!firstMatch) {
855 $.each(tokenGroup.matches, function(ndx, match) {
856 if (match.isQuantifier === true) firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]); else if (match.hasOwnProperty("matches")) firstMatch = isFirstMatch(latestMatch, match);
857 if (firstMatch) return false;
858 });
859 }
860 return firstMatch;
861 }
862 function resolveNdxInitializer(pos, alternateNdx, targetAlternation) {
863 var bestMatch, indexPos;
864 if (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) {
865 $.each(getMaskSet().tests[pos] || [ getMaskSet().validPositions[pos] ], function(ndx, lmnt) {
866 if (lmnt.mloc[alternateNdx]) {
867 bestMatch = lmnt;
868 return false;
869 }
870 var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation, ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1;
871 if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) {
872 bestMatch = lmnt;
873 indexPos = ndxPos;
874 }
875 });
876 }
877 if (bestMatch) {
878 var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation];
879 var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator;
880 return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1);
881 } else {
882 return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined;
883 }
884 }
885 function isSubsetOf(source, target) {
886 function expand(pattern) {
887 var expanded = [], start, end;
888 for (var i = 0, l = pattern.length; i < l; i++) {
889 if (pattern.charAt(i) === "-") {
890 end = pattern.charCodeAt(i + 1);
891 while (++start < end) expanded.push(String.fromCharCode(start));
892 } else {
893 start = pattern.charCodeAt(i);
894 expanded.push(pattern.charAt(i));
895 }
896 }
897 return expanded.join("");
898 }
899 if (opts.regex && source.match.fn !== null && target.match.fn !== null) {
900 return expand(target.match.def.replace(/[\[\]]/g, "")).indexOf(expand(source.match.def.replace(/[\[\]]/g, ""))) !== -1;
901 }
902 return source.match.def === target.match.nativeDef;
903 }
904 function staticCanMatchDefinition(source, target) {
905 var sloc = source.locator.slice(source.alternation).join(""), tloc = target.locator.slice(target.alternation).join(""), canMatch = sloc == tloc;
906 canMatch = canMatch && source.match.fn === null && target.match.fn !== null ? target.match.fn.test(source.match.def, getMaskSet(), pos, false, opts, false) : false;
907 return canMatch;
908 }

Callers 1

resolveTestFromTokenFunction · 0.85

Calls 11

getMaskSetFunction · 0.85
resolveTestFromTokenFunction · 0.85
isFirstMatchFunction · 0.85
resolveNdxInitializerFunction · 0.85
setMergeLocatorsFunction · 0.85
isSubsetOfFunction · 0.85
staticCanMatchDefinitionFunction · 0.85
concatMethod · 0.80
pushMethod · 0.45
reverseMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected