Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
11636:11e0a0a08da3 | 11637:19cddf92fcc2 |
---|---|
78 | 78 |
79 -- Read to, and including, the specified character sequence (return nil if not found) | 79 -- Read to, and including, the specified character sequence (return nil if not found) |
80 function dbuffer_methods:read_until(char) | 80 function dbuffer_methods:read_until(char) |
81 local buffer_pos = 0; | 81 local buffer_pos = 0; |
82 for i, chunk in self.items:items() do | 82 for i, chunk in self.items:items() do |
83 local start = 1 + self.front_consumed; | 83 local start = 1 + ((i == 1) and self.front_consumed or 0); |
84 local char_pos = chunk:find(char, start, true); | 84 local char_pos = chunk:find(char, start, true); |
85 if char_pos then | 85 if char_pos then |
86 return self:read(buffer_pos + (char_pos - start) + #char); | 86 return self:read(1 + buffer_pos + char_pos - start); |
87 end | 87 end |
88 buffer_pos = buffer_pos + #chunk; | 88 buffer_pos = buffer_pos + #chunk - (start - 1); |
89 end | 89 end |
90 return nil; | 90 return nil; |
91 end | 91 end |
92 | 92 |
93 function dbuffer_methods:discard(requested_bytes) | 93 function dbuffer_methods:discard(requested_bytes) |