Skip to content

strings.split_lines always return 1 extra empty line #3016

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

Closed
edyu opened this issue Dec 12, 2023 · 3 comments
Closed

strings.split_lines always return 1 extra empty line #3016

edyu opened this issue Dec 12, 2023 · 3 comments

Comments

@edyu
Copy link
Contributor

edyu commented Dec 12, 2023

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Operating System & Odin Version:

  • Please paste odin report output:

      Odin: dev-2023-12:bf9ae77f
      OS:   Ubuntu 22.04.3 LTS, Linux 5.15.133.1-microsoft-standard-WSL2
      CPU:  12th Gen Intel(R) Core(TM) i7-12700H
      RAM:  15838 MiB
    

Expected Behavior

strings.split_lines should return just the number of lines in the text file

Current Behavior

What is the current behavior?

strings.split_lines when coupled with os.read_entire_file will always return 1 extra empty line

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. use os.read_entire_file to read a text file
  2. use strings.split_lines to get the file content as an array
  3. print the number of lines

Failure Logs

Please include any relevant log snippets or files here.

For most file editors or even most languages when they do split_lines, they don't expect to see a trailing empty line. Whether it's correct because there is a trailing \n at the end of the last line there should be an extra empty line or not, it doesn't go against expectations and makes parsing text files more dificult because you have to remember there is an extra empty line that you have to ignore.

@edyu
Copy link
Contributor Author

edyu commented Dec 12, 2023

mytest.txt

This is reported as 4 lines

@edyu
Copy link
Contributor Author

edyu commented Dec 12, 2023

test.odin.txt

This is the example test program I'm using

@Kelimion
Copy link
Member

Still not a bug, as demonstrated on Discord.

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