Lines package:text-rope

Split into lines by \n, similar to Data.Text.lines. Each line is produced in O(1).
>>> :set -XOverloadedStrings

>>> lines ""
[]

>>> lines "foo"
["foo"]

>>> lines "foo\n"
["foo"]

>>> lines "foo\n\n"
["foo",""]

>>> lines "foo\nbar"
["foo","bar"]
Split into lines by \n, similar to Data.Text.lines. Each line is produced in O(1).
>>> :set -XOverloadedStrings

>>> lines ""
[]

>>> lines "foo"
["foo"]

>>> lines "foo\n"
["foo"]

>>> lines "foo\n\n"
["foo",""]

>>> lines "foo\nbar"
["foo","bar"]
A wrapper around Text for fast line/column navigation. Concatenation takes linear time. This is a building block for Rope, which provides logarithmic concatenation.
Equivalent to length . lines, but in O(1).
>>> :set -XOverloadedStrings

>>> lengthInLines ""
0

>>> lengthInLines "foo"
1

>>> lengthInLines "foo\n"
1

>>> lengthInLines "foo\n\n"
2

>>> lengthInLines "foo\nbar"
2
Create from TextLines, linear time.
Equivalent to length . lines, but in logarithmic time.
>>> :set -XOverloadedStrings

>>> lengthInLines ""
0

>>> lengthInLines "foo"
1

>>> lengthInLines "foo\n"
1

>>> lengthInLines "foo\n\n"
2

>>> lengthInLines "foo\nbar"
2
If you do not care about ignoring the last newline character, you can use posLine . charLengthAsPosition instead, which works in O(1).
Glue chunks into TextLines, linear time.
Equivalent to length . lines, but in logarithmic time.
>>> :set -XOverloadedStrings

>>> lengthInLines ""
0

>>> lengthInLines "foo"
1

>>> lengthInLines "foo\n"
1

>>> lengthInLines "foo\n\n"
2

>>> lengthInLines "foo\nbar"
2
If you do not care about ignoring the last newline character, you can use posLine . lengthAsPosition instead, which works in O(1).