Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eachlineV omits final line #3

Open
grahamas opened this issue Jan 12, 2024 · 6 comments
Open

eachlineV omits final line #3

grahamas opened this issue Jan 12, 2024 · 6 comments

Comments

@grahamas
Copy link

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
@rickbeeloo
Copy link
Collaborator

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

@rickbeeloo
Copy link
Collaborator

rickbeeloo commented Jan 16, 2024

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)

@grahamas
Copy link
Author

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.

@rickbeeloo
Copy link
Collaborator

Hey @grahamas, could you send me your test.txt file to [email protected]. Then we know if this is about the file or some system thing.

@grahamas
Copy link
Author

grahamas commented Jan 16, 2024

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

@rickbeeloo
Copy link
Collaborator

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants