From 03f474096895c604cef7b584ff82735de64c9479 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 13 Nov 2019 18:04:36 +0000 Subject: [PATCH] Tidied up consumeWhile and consumeUntil --- src/core/lib/Stream.mjs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/lib/Stream.mjs b/src/core/lib/Stream.mjs index da299b65..800d6b1a 100644 --- a/src/core/lib/Stream.mjs +++ b/src/core/lib/Stream.mjs @@ -156,7 +156,6 @@ export default class Stream { // val is an array - /** * Builds the skip forward table from the value to be searched. * @@ -173,9 +172,7 @@ export default class Stream { } const length = val.length; - const initial = val[length-1]; - this.position = length; // Get the skip table. @@ -183,7 +180,6 @@ export default class Stream { let found = true; while (this.position < this.length) { - // Until we hit the final element of val in the stream. 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. 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; // 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 */ @@ -219,6 +215,7 @@ export default class Stream { } this.position++; } + this.bitPos = 0; } /**