PageRenderTime 21ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/jsdoc_toolkit-2.2.1/jsdoc-toolkit/app/lib/JSDOC/TextStream.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 41 lines | 32 code | 6 blank | 3 comment | 12 complexity | f03e82a96130f5b13e39a374f85beec2 MD5 | raw file
 1
 2/**
 3	@constructor
 4*/
 5JSDOC.TextStream = function(text) {
 6	if (typeof(text) == "undefined") text = "";
 7	text = ""+text;
 8	this.text = text;
 9	this.cursor = 0;
10}
11
12JSDOC.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
23JSDOC.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}