PageRenderTime 11ms CodeModel.GetById 6ms RepoModel.GetById 0ms 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. @constructor
  3. */
  4. JSDOC.TextStream = function(text) {
  5. if (typeof(text) == "undefined") text = "";
  6. text = ""+text;
  7. this.text = text;
  8. this.cursor = 0;
  9. }
  10. JSDOC.TextStream.prototype.look = function(n) {
  11. if (typeof n == "undefined") n = 0;
  12. if (this.cursor+n < 0 || this.cursor+n >= this.text.length) {
  13. var result = new String("");
  14. result.eof = true;
  15. return result;
  16. }
  17. return this.text.charAt(this.cursor+n);
  18. }
  19. JSDOC.TextStream.prototype.next = function(n) {
  20. if (typeof n == "undefined") n = 1;
  21. if (n < 1) return null;
  22. var pulled = "";
  23. for (var i = 0; i < n; i++) {
  24. if (this.cursor+i < this.text.length) {
  25. pulled += this.text.charAt(this.cursor+i);
  26. }
  27. else {
  28. var result = new String("");
  29. result.eof = true;
  30. return result;
  31. }
  32. }
  33. this.cursor += n;
  34. return pulled;
  35. }