Friendly reminder to turn this off :sweat_smile: i...
# advent-of-code
x
Friendly reminder to turn this off 馃槄 it was adding extra
\n
to the imported `.txt`s
e
all the files served by adventofcode.com are proper UNIX text files, meaning they are
\n
-terminated to begin with
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403
A file that contains characters organized into zero or more lines.
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
A sequence of zero or more non- <newline> characters plus a terminating <newline> character.
a non-empty file that does not end in a newline is not a text file
c
If you have a utility function to read files you can add .trim() to it to remove the extra line
j
the thing with
\n
terminated last lines (and I am a big fan of it, and wouldn鈥檛 have it any other way) is that
String.lines()
always end up with an empty string at the end, so it鈥檚 best to add
.filter(String::isNotBlank)
.
c
While we're at it, should that be filed as a bug of
lines()
? We clearly don't expect a terminal
LF
character to represent an empty line.
j
Nonono, we expect lines() to behave similar to split("\n"), which wold give us empty string at the end. And even if not, it's too late to change that now after 10 years, that would be too breaking change for existing code.
c
I understand the backwards compatibility argument, but it's still going to be a weird thing everyone stumbles upon.
e
note that `readLines()`/`useLines()` do not have this issue: they handle a terminal EOL just fine
so if you use those instead of
split()
or
lines()
then you have nothing to worry about
Copy code
"a\nb\nc\n".lines() == listOf("a", "b", "c", "")
"a\nb\nc\n".reader().readLines() == listOf("a", "b", "c")
although it is more natural to use
readLines()
on a
File
than on a
String