Command.newlines: account for physical newlines;
authorwenzelm
Mon, 30 Aug 2010 20:11:21 +0200
changeset 38877 682c4932b3cc
parent 38876 ec7045139e70
child 38878 1d5b3175fd30
Command.newlines: account for physical newlines;
src/Pure/General/symbol.scala
src/Pure/PIDE/command.scala
--- a/src/Pure/General/symbol.scala	Mon Aug 30 16:49:41 2010 +0200
+++ b/src/Pure/General/symbol.scala	Mon Aug 30 20:11:21 2010 +0200
@@ -53,6 +53,9 @@
 
   def is_plain(c: Char): Boolean = !(c == '\r' || c == '\\' || '\ud800' <= c && c <= '\udfff')
 
+  def is_physical_newline(s: CharSequence): Boolean =
+    "\n".contentEquals(s) || "\r".contentEquals(s) || "\r\n".contentEquals(s)
+
   def is_wellformed(s: CharSequence): Boolean =
     s.length == 1 && is_plain(s.charAt(0)) || !bad_symbol.pattern.matcher(s).matches
 
--- a/src/Pure/PIDE/command.scala	Mon Aug 30 16:49:41 2010 +0200
+++ b/src/Pure/PIDE/command.scala	Mon Aug 30 20:11:21 2010 +0200
@@ -96,6 +96,10 @@
   def source(range: Text.Range): String = source.substring(range.start, range.stop)
   def length: Int = source.length
 
+  val newlines =
+    (0 /: Symbol.iterator(source)) {
+      case (n, s) => if (Symbol.is_physical_newline(s)) n + 1 else n }
+
   val range: Text.Range = Text.Range(0, length)
 
   lazy val symbol_index = new Symbol.Index(source)