all files / graphics/fonts/ string-tokenizer.js

73.02% Statements 92/126
54.17% Branches 26/48
82.35% Functions 14/17
73.02% Lines 92/126
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   480× 480×     480×     7635×           495×                           500×                                     500×     500×     500× 500× 2862× 2862× 72×     500×     1472× 1472× 5880× 5880×     56× 56× 56× 32×   56×     5824×   1416× 944× 944× 944×   472×   972× 972× 972× 972×   57× 57× 275× 275×                     33× 16×   33× 33× 33×     242×   24× 16× 16× 16×     33× 33× 33× 33×   11× 11× 11× 11× 11×   11×                         12× 12× 12×   12×   480×                       2862× 2862× 5652× 72× 72×     2862×        
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var StringTokenizer = (function () {
        function StringTokenizer(textValue) {
            this.currentPosition = 0;
            Iif (textValue == null) {
                throw new Error('ArgumentNullException:text');
            }
            this.text = textValue;
        }
        Object.defineProperty(StringTokenizer.prototype, "length", {
            get: function () {
                return this.text.length;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(StringTokenizer.prototype, "end", {
            get: function () {
                return (this.currentPosition === this.text.length);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(StringTokenizer.prototype, "position", {
            get: function () {
                return this.currentPosition;
            },
            set: function (value) {
                this.currentPosition = value;
            },
            enumerable: true,
            configurable: true
        });
        StringTokenizer.getCharsCount = function (text, symbols) {
            Iif (typeof symbols === 'string') {
                if (text == null) {
                    throw new Error('ArgumentNullException:wholeText');
                }
                var numSymbols = 0;
                var curIndex = 0;
                for (;;) {
                    curIndex = text.indexOf(symbols, curIndex);
                    if (curIndex === -1) {
                        break;
                    }
                    else {
                        numSymbols++;
                        curIndex++;
                    }
                }
                return numSymbols;
            }
            else {
                Iif (text == null) {
                    throw new Error('ArgumentNullException:text');
                }
                Iif (symbols == null) {
                    throw new Error('ArgumentNullException:symbols');
                }
                var count = 0;
                for (var i = 0, len = text.length; i < len; i++) {
                    var ch = text[i];
                    if (this.contains(symbols, ch)) {
                        count++;
                    }
                }
                return count;
            }
        };
        StringTokenizer.prototype.readLine = function () {
            var pos = this.currentPosition;
            while (pos < this.length) {
                var ch = this.text[pos];
                switch (ch) {
                    case '\r':
                    case '\n': {
                        var text = this.text.substr(this.currentPosition, pos - this.currentPosition);
                        this.currentPosition = pos + 1;
                        if (((ch === '\r') && (this.currentPosition < this.length)) && (this.text[this.currentPosition] === '\n')) {
                            this.currentPosition++;
                        }
                        return text;
                    }
                }
                pos++;
            }
            if (pos > this.currentPosition) {
                var text2 = this.text.substr(this.currentPosition, pos - this.currentPosition);
                this.currentPosition = pos;
                return text2;
            }
            return null;
        };
        StringTokenizer.prototype.peekLine = function () {
            var pos = this.currentPosition;
            var line = this.readLine();
            this.currentPosition = pos;
            return line;
        };
        StringTokenizer.prototype.readWord = function () {
            var pos = this.currentPosition;
            while (pos < this.length) {
                var ch = this.text[pos];
                switch (ch) {
                    case '\r':
                    case '\n':
                        var textValue = this.text.substr(this.currentPosition, pos - this.currentPosition);
                        this.currentPosition = pos + 1;
                        if (((ch === '\r') && (this.currentPosition < this.length)) && (this.text[this.currentPosition] === '\n')) {
                            this.currentPosition++;
                        }
                        return textValue;
                    case ' ':
                    case '\t': {
                        if (pos === this.currentPosition) {
                            pos++;
                        }
                        var text = this.text.substr(this.currentPosition, pos - this.currentPosition);
                        this.currentPosition = pos;
                        return text;
                    }
                }
                pos++;
            }
            if (pos > this.currentPosition) {
                var text2 = this.text.substr(this.currentPosition, pos - this.currentPosition);
                this.currentPosition = pos;
                return text2;
            }
            return null;
        };
        StringTokenizer.prototype.peekWord = function () {
            var pos = this.currentPosition;
            var word = this.readWord();
            this.currentPosition = pos;
            return word;
        };
        StringTokenizer.prototype.read = function (count) {
            Eif (typeof count === 'undefined') {
                var ch = '0';
                Eif (!this.end) {
                    ch = this.text[this.currentPosition];
                    this.currentPosition++;
                }
                return ch;
            }
            else {
                var num = 0;
                var builder = '';
                while (!this.end && num < count) {
                    var ch = this.read();
                    builder = builder + ch;
                    num++;
                }
                return builder;
            }
        };
        StringTokenizer.prototype.peek = function () {
            var ch = '0';
            Eif (!this.end) {
                ch = this.text[this.currentPosition];
            }
            return ch;
        };
        StringTokenizer.prototype.close = function () {
            this.text = null;
        };
        StringTokenizer.prototype.readToEnd = function () {
            var text;
            if (this.currentPosition === 0) {
                text = this.text;
            }
            else {
                text = this.text.substr(this.currentPosition, this.length - this.currentPosition);
            }
            this.currentPosition = this.length;
            return text;
        };
        StringTokenizer.contains = function (array, symbol) {
            var contains = false;
            for (var i = 0; i < array.length; i++) {
                if (array[i] === symbol) {
                    contains = true;
                    break;
                }
            }
            return contains;
        };
        StringTokenizer.whiteSpace = ' ';
        StringTokenizer.tab = '\t';
        StringTokenizer.spaces = [StringTokenizer.whiteSpace, StringTokenizer.tab];
        StringTokenizer.whiteSpacePattern = '^[ \t]+$';
        return StringTokenizer;
    }());
    exports.StringTokenizer = StringTokenizer;
});