Skip to content

OffsetPosition lineContents includes newline #7483

Closed
@scabug

Description

@scabug

The method lineContents of OffsetPosition includes newlines contrary to the statement in the comment:

scala> val s = "foo\nbar"
s: String = 
foo
bar

scala> val reader = new CharSequenceReader(s.toCharArray(), 0)
reader: scala.util.parsing.input.CharSequenceReader = scala.util.parsing.input.CharSequenceReader@4ad5e1aa

scala> val p = reader.pos.asInstanceOf[OffsetPosition]
p: scala.util.parsing.input.OffsetPosition = 1.1

scala> p.lineContents
res6: String = 
"foo
"

This issue is fixed by adjusting the end index of lineContents:

def lineContents: String =
    source.subSequence(index(line - 1), index(line) - 1).toString

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions