eachlineV omits final line
Opened this issue · 6 comments
test.txt:
hello
my
name is
bob
test.jl:
using ViewReader
@info "eachlineV:"
for line in eachlineV("test.txt")
@show line
end
@info "eachline:"
for line in eachline("test.txt")
@show line
end
REPL:
julia> include("test.jl")
[ Info: eachlineV:
line = "hello"
line = "my"
line = "name is"
[ Info: eachline:
line = "hello"
line = "my"
line = "name is"
line = "bob"
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 16 × AMD Ryzen 9 5900HS with Radeon Graphics
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, znver3)
Threads: 1 on 16 virtual cores
Hey @grahamas,
Not looking at Julia much lately so didn't notice the issue.
When I run your code (on the provided text file) it works fine for me.
I do have an older version of Julia, perhaps that is it - will check
I can't replicate this on Julia 1.10 either.
[ Info: eachlineV:
line = "hello"
line = "my"
line = "name is"
line = "bob"
[ Info: eachline:
line = "hello"
line = "my"
line = "name is"
line = "bob"
On my machine
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
Threads: 1 on 8 virtual cores
@grahamas is that just this file? or is this a consistent problem? (Just thining whether it could be a file thing, like a hidden character)
Hi @rickbeeloo, thanks for looking into this. The problem happened across multiple files (all files as far as I could tell, but I didn’t check diligently). I’ll poke around and see if I can find any exceptions on this or my other computer.
Hey @grahamas, could you send me your test.txt file to biobeeloo@gmail.com. Then we know if this is about the file or some system thing.
Is it possible your test file had a trailing newline? If I put a trailing newline in, all the lines get parsed fine.
edit: then again that would also happen if the problem is something else entirely
edit2: which is to say, I sent it
It indeed is because there is no trailing newline.
The fix is quite easy, still return the slice of the buffer if there are non zero bytes after the last returned line.
Has been 9 months since I wrote a Julia script so gonna do my best :)