mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 02:39:48 -04:00
Chomp \r and \r\n from lines, not just \n
This commit is contained in:
parent
a686f2ac3f
commit
9ffc060205
@ -240,13 +240,20 @@ function buffer:read(...)
|
|||||||
local function readLine(chop)
|
local function readLine(chop)
|
||||||
local start = 1
|
local start = 1
|
||||||
while true do
|
while true do
|
||||||
local l = self.bufferRead:find("\n", start, true)
|
local buf = self.bufferRead
|
||||||
if l then
|
local i = buf:find("[\r\n]", start)
|
||||||
local result = self.bufferRead:sub(1, l + (chop and -1 or 0))
|
local c = i and buf:sub(i,i)
|
||||||
self.bufferRead = self.bufferRead:sub(l + 1)
|
local is_cr = c == "\r"
|
||||||
|
if i and (not is_cr or i < #buf) then
|
||||||
|
local n = buf:sub(i+1,i+1)
|
||||||
|
if is_cr and n == "\n" then
|
||||||
|
c = c .. n
|
||||||
|
end
|
||||||
|
local result = buf:sub(1, i - 1) .. (chop and "" or c)
|
||||||
|
self.bufferRead = buf:sub(i + #c)
|
||||||
return result
|
return result
|
||||||
else
|
else
|
||||||
start = #self.bufferRead
|
start = #self.bufferRead - (is_cr and 1 or 0)
|
||||||
local result, reason = readChunk()
|
local result, reason = readChunk()
|
||||||
if not result then
|
if not result then
|
||||||
if reason then
|
if reason then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user