src/Pure/General/bytes.scala
changeset 80355 5a555acad203
parent 80353 52154fef991d
child 80356 8365f1e7955e
equal deleted inserted replaced
80354:e5a6b3f1f377 80355:5a555acad203
   112     using(new FileOutputStream(file, true))(bytes.write_stream(_))
   112     using(new FileOutputStream(file, true))(bytes.write_stream(_))
   113 
   113 
   114   def append(path: Path, bytes: Bytes): Unit = append(path.file, bytes)
   114   def append(path: Path, bytes: Bytes): Unit = append(path.file, bytes)
   115 
   115 
   116 
   116 
   117   /* vector of unsigned integers */
   117   /* vector of short unsigned integers */
   118 
   118 
   119   trait Vec {
   119   trait Vec {
   120     def size: Long
   120     def size: Long
   121     def apply(i: Long): Int
   121     def apply(i: Long): Char
   122   }
   122   }
   123 
   123 
   124   class Vec_String(string: String) extends Vec {
   124   class Vec_String(string: String) extends Vec {
   125     override def size: Long = string.length.toLong
   125     override def size: Long = string.length.toLong
   126     override def apply(i: Long): Int =
   126     override def apply(i: Long): Char =
   127       if (0 <= i && i < size) string(i.toInt).toInt
   127       if (0 <= i && i < size) string(i.toInt)
   128       else throw new IndexOutOfBoundsException
   128       else throw new IndexOutOfBoundsException
   129   }
   129   }
   130 }
   130 }
   131 
   131 
   132 final class Bytes private(
   132 final class Bytes private(
   217 
   217 
   218   /* Vec operations */
   218   /* Vec operations */
   219 
   219 
   220   def size: Long = length.toLong
   220   def size: Long = length.toLong
   221 
   221 
   222   def apply(i: Long): Int =
   222   def apply(i: Long): Char =
   223     if (0 <= i && i < size) bytes((offset + i).toInt).asInstanceOf[Int] & 0xFF
   223     if (0 <= i && i < size) (bytes((offset + i).toInt).asInstanceOf[Int] & 0xFF).asInstanceOf[Char]
   224     else throw new IndexOutOfBoundsException
   224     else throw new IndexOutOfBoundsException
   225 
   225 
   226 
   226 
   227   /* slice */
   227   /* slice */
   228 
   228