equal
deleted
inserted
replaced
10 import scala.annotation.tailrec |
10 import scala.annotation.tailrec |
11 |
11 |
12 |
12 |
13 object Line |
13 object Line |
14 { |
14 { |
|
15 /* logical lines */ |
|
16 |
|
17 def normalize(text: String): String = |
|
18 if (text.contains('\r')) text.replace("\r\n", "\n") else text |
|
19 |
|
20 def logical_lines(text: String): List[String] = |
|
21 Library.split_lines(normalize(text)) |
|
22 |
|
23 |
15 /* position */ |
24 /* position */ |
16 |
25 |
17 object Position |
26 object Position |
18 { |
27 { |
19 val zero: Position = Position() |
28 val zero: Position = Position() |
32 } |
41 } |
33 |
42 |
34 def advance(text: String, text_length: Text.Length): Position = |
43 def advance(text: String, text_length: Text.Length): Position = |
35 if (text.isEmpty) this |
44 if (text.isEmpty) this |
36 else { |
45 else { |
37 val lines = Library.split_lines(text) |
46 val lines = logical_lines(text) |
38 val l = line + lines.length - 1 |
47 val l = line + lines.length - 1 |
39 val c = (if (l == line) column else 0) + text_length(Library.trim_line(lines.last)) |
48 val c = (if (l == line) column else 0) + text_length(Library.trim_line(lines.last)) |
40 Position(l, c) |
49 Position(l, c) |
41 } |
50 } |
42 } |
51 } |
79 /* document with newline as separator (not terminator) */ |
88 /* document with newline as separator (not terminator) */ |
80 |
89 |
81 object Document |
90 object Document |
82 { |
91 { |
83 def apply(text: String, text_length: Text.Length): Document = |
92 def apply(text: String, text_length: Text.Length): Document = |
84 if (text.contains('\r')) |
93 Document(logical_lines(text).map(Line(_)), text_length) |
85 Document(Library.split_lines(text).map(s => Line(Library.trim_line(s))), text_length) |
|
86 else |
|
87 Document(Library.split_lines(text).map(s => Line(s)), text_length) |
|
88 } |
94 } |
89 |
95 |
90 sealed case class Document(lines: List[Line], text_length: Text.Length) |
96 sealed case class Document(lines: List[Line], text_length: Text.Length) |
91 { |
97 { |
92 def make_text: String = lines.mkString("", "\n", "") |
98 def make_text: String = lines.mkString("", "\n", "") |