mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-11 02:03:58 +01:00
25 lines
627 B
JavaScript
25 lines
627 B
JavaScript
|
/* InputStream class. Creates a "stream object" that provides operations to read
|
||
|
* from a string. */
|
||
|
function InputStream(input) {
|
||
|
var pos = 0, line = 1, col = 0;
|
||
|
return {
|
||
|
next : next,
|
||
|
peek : peek,
|
||
|
eof : eof,
|
||
|
croak : croak,
|
||
|
};
|
||
|
function next() {
|
||
|
var ch = input.charAt(pos++);
|
||
|
if (ch == "\n") line++, col = 0; else col++;
|
||
|
return ch;
|
||
|
}
|
||
|
function peek() {
|
||
|
return input.charAt(pos);
|
||
|
}
|
||
|
function eof() {
|
||
|
return peek() == "";
|
||
|
}
|
||
|
function croak(msg) {
|
||
|
throw new Error(msg + " (" + line + ":" + col + ")");
|
||
|
}
|
||
|
}
|