Skip to content
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

lines & unlines #28

Closed
chemist opened this issue Aug 5, 2014 · 4 comments
Closed

lines & unlines #28

chemist opened this issue Aug 5, 2014 · 4 comments

Comments

@chemist
Copy link

chemist commented Aug 5, 2014

In Bytestring, String and Text EOL always '\n', but in windows its \r\n
how about separate version for lines, unlines?
lines can be universal, and unlines like
unlinesUniversal :: EOL -> [ByteString] -> ByteString

Its not critical, but can be useful.

@dcoutts
Copy link
Contributor

dcoutts commented Nov 9, 2014

I don't like this very much, even on Windows if you open a file in text mode then you'll get \r\n conversion. The more general thing is then splitting, which we should do by integrating or extending the split package for ByteString (and Text).

Leaving this open for discussion though.

@rahulmutt
Copy link

rahulmutt commented Mar 25, 2018

It would be really useful to have unlinesUniversal or even patch unlines to handle \r too because the current implementation violates the principle of least astonishment.

The intuition any beginner Haskeller gets from using the lines function for String is that it returns proper lines without the \r character. You'll write a code assuming that ByteString's version of lines works in a cross-platform way.

I'd be happy to send a PR if the maintainers are fine with it. I wasted half a day finding a bug in a parser only to find that it was working under the assumption that the lines function strips away the \r as well for Windows. I hope to prevent this for anyone else in the future.

There should at least be a line in the documentation in bold letters saying that lines doesn't strip off \r because that's very important to know.

fumieval added a commit to fumieval/bytestring that referenced this issue Jul 7, 2020
fumieval added a commit to fumieval/bytestring that referenced this issue Jul 8, 2020
sjakobi pushed a commit that referenced this issue Jul 17, 2020
* add haddock comments about the behaviour of IsString instances (#140)

* Correct the documentation of split and so on (fixes #161)

* Document the behaviour of unsafeUseAsCStringLen when BS.empty is passed (fixes #207)

* s/encodeListWithB/primMapListBounded/ (fixes #50)

* Fix broken links in Data.ByteString.Prim

* Fix all missing Haddock links

* Note that `lines` doesn't handle CR (#28)

* encodeByteStringWithF seems to actually mean primMapByteStringFixed
@Bodigrim
Copy link
Contributor

The intuition any beginner Haskeller gets from using the lines function for String is that it returns proper lines without the \r character.

I cannot find any special treatment for \r in Data.List.lines:

> lines "foo\r\nbar"
["foo\r","bar"]

So Data.ByteString.lines is in line with its Prelude counterpart. This behaviour has been recently reflected in the documentation. A general splitOn function is discussed in #100.

I'm in favor of closing this.

@sjakobi
Copy link
Member

sjakobi commented Oct 1, 2020

I agree with closing this issue.

@sjakobi sjakobi closed this as completed Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants