thirdparty/jsdoctoolkit/app/lib/JSDOC/TextStream.js
changeset 3041 c8f47f0b6697
equal deleted inserted replaced
3040:8f9580309846 3041:c8f47f0b6697
       
     1 
       
     2 /**
       
     3 	@constructor
       
     4 */
       
     5 JSDOC.TextStream = function(text) {
       
     6 	if (typeof(text) == "undefined") text = "";
       
     7 	text = ""+text;
       
     8 	this.text = text;
       
     9 	this.cursor = 0;
       
    10 }
       
    11 
       
    12 JSDOC.TextStream.prototype.look = function(n) {
       
    13 	if (typeof n == "undefined") n = 0;
       
    14 	
       
    15 	if (this.cursor+n < 0 || this.cursor+n >= this.text.length) {
       
    16 		var result = new String("");
       
    17 		result.eof = true;
       
    18 		return result;
       
    19 	}
       
    20 	return this.text.charAt(this.cursor+n);
       
    21 }
       
    22 
       
    23 JSDOC.TextStream.prototype.next = function(n) {
       
    24 	if (typeof n == "undefined") n = 1;
       
    25 	if (n < 1) return null;
       
    26 	
       
    27 	var pulled = "";
       
    28 	for (var i = 0; i < n; i++) {
       
    29 		if (this.cursor+i < this.text.length) {
       
    30 			pulled += this.text.charAt(this.cursor+i);
       
    31 		}
       
    32 		else {
       
    33 			var result = new String("");
       
    34 			result.eof = true;
       
    35 			return result;
       
    36 		}
       
    37 	}
       
    38 
       
    39 	this.cursor += n;
       
    40 	return pulled;
       
    41 }