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;
});
|