Advertisement
Guest User

searchforwards(predicate)

a guest
Mar 12th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.01 KB | None | 0 0
  1.  /**
  2.     *
  3.     * Search Forwards.  This generalises the character version of find forwards
  4.     *
  5.     * The user provides a predicate to specify the search condition.
  6.     *
  7.     * This operation does not change any variable other than the cursor position.
  8.     *
  9.     */
  10.  
  11.   def sf( p: Char => Boolean ): Boolean = {
  12.  
  13.     /*    def currentPos( pos: Int ): Option[Int] = {
  14.           if ( pos >= end ) None
  15.           else if ( p( buffer( pos ) ) ) {
  16.             cursor = pos
  17.             Some( pos )
  18.           }
  19.           else currentPos( pos + 1 )
  20.         }
  21.      
  22.         currentPos( 0 )
  23.      
  24.         buffer.find( p ) match {
  25.           case Some( _ ) => true
  26.           case None => false
  27.         }*/
  28.  
  29.     /*    var b =false
  30.         for (i <- cursor until end if !b) {
  31.           if (p(buffer(i))) {
  32.             cursor = i
  33.             b = true
  34.           }
  35.         }
  36.         b*/
  37.  
  38.     var c = false
  39.     ( cursor until end ) collectFirst { case i if p( buffer( i ) ) => cursor = i; c = true }
  40.     c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement