# all files / TypeScript.NET/source/System/Text/ RegularExpressions.js

96.07% Statements 171/178
83.18% Branches 89/107
100% Functions 25/25
97.55% Lines 159/163

    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
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227

    1×
    2×
    2×
    2×

    1×
    1×
    1×

    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×
    1×
    8×
    8×
    1×

    8×
    1×
    7×

    7×
    3×
    3×
    1×
    3×
    1×
    3×

    4×

    7×
    7×
    7×

    7×
    7×
    1×
    1×

    1×
    1×

    7×
    1×
    7×

    7×

    1×
    23×
    23×
    23×
    23×

    7×
    16×
    8×
    16×
    16×
    30×
    30×
    30×
    30×
    30×

    30×
    12×
    30×
    30×
    14×

    16×
    16×
    16×

    1×
    2×
    2×
    4×
    4×

    2×

    1×
    5×
    5×
    1×
    4×
    4×
    4×
    4×
    8×
    8×
    4×
    8×
    8×

    4×
    4×
    4×

    1×
    4×

    1×
    2×
    2×

    1×
    1×
    1×

    1×

    1×
    1×
    1×
    48×
    48×
    48×
    48×

    1×

    14×
    14×

    1×
    48×

    1×

    1×
    1×
    1×
    1×
    48×
    48×
    48×

    1×

    21×

    1×

    1×

    1×

    1×
    1×
    1×
    1×
    1×
    1×
    17×
    17×
    17×
    17×
    17×
    17×
    17×

    1×
    17×

    17×

    17×
    17×
    17×

    1×

    7×

    1×

    1×
    1×
    1×
    1×
    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Named groups based on: http://trentrichardson.com/2011/08/02/javascript-regexp-match-named-captures/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    var __extends = (this && this.__extends) || function (d, b) {
        for (var p in b) Eif (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
    (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"], factory);
        }
    })(function (require, exports) {
        "use strict";
        var EMPTY = "";
        var UNDEFINED = "undefined";
        var _I = 'i', _G = 'g', _M = 'm', _U = 'u', _W = 'w', _Y = 'y';
        var RegexOptions;
        (function (RegexOptions) {
            RegexOptions.IGNORE_CASE = _I;
            RegexOptions.I = _I;
            RegexOptions.GLOBAL = _G;
            RegexOptions.G = _G;
            RegexOptions.MULTI_LINE = _M;
            RegexOptions.M = _M;
            RegexOptions.UNICODE = _U;
            RegexOptions.U = _U;
            RegexOptions.STICKY = _Y;
            RegexOptions.Y = _Y;
            RegexOptions.IGNORE_PATTERN_WHITESPACE = _W;
            RegexOptions.W = _W;
        })(RegexOptions = exports.RegexOptions || (exports.RegexOptions = {}));
        var Regex = (function () {
            function Regex(pattern, options) {
                var extra = [];
                for (var _i = 2; _i < arguments.length; _i++) {
                    extra[_i - 2] = arguments[_i];
                }
                if (!pattern)
                    throw new Error("'pattern' cannot be null or empty.");
                var patternString, flags = (options && (Array.isArray(options) ? options : [options]).concat(extra) || extra)
                    .join(EMPTY).toLowerCase();
                if (pattern instanceof RegExp) {
                    var p = pattern;
                    if (p.ignoreCase && flags.indexOf(_I) === -1)
                        flags += _I;
                    if (p.multiline && flags.indexOf(_M) === -1)
                        flags += _M;
                    patternString = p.source;
                }
                else {
                    patternString = pattern;
                }
                var ignoreWhiteSpace = flags.indexOf(_W) != -1;
                flags = flags.replace(/[gw]/g, EMPTY);
                var keys = [];
                {
                    var k = patternString.match(/(?!\(\?<)(\w+)(?=>)/g);
                    if (k) {
                        for (var i = 0, len = k.length; i < len; i++) {
                            keys[i + 1] = k[i];
                        }
                        patternString = patternString.replace(/\?<\w+>/g, EMPTY);
                        this._keys = keys;
                    }
                    if (ignoreWhiteSpace)
                        patternString = patternString.replace(/\s+/g, "\\s*");
                    this._re = new RegExp(patternString, flags);
                }
                Object.freeze(this);
            }
            Regex.prototype.match = function (input, startIndex) {
                if (startIndex === void 0) { startIndex = 0; }
                var _ = this;
                var r;
                if (!input
                    || startIndex >= input.length
                    || !(r = this._re.exec(input.substring(startIndex))))
                    return Match.Empty;
                if (!(startIndex > 0))
                    startIndex = 0;
                var first = startIndex + r.index, loc = first, groups = [], groupMap = {};
                for (var i = 0, len = r.length; i < len; ++i) {
                    var text = r[i];
                    var g = EmptyGroup;
                    Eif (text !== null || text !== void 0) {
                        g = new Group(text, loc);
                        g.freeze();
                    }
                    if (i && _._keys && i < _._keys.length)
                        groupMap[_._keys[i]] = g;
                    groups.push(g);
                    if (i !== 0)
                        loc += text.length;
                }
                var m = new Match(r[0], first, groups, groupMap);
                m.freeze();
                return m;
            };
            Regex.prototype.matches = function (input) {
                var matches = [], m, p = 0, end = input && input.length || 0;
                while (p < end && (m = this.match(input, p)) && m.success) {
                    matches.push(m);
                    p = m.index + m.length;
                }
                return Object.freeze(matches);
            };
            Regex.prototype.replace = function (input, r, count) {
                Eif (count === void 0) { count = Infinity; }
                if (!input || r === null || r === void 0 || !(count > 0))
                    return input;
                var result = [];
                var p = 0, end = input.length, isEvaluator = typeof r == "function";
                var m, i = 0;
                while (i < count && p < end && (m = this.match(input, p)) && m.success) {
                    var index = m.index, length_1 = m.length;
                    if (p !== index)
                        result.push(input.substring(p, index));
                    result.push(isEvaluator ? r(m, i++) : r);
                    p = index + length_1;
                }
                Eif (p < end)
                    result.push(input.substring(p));
                return result.join(EMPTY);
            };
            Regex.prototype.isMatch = function (input) {
                return this._re.test(input);
            };
            Regex.isMatch = function (input, pattern, options) {
                var r = new Regex(pattern, options);
                return r.isMatch(input);
            };
            Regex.replace = function (input, pattern, e, options) {
                var r = new Regex(pattern, options);
                return r.replace(input, e);
            };
            return Regex;
        }());
        exports.Regex = Regex;
        var Capture = (function () {
            function Capture(value, index) {
                Iif (value === void 0) { value = EMPTY; }
                Iif (index === void 0) { index = -1; }
                this.value = value;
                this.index = index;
            }
            Object.defineProperty(Capture.prototype, "length", {
                get: function () {
                    var v = this.value;
                    return v && v.length || 0;
                },
                enumerable: true,
                configurable: true
            });
            Capture.prototype.freeze = function () {
                Object.freeze(this);
            };
            return Capture;
        }());
        exports.Capture = Capture;
        var Group = (function (_super) {
            __extends(Group, _super);
            function Group(value, index) {
                if (value === void 0) { value = EMPTY; }
                if (index === void 0) { index = -1; }
                _super.call(this, value, index);
            }
            Object.defineProperty(Group.prototype, "success", {
                get: function () {
                    return this.index != -1;
                },
                enumerable: true,
                configurable: true
            });
            Object.defineProperty(Group, "Empty", {
                get: function () {
                    return EmptyGroup;
                },
                enumerable: true,
                configurable: true
            });
            return Group;
        }(Capture));
        exports.Group = Group;
        var EmptyGroup = new Group();
        EmptyGroup.freeze();
        var Match = (function (_super) {
            __extends(Match, _super);
            function Match(value, index, groups, namedGroups) {
                if (value === void 0) { value = EMPTY; }
                if (index === void 0) { index = -1; }
                if (groups === void 0) { groups = []; }
                if (namedGroups === void 0) { namedGroups = {}; }
                _super.call(this, value, index);
                this.groups = groups;
                this.namedGroups = namedGroups;
            }
            Match.prototype.freeze = function () {
                Iif (!this.groups)
                    throw new Error("'groups' cannot be null.");
                Iif (!this.namedGroups)
                    throw new Error("'groupMap' cannot be null.");
                Object.freeze(this.groups.slice());
                Object.freeze(this.namedGroups);
                _super.prototype.freeze.call(this);
            };
            Object.defineProperty(Match, "Empty", {
                get: function () {
                    return EmptyMatch;
                },
                enumerable: true,
                configurable: true
            });
            return Match;
        }(Group));
        exports.Match = Match;
        var EmptyMatch = new Match();
        EmptyMatch.freeze();
        Object.defineProperty(exports, "__esModule", { value: true });
        exports.default = Regex;
    });
    //# sourceMappingURL=RegularExpressions.js.map