src/Pure/PIDE/text.scala
changeset 65154 ba1929b749f0
parent 65132 60e7072b8dbe
child 65155 25bccf5bf33e
equal deleted inserted replaced
65153:82bd5d29adbf 65154:ba1929b749f0
    26     def apply(start: Offset): Range = Range(start, start)
    26     def apply(start: Offset): Range = Range(start, start)
    27 
    27 
    28     val full: Range = apply(0, Integer.MAX_VALUE / 2)
    28     val full: Range = apply(0, Integer.MAX_VALUE / 2)
    29     val offside: Range = apply(-1)
    29     val offside: Range = apply(-1)
    30 
    30 
    31     object Ordering extends scala.math.Ordering[Text.Range]
    31     object Ordering extends scala.math.Ordering[Range]
    32     {
    32     {
    33       def compare(r1: Text.Range, r2: Text.Range): Int = r1 compare r2
    33       def compare(r1: Range, r2: Range): Int = r1 compare r2
    34     }
    34     }
    35   }
    35   }
    36 
    36 
    37   sealed case class Range(start: Offset, stop: Offset)
    37   sealed case class Range(start: Offset, stop: Offset)
    38   {
    38   {
    82 
    82 
    83     def full: Perspective = Perspective(List(Range.full))
    83     def full: Perspective = Perspective(List(Range.full))
    84 
    84 
    85     def apply(ranges: Seq[Range]): Perspective =
    85     def apply(ranges: Seq[Range]): Perspective =
    86     {
    86     {
    87       val result = new mutable.ListBuffer[Text.Range]
    87       val result = new mutable.ListBuffer[Range]
    88       var last: Option[Text.Range] = None
    88       var last: Option[Range] = None
    89       def ship(next: Option[Range]) { result ++= last; last = next }
    89       def ship(next: Option[Range]) { result ++= last; last = next }
    90 
    90 
    91       for (range <- ranges.sortBy(_.start))
    91       for (range <- ranges.sortBy(_.start))
    92       {
    92       {
    93         last match {
    93         last match {
   122   }
   122   }
   123 
   123 
   124 
   124 
   125   /* information associated with text range */
   125   /* information associated with text range */
   126 
   126 
   127   sealed case class Info[A](range: Text.Range, info: A)
   127   sealed case class Info[A](range: Range, info: A)
   128   {
   128   {
   129     def restrict(r: Text.Range): Info[A] = Info(range.restrict(r), info)
   129     def restrict(r: Range): Info[A] = Info(range.restrict(r), info)
   130     def try_restrict(r: Text.Range): Option[Info[A]] = range.try_restrict(r).map(Info(_, info))
   130     def try_restrict(r: Range): Option[Info[A]] = range.try_restrict(r).map(Info(_, info))
   131 
   131 
   132     def map[B](f: A => B): Info[B] = Info(range, f(info))
   132     def map[B](f: A => B): Info[B] = Info(range, f(info))
   133   }
   133   }
   134 
   134 
   135   type Markup = Info[XML.Elem]
   135   type Markup = Info[XML.Elem]
   192   /* text length wrt. encoding */
   192   /* text length wrt. encoding */
   193 
   193 
   194   trait Length
   194   trait Length
   195   {
   195   {
   196     def apply(text: String): Int
   196     def apply(text: String): Int
   197     def offset(text: String, i: Int): Option[Text.Offset]
   197     def offset(text: String, i: Int): Option[Offset]
   198   }
   198   }
   199 
   199 
   200   object Length extends Length
   200   object Length extends Length
   201   {
   201   {
   202     def apply(text: String): Int = text.length
   202     def apply(text: String): Int = text.length
   203     def offset(text: String, i: Int): Option[Text.Offset] =
   203     def offset(text: String, i: Int): Option[Offset] =
   204       if (0 <= i && i <= text.length) Some(i) else None
   204       if (0 <= i && i <= text.length) Some(i) else None
   205 
   205 
   206     val encodings: List[(String, Length)] =
   206     val encodings: List[(String, Length)] =
   207       List(
   207       List(
   208         "UTF-16" -> Length,
   208         "UTF-16" -> Length,