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

StringLike.linesWithSeparators gives wrong result for the empty string #9773

Closed
scabug opened this Issue May 11, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented May 11, 2016

According to http://www.scala-lang.org/api/2.11.8/index.html#scala.collection.immutable.StringLike@linesWithSeparators:Iterator[String], "The number of strings returned is one greater than the number of line end characters in this string. For an empty string, a single empty line is returned."

But in fact, "".linesWithSeparators is an empty iterator.

Either documentation or implementation has to be fixed. On one hand, the documented behavior is what I expected before reading, but on the other there probably are applications/libraries relying on the current one...

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 11, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9773?orig=1
Reporter: @alexeyr
Affected Versions: 2.11.8, 2.12.0-M3

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 12, 2016

@som-snytt said (edited on May 12, 2016 6:02:47 PM UTC):
In ancient times, it would claim hasNext and then throw on next. That was fixed when StringLike replaced RichString.

The doc is plain wrong, since "a\nb" and "a\nb\n" are both two elements.

However, the impl is also wrong because it ought to work like split, except retaining the separators in the preceding element.

scala/scala#5160

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 17, 2016

@lrytz said:
scala/scala#5161 - the doc was fixed in the end, the impl remained unchanged.

@scabug scabug closed this May 17, 2016

@scabug scabug added this to the 2.12.0-M5 milestone Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.