#Reliable, platform independent newline splitter in gleam

1 messages · Page 1 of 1 (latest)

atomic notch
#

Hello,
is there a recommended newline splitter in gleam? Like the Environment.NewLine in .NET?

fluid jackal
#

What's that?

atomic notch
#

A uniform function to split a string on newlines as different platforms split differently like \r\n on windows and \n on linux/mac

#

Just a nice api so you don't have to think about the host platform

fluid jackal
#

Cool cool

#

What would it do in contexts where you don't know the operating system?

atomic notch
#

.NET keeps a neutral stance and just does \n for unix and \n\r for non unix platforms

fluid jackal
#

Aye, I was asking what should it do when you cannot tell what platform you're running on?

deft tendon
#

Not knowing is probably non unix then?

atomic notch
#

Yeah I believe defaulting to \n would be safest

#

Sorry for my misunderstanding

fluid jackal
#

It's tricky

#

The main one is in a browser

#

Wait we could check window.navigator.platform

#

Nice

#

OK so I think that's practically enough for everything

gray root
#

My favourite thing is checking if someone is on windows and changing the breadcrumbs from Home / Etc / Etc to Home \ Etc \ Etc

fluid jackal
#

That's cute

#

Though / is also a valid windows path delimeter

#

idk why it has 2

gray root
#

Backwards compatibility

#

/ was added in later iirc

fluid jackal
#

such a silly design that OS

deft tendon
gray root
#

You can do that in most langs, I was talking about UI in a browser

#

For ex. I have a project with a team switcher that looks like this on Windows

#

And this everywhere else

deft tendon
#

why does is matter in a web ui?

gray root
#

It's just a neat easter egg

deft tendon
#

ahh i see

gray root
#

Like Louis said, it's cute 😂

deft tendon
#

I didn't know that was called breabcrumbs

gray root
#

Breadcrumbs is the name for the thing you see sometimes that shows the path to the current page, like this

cinder sandal
#

people who don't know about hansel and gretel are going to be so confused lmao.