all files / TypeScript.NET/source/System/Text/ RegexMatchEnumerator.js

87.1% Statements 27/31
55.56% Branches 10/18
100% Functions 8/8
89.66% Lines 26/29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                                 
/*!
 * @author electricessence / https://github.com/electricessence/
 * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
 */
(function (factory) {
    Eif (typeof module === 'object' && typeof module.exports === 'object') {
        var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
    }
    else if (typeof define === 'function' && define.amd) {
        define(["require", "exports", "./RegularExpressions", "../Collections/Enumeration/EmptyEnumerator", "../Collections/Enumeration/EnumeratorBase"], factory);
    }
})(function (require, exports) {
    "use strict";
    var RegularExpressions_1 = require("./RegularExpressions");
    var EmptyEnumerator_1 = require("../Collections/Enumeration/EmptyEnumerator");
    var EnumeratorBase_1 = require("../Collections/Enumeration/EnumeratorBase");
    var RegexMatchEnumerator = (function () {
        function RegexMatchEnumerator(pattern) {
            Eif (pattern instanceof RegularExpressions_1.Regex) {
                this._pattern = pattern;
            }
            else {
                this._pattern = new RegularExpressions_1.Regex(pattern);
            }
        }
        RegexMatchEnumerator.prototype.matches = function (input) {
            var _this = this;
            var p;
            return new EnumeratorBase_1.EnumeratorBase(function () {
                p = 0;
            }, function (yielder) {
                var match = _this._pattern.match(input, p);
                if (match.success) {
                    p = match.index + match.length;
                    return yielder.yieldReturn(match);
                }
                return yielder.yieldBreak();
            });
        };
        RegexMatchEnumerator.matches = function (input, pattern) {
            return input && pattern
                ? (new RegexMatchEnumerator(pattern)).matches(input)
                : EmptyEnumerator_1.EmptyEnumerator;
        };
        return RegexMatchEnumerator;
    }());
    exports.RegexMatchEnumerator = RegexMatchEnumerator;
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.default = RegexMatchEnumerator.matches;
});
//# sourceMappingURL=RegexMatchEnumerator.js.map