-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuffer.js
More file actions
52 lines (41 loc) · 1.12 KB
/
buffer.js
File metadata and controls
52 lines (41 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Created by blarsen on 03.10.14.
*/
"use strict";
var Buffer = function(data, index) {
this.data = data;
this.index = index;
this.skipSpaces = function() {
while (this.hasMore() && this.data[this.index] == ' ')
this.index++;
};
this.getUpto = function(char) {
if (!this.hasMore())
return undefined;
var result = '';
while (this.hasMore() && (this.data[this.index] != char || this.data[this.index-1] == '\\')) {
result += this.data[this.index++];
}
return result;
};
this.skip = function(count) {
count = count || 1;
var before = this.index;
this.index = Math.min(this.index+count, this.data.length);
};
this.rewind = function() {
this.index = 0;
};
this.lookingAt = function() {
if (!this.hasMore())
return undefined;
return this.data[this.index];
};
this.hasMore = function() {
return this.remaining() > 0;
};
this.remaining = function() {
return this.data.length - this.index;
};
}
module.exports = Buffer;