src/Pure/General/bytes.scala
changeset 80479 762fcf8f9ced
parent 80474 66ebeae3acdc
child 80480 972f7a4cdc0e
equal deleted inserted replaced
80478:902e6da44a68 80479:762fcf8f9ced
   388       slice(0, size - 1)
   388       slice(0, size - 1)
   389     }
   389     }
   390     else this
   390     else this
   391 
   391 
   392 
   392 
       
   393   /* separated chunks */
       
   394 
       
   395   def separated_chunks(sep: Byte): Iterator[Bytes] =
       
   396     new Iterator[Bytes] {
       
   397       private var start: Long = -1
       
   398       private var stop: Long = -1
       
   399 
       
   400       private def end(i: Long): Long = {
       
   401         var j = i
       
   402         while (j < Bytes.this.size && byte_unchecked(j) != sep) { j += 1 }
       
   403         j
       
   404       }
       
   405 
       
   406       // init
       
   407       if (!Bytes.this.is_empty) { start = 0; stop = end(0) }
       
   408 
       
   409       def hasNext: Boolean =
       
   410         0 <= start && start <= stop && stop <= Bytes.this.size
       
   411 
       
   412       def next(): Bytes =
       
   413         if (hasNext) {
       
   414           val chunk = Bytes.this.slice(start, stop)
       
   415           if (stop < Bytes.this.size) { start = stop + 1; stop = end(start) }
       
   416           else { start = -1; stop = -1 }
       
   417           chunk
       
   418         }
       
   419         else throw new NoSuchElementException
       
   420     }
       
   421 
       
   422   def space_explode(sep: Byte): List[Bytes] = separated_chunks(sep).toList
       
   423 
       
   424   def split_lines: List[Bytes] = space_explode(10)
       
   425 
       
   426 
   393   /* hash and equality */
   427   /* hash and equality */
   394 
   428 
   395   lazy val sha1_digest: SHA1.Digest =
   429   lazy val sha1_digest: SHA1.Digest =
   396     if (is_empty) SHA1.digest_empty
   430     if (is_empty) SHA1.digest_empty
   397     else {
   431     else {