1 /**
  2  * @fileoverview Helper class for class xrx.stream.
  3  */
  4 
  5 goog.provide('xrx.reader');
  6 
  7 
  8 
  9 xrx.reader = function(input) {
 10 
 11 
 12 
 13   this.input_ = input || '';
 14 
 15 
 16 
 17   this.pos_ = 0;
 18 
 19 
 20 
 21   this.length_ = input.length;
 22 };
 23 
 24 
 25 
 26 xrx.reader.prototype.first = function() {
 27 
 28   this.pos_ = 0;
 29 };
 30 
 31 
 32 
 33 xrx.reader.prototype.last = function() {
 34 
 35   this.pos_ = this.length_ - 1;
 36 };
 37 
 38 
 39 
 40 xrx.reader.prototype.set = function(pos) {
 41 
 42   this.pos_ = pos || 0;
 43 };
 44 
 45 
 46 
 47 xrx.reader.prototype.get = function() {
 48 
 49   return this.input_.charAt(this.pos_);
 50 };
 51 
 52 
 53 
 54 xrx.reader.prototype.input = function(xml) {
 55   
 56   xml ? this.input_ = xml : null;
 57   return this.input_;
 58 };
 59 
 60 
 61 
 62 xrx.reader.prototype.pos = function() {
 63 
 64   return this.pos_;
 65 };
 66 
 67 
 68 
 69 xrx.reader.prototype.length = function() {
 70 
 71   return this.length_;
 72 };
 73 
 74 
 75 
 76 xrx.reader.prototype.finished = function() {
 77 
 78   return this.pos_ < 0 || this.pos_ > this.length_ ? true : false;
 79 };
 80 
 81 
 82 
 83 xrx.reader.prototype.next = function() {
 84 
 85   return this.input_.charAt(this.pos_++);
 86 };
 87 
 88 
 89 
 90 xrx.reader.prototype.previous = function() {
 91 
 92   return this.input_.charAt(this.pos_--);
 93 };
 94 
 95 
 96 
 97 xrx.reader.prototype.peek = function(i) {
 98 
 99   return this.input_.charAt(this.pos_ + (i || 0));
100 };
101 
102 
103 
104 xrx.reader.prototype.forward = function(i) {
105 
106   this.pos_ += (i || 0);
107 };
108 
109 
110 
111 xrx.reader.prototype.backward = function(i) {
112 
113   this.pos_ -= (i || 0);
114 };
115 
116 
117 
118 xrx.reader.prototype.forwardInclusive = function(ch) {
119   var i;
120 
121   for (i = 0;; i++) {
122     if (this.peek(i) === ch) break;
123   }
124   this.forward(++i);
125 };
126 
127 
128 
129 xrx.reader.prototype.forwardExclusive = function(ch) {
130   var i;
131 
132   for (i = 0;; i++) {
133     if (this.peek(i) === ch) break;
134   }
135   this.forward(i);
136 };
137 
138 
139 
140 xrx.reader.prototype.backwardInclusive = function(ch) {
141   var i;
142 
143   for (i = 0;; i++) {
144     if (this.peek(-i) === ch) break;
145   }
146   this.backward(i);
147 };
148 
149 
150 
151 xrx.reader.prototype.backwardExclusive = function(ch) {
152   var i;
153 
154   for (i = 0;; i++) {
155     if (this.peek(-i) === ch) break;
156   }
157   this.backward(--i);
158 };
159