gleam-lang / stdlib

🎁 Gleam's standard library
https://hexdocs.pm/gleam_stdlib/
Apache License 2.0
413 stars 152 forks source link

Issue with CRLF in string.contains() #653

Closed 22ispencer closed 2 days ago

22ispencer commented 5 days ago

I am learning gleam, and to do this i am doing the advent of code 2023, however because i'm on windows line endings are CRLF by default, when i try to parse my string i created a function to split a string by lines and i tried to use string.contains(input, "\r") however this is returning false even though the io.debug print of the string contains "\r\n".

22ispencer commented 5 days ago

upon further investigation it does work when i use string.contains(input, "\r\n"), which seems counter intuitive, could anyone explain why?

lpil commented 2 days ago

\r\n is a single grapheme. The JavaScript version however has a bug in which it does not correctly handle the unicode here and splits it in half: https://github.com/gleam-lang/stdlib/issues/584