scala-io icon indicating copy to clipboard operation
scala-io copied to clipboard

Explicitly specifying RNPair line terminator truncates last line

Open asflierl opened this issue 11 years ago • 1 comments

In the following REPL session, res1 clearly is wrong, it should be equivalent to res2. This only seems to happen with RNPair. Using NewLine or CarriageReturn seems fine.

The version of scala-io I used is 0.4.2.

Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_38).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import scalax.file.Path
import scalax.file.Path

scala> import scalax.io.Line.Terminators.RNPair
import scalax.io.Line.Terminators.RNPair

scala> val f = Path.createTempFile()
f: scalax.file.defaultfs.DefaultPath = Path(/tmp/_UBQ4rn7147447547355346080.tmp)

scala> f.writeStrings(Seq("abc","def"), RNPair sep)

scala> f.lines(RNPair).toList
res1: List[String] = List(abc, d)

scala> f.lines().toList
res2: List[String] = List(abc, def)

asflierl avatar Apr 09 '13 08:04 asflierl

Reproduced with current master on 2.12 branch:

scala> import Line.Terminators.Custom
scala> import java.io.StringReader

scala> val resource = Resource.fromReader(new StringReader("foo**bar**bogus"))scala> resource.string
res4: String = foo**bar**bogus

scala> // read each segment ending in ** but do not include **
     | val lines = resource.lines(terminator=Custom("**"), includeTerminator=false)
lines: scalax.io.LongTraversable[String] = LongTraversable(...)

scala> lines.toList
res6: List[String] = List(foo, bar, bog)

rtyley avatar Aug 26 '17 08:08 rtyley