Tidied up consumeWhile and consumeUntil

This commit is contained in:
n1474335 2019-11-13 18:04:36 +00:00
parent ea6d80edfb
commit 03f4740968

View file

@ -156,7 +156,6 @@ export default class Stream {
// val is an array // val is an array
/** /**
* Builds the skip forward table from the value to be searched. * Builds the skip forward table from the value to be searched.
* *
@ -173,9 +172,7 @@ export default class Stream {
} }
const length = val.length; const length = val.length;
const initial = val[length-1]; const initial = val[length-1];
this.position = length; this.position = length;
// Get the skip table. // Get the skip table.
@ -183,7 +180,6 @@ export default class Stream {
let found = true; let found = true;
while (this.position < this.length) { while (this.position < this.length) {
// Until we hit the final element of val in the stream. // Until we hit the final element of val in the stream.
while ((this.position < this.length) && (this.bytes[this.position++] !== initial)); while ((this.position < this.length) && (this.bytes[this.position++] !== initial));
@ -191,7 +187,7 @@ export default class Stream {
// Loop through the elements comparing them to val. // Loop through the elements comparing them to val.
for (let x = length-1; x >= 0; x--) { for (let x = length-1; x >= 0; x--) {
if (this.bytes[this.position-length + x] !== val[x]) { if (this.bytes[this.position - length + x] !== val[x]) {
found = false; found = false;
// If element is not equal to val's element then jump forward by the correct amount. // If element is not equal to val's element then jump forward by the correct amount.
@ -208,7 +204,7 @@ export default class Stream {
/** /**
* Consume bytes if it matches the supplied value. * Consume bytes if they match the supplied value.
* *
* @param {Number} val * @param {Number} val
*/ */
@ -219,6 +215,7 @@ export default class Stream {
} }
this.position++; this.position++;
} }
this.bitPos = 0;
} }
/** /**