Diff

util/dbuffer.lua @ 11637:19cddf92fcc2

util.dbuffer: Fix bugs, remove multi-char support (more complex than first thought) Character sequences could be split across chunk boundaries. Would require a bunch of code to make that work reliably. Only apply front_consumed on first chunk, and adjust buffer_pos accordingly.
author Matthew Wild <mwild1@gmail.com>
date Tue, 29 Jun 2021 14:25:57 +0100
parent 11636:11e0a0a08da3
child 12762:79b89f382290
line wrap: on
line diff
--- a/util/dbuffer.lua	Tue Jun 29 13:48:14 2021 +0100
+++ b/util/dbuffer.lua	Tue Jun 29 14:25:57 2021 +0100
@@ -80,12 +80,12 @@
 function dbuffer_methods:read_until(char)
 	local buffer_pos = 0;
 	for i, chunk in self.items:items() do
-		local start = 1 + self.front_consumed;
+		local start = 1 + ((i == 1) and self.front_consumed or 0);
 		local char_pos = chunk:find(char, start, true);
 		if char_pos then
-			return self:read(buffer_pos + (char_pos - start) + #char);
+			return self:read(1 + buffer_pos + char_pos - start);
 		end
-		buffer_pos = buffer_pos + #chunk;
+		buffer_pos = buffer_pos + #chunk - (start - 1);
 	end
 	return nil;
 end