Browse Source

optimize handling of optionals with quantifiers

Robin Herbots 11 years ago
parent
commit
996ddf0520

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "jquery.inputmask",
     "name": "jquery.inputmask",
-    "version": "3.0.6",
+    "version": "3.0.7",
     "main": "./dist/jquery.inputmask.bundle.js",
     "main": "./dist/jquery.inputmask.bundle.js",
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 
 build.major = 3
 build.major = 3
 build.minor = 0
 build.minor = 0
-build.revision = 6
+build.revision = 7
 
 
 target = jquery.inputmask.bundle.js
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js
 target.min = jquery.inputmask.bundle.min.js

BIN
dist/jQuery.InputMask.3.0.5.nupkg


BIN
dist/jQuery.InputMask.3.0.6.nupkg


BIN
dist/jQuery.InputMask.3.0.7.nupkg


+ 9 - 13
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.6
+* Version: 3.0.7
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -244,7 +244,7 @@
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                     } else {
                     } else {
                         var testPos = getTests(pos, ndxIntlzr, pos - 1), firstMatch = testPos[0]["match"];
                         var testPos = getTests(pos, ndxIntlzr, pos - 1), firstMatch = testPos[0]["match"];
-                        testPos = testPos[(minimalPos > pos || (firstMatch.optionalQuantifier !== true && (opts.greedy || (firstMatch.optionality === true && firstMatch.newBlockMarker === false)))) ? 0 : (testPos.length - 1)];
+                        testPos = testPos[(minimalPos > pos || (opts.greedy || (firstMatch.optionality === true && firstMatch.newBlockMarker === false && firstMatch.optionalQuantifier !== true))) ? 0 : (testPos.length - 1)];
                         test = testPos["match"];
                         test = testPos["match"];
                         ndxIntlzr = testPos["locator"].slice();
                         ndxIntlzr = testPos["locator"].slice();
                         maskTemplate.push(test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
                         maskTemplate.push(test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
@@ -351,7 +351,6 @@
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
 
 
                     function handleMatch(match, loopNdx, quantifierRecurse) {
                     function handleMatch(match, loopNdx, quantifierRecurse) {
-                        var currentPos = testPos;
                         if (testPos == pos && match.matches == undefined) {
                         if (testPos == pos && match.matches == undefined) {
                             matches.push({ "match": match, "locator": loopNdx.reverse() });
                             matches.push({ "match": match, "locator": loopNdx.reverse() });
                             return true;
                             return true;
@@ -368,8 +367,7 @@
                                     if (isFirstMatch) {
                                     if (isFirstMatch) {
                                         insertStop = true; //insert a stop for non greedy
                                         insertStop = true; //insert a stop for non greedy
                                     }
                                     }
-                                    //search for next possible match
-                                    testPos = currentPos;
+                                    testPos = pos; //match the position after the group
                                 }
                                 }
                             } else if (match.isAlternator) {
                             } else if (match.isAlternator) {
                                 //TODO
                                 //TODO
@@ -381,9 +379,7 @@
                                     if (match) {
                                     if (match) {
                                         //get latest match
                                         //get latest match
                                         var latestMatch = matches[matches.length - 1]["match"];
                                         var latestMatch = matches[matches.length - 1]["match"];
-                                        if (qndx > qt.quantifier.min - 1) { //mark optionality
-                                            latestMatch.optionalQuantifier = true;
-                                        }
+                                        latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
                                         var isFirstMatch = (tokenGroup.matches.indexOf(latestMatch) == 0);
                                         var isFirstMatch = (tokenGroup.matches.indexOf(latestMatch) == 0);
                                         if (isFirstMatch) { //search for next possible match
                                         if (isFirstMatch) { //search for next possible match
                                             if (qndx > qt.quantifier.min - 1) {
                                             if (qndx > qt.quantifier.min - 1) {
@@ -1831,7 +1827,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.6
+Version: 3.0.7
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -1941,7 +1937,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.6
+Version: 3.0.7
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2404,7 +2400,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.6
+Version: 3.0.7
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2667,7 +2663,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.6
+Version: 3.0.7
 
 
 Regex extensions on the jquery.inputmask base
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 Allows for using regular expressions as a mask
@@ -2854,7 +2850,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.6
+Version: 3.0.7
 
 
 Phone extension.
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks
 When using this extension make sure you specify the correct url to get the masks

File diff suppressed because it is too large
+ 51 - 51
dist/jquery.inputmask.bundle.min.js


File diff suppressed because it is too large
+ 23 - 23
dist/min/jquery.inputmask.js


+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"inputmask",
 		"mask"
 		"mask"
     ],
     ],
-    "version": "3.0.6",
+    "version": "3.0.7",
     "author": {
     "author": {
         "name": "Robin Herbots",
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 3 - 7
js/jquery.inputmask.js

@@ -244,7 +244,7 @@
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                         maskTemplate.push(test["fn"] == null ? test["def"] : (includeInput === true ? validPos["input"] : opts.placeholder.charAt(pos % opts.placeholder.length)));
                     } else {
                     } else {
                         var testPos = getTests(pos, ndxIntlzr, pos - 1), firstMatch = testPos[0]["match"];
                         var testPos = getTests(pos, ndxIntlzr, pos - 1), firstMatch = testPos[0]["match"];
-                        testPos = testPos[(minimalPos > pos || (firstMatch.optionalQuantifier !== true && (opts.greedy || (firstMatch.optionality === true && firstMatch.newBlockMarker === false)))) ? 0 : (testPos.length - 1)];
+                        testPos = testPos[(minimalPos > pos || (opts.greedy || (firstMatch.optionality === true && firstMatch.newBlockMarker === false && firstMatch.optionalQuantifier !== true))) ? 0 : (testPos.length - 1)];
                         test = testPos["match"];
                         test = testPos["match"];
                         ndxIntlzr = testPos["locator"].slice();
                         ndxIntlzr = testPos["locator"].slice();
                         maskTemplate.push(test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
                         maskTemplate.push(test["fn"] == null ? test["def"] : opts.placeholder.charAt(pos % opts.placeholder.length));
@@ -351,7 +351,6 @@
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
                 function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitilizer contains a set of indexes to speedup searches in the mtokens
 
 
                     function handleMatch(match, loopNdx, quantifierRecurse) {
                     function handleMatch(match, loopNdx, quantifierRecurse) {
-                        var currentPos = testPos;
                         if (testPos == pos && match.matches == undefined) {
                         if (testPos == pos && match.matches == undefined) {
                             matches.push({ "match": match, "locator": loopNdx.reverse() });
                             matches.push({ "match": match, "locator": loopNdx.reverse() });
                             return true;
                             return true;
@@ -368,8 +367,7 @@
                                     if (isFirstMatch) {
                                     if (isFirstMatch) {
                                         insertStop = true; //insert a stop for non greedy
                                         insertStop = true; //insert a stop for non greedy
                                     }
                                     }
-                                    //search for next possible match
-                                    testPos = currentPos;
+                                    testPos = pos; //match the position after the group
                                 }
                                 }
                             } else if (match.isAlternator) {
                             } else if (match.isAlternator) {
                                 //TODO
                                 //TODO
@@ -381,9 +379,7 @@
                                     if (match) {
                                     if (match) {
                                         //get latest match
                                         //get latest match
                                         var latestMatch = matches[matches.length - 1]["match"];
                                         var latestMatch = matches[matches.length - 1]["match"];
-                                        if (qndx > qt.quantifier.min - 1) { //mark optionality
-                                            latestMatch.optionalQuantifier = true;
-                                        }
+                                        latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1;
                                         var isFirstMatch = (tokenGroup.matches.indexOf(latestMatch) == 0);
                                         var isFirstMatch = (tokenGroup.matches.indexOf(latestMatch) == 0);
                                         if (isFirstMatch) { //search for next possible match
                                         if (isFirstMatch) { //search for next possible match
                                             if (qndx > qt.quantifier.min - 1) {
                                             if (qndx > qt.quantifier.min - 1) {