#Is there a cross platform newline?

1 messages · Page 1 of 1 (latest)

unborn fable
#

So I don't have to bake in this

#

like I know there is std.fs.path.delimiter

kind shell
#

you can just make a utility constant, I'm fairly certain the only difference between platforms is that windows uses \r\n

unborn fable
#

yeah windows uses \r\n

kind shell
#

yea I'd just do that

#

looks like std.log.* just uses \n in all cases, so I doubt there's anything in the standard library

unborn fable
#

i mean it's console

#

in files it's different

#

im tokenizing a file

#

windows can also have only \n tho...

kind shell
#

if you're tokenising a file then I'd just have an optional \r before each \n

#

don't do it based on the platform

unborn fable
#

how do I do that lol

kind shell
#

I don't know how you're tokenising the file so I can't say

unborn fable
#

std.mem.tokenize

#

i mean I can probably just ignore \r...

kind shell
#

yeah or that

unborn fable
#

i'll just have to make sure then it does not get into a hash map lol

#

yeah but thx

plush shadow
#

std.mem.tokenizeAny(u8, buffer, &std.ascii.whitespace)

kind shell
#

not all whitespace necessarily can be used as a delimeter

#

and also I think that would split twice on each newline on windows, like "a\r\nb" -> "a", "", "b"

edgy agate
#

that's split, tokenize skips empty

kind shell
#

fair enough

edgy agate
#

std.mem.tokenizeAny(u8, buffer, "\r\n") should handle all three newline variants

plush shadow
#

ah true, should be only these two, not all whitespace

edgy agate
#

it's not really correct to hardcode an os-specific sequence when reading - there's no guarantee a file on that os will follow that convention