...

Source file src/github.com/gobwas/glob/match/max.go

Documentation: github.com/gobwas/glob/match

     1  package match
     2  
     3  import (
     4  	"fmt"
     5  	"unicode/utf8"
     6  )
     7  
     8  type Max struct {
     9  	Limit int
    10  }
    11  
    12  func NewMax(l int) Max {
    13  	return Max{l}
    14  }
    15  
    16  func (self Max) Match(s string) bool {
    17  	var l int
    18  	for range s {
    19  		l += 1
    20  		if l > self.Limit {
    21  			return false
    22  		}
    23  	}
    24  
    25  	return true
    26  }
    27  
    28  func (self Max) Index(s string) (int, []int) {
    29  	segments := acquireSegments(self.Limit + 1)
    30  	segments = append(segments, 0)
    31  	var count int
    32  	for i, r := range s {
    33  		count++
    34  		if count > self.Limit {
    35  			break
    36  		}
    37  		segments = append(segments, i+utf8.RuneLen(r))
    38  	}
    39  
    40  	return 0, segments
    41  }
    42  
    43  func (self Max) Len() int {
    44  	return lenNo
    45  }
    46  
    47  func (self Max) String() string {
    48  	return fmt.Sprintf("<max:%d>", self.Limit)
    49  }
    50  

View as plain text