src/Pure/PIDE/line.scala
changeset 64821 37bf7acf6a4b
parent 64820 00488a8c042f
child 64822 c8bac4b0ef07
equal deleted inserted replaced
64820:00488a8c042f 64821:37bf7acf6a4b
    93       Document(logical_lines(text).map(s => Line(Library.trim_substring(s))), text_length)
    93       Document(logical_lines(text).map(s => Line(Library.trim_substring(s))), text_length)
    94   }
    94   }
    95 
    95 
    96   sealed case class Document(lines: List[Line], text_length: Text.Length)
    96   sealed case class Document(lines: List[Line], text_length: Text.Length)
    97   {
    97   {
    98     def make_text: String = lines.mkString("", "\n", "")
    98     lazy val text: String = lines.mkString("", "\n", "")
       
    99     lazy val bytes: Bytes = Bytes(text)
       
   100     lazy val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(text)
    99 
   101 
   100     override def toString: String = make_text
   102     lazy val length: Int =
       
   103       if (lines.isEmpty) 0
       
   104       else ((0 /: lines) { case (n, line) => n + line.text.length + 1 }) - 1
       
   105 
       
   106     def text_range: Text.Range = Text.Range(0, length)
       
   107 
       
   108     override def toString: String = text
   101 
   109 
   102     override def equals(that: Any): Boolean =
   110     override def equals(that: Any): Boolean =
   103       that match {
   111       that match {
   104         case other: Document => lines == other.lines
   112         case other: Document => lines == other.lines
   105         case _ => false
   113         case _ => false
   134           (0 /: lines.iterator.take(l)) { case (n, line) => n + text_length(line.text) + 1 }
   142           (0 /: lines.iterator.take(l)) { case (n, line) => n + text_length(line.text) + 1 }
   135         text_length.offset(lines(l).text, c).map(line_offset + _)
   143         text_length.offset(lines(l).text, c).map(line_offset + _)
   136       }
   144       }
   137       else None
   145       else None
   138     }
   146     }
   139 
       
   140     lazy val length: Int =
       
   141       if (lines.isEmpty) 0
       
   142       else ((0 /: lines) { case (n, line) => n + line.text.length + 1 }) - 1
       
   143 
       
   144     def full_range: Text.Range = Text.Range(0, length)
       
   145 
       
   146     lazy val blob: (Bytes, Symbol.Text_Chunk) =
       
   147     {
       
   148       val text = make_text
       
   149       (Bytes(text), Symbol.Text_Chunk(text))
       
   150     }
       
   151   }
   147   }
   152 
   148 
   153 
   149 
   154   /* line text */
   150   /* line text */
   155 
   151