mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 19:08:37 +00:00 
			
		
		
		
	* Fix validate() function to handle errors in embedded anon structs * Implement webhook branch filter See #2025, #3998.
		
			
				
	
	
		
			50 lines
		
	
	
		
			791 B
		
	
	
	
		
			Go
		
	
	
	
		
			Vendored
		
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			791 B
		
	
	
	
		
			Go
		
	
	
	
		
			Vendored
		
	
	
	
| package match
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"github.com/gobwas/glob/util/runes"
 | |
| 	"unicode/utf8"
 | |
| )
 | |
| 
 | |
| type List struct {
 | |
| 	List []rune
 | |
| 	Not  bool
 | |
| }
 | |
| 
 | |
| func NewList(list []rune, not bool) List {
 | |
| 	return List{list, not}
 | |
| }
 | |
| 
 | |
| func (self List) Match(s string) bool {
 | |
| 	r, w := utf8.DecodeRuneInString(s)
 | |
| 	if len(s) > w {
 | |
| 		return false
 | |
| 	}
 | |
| 
 | |
| 	inList := runes.IndexRune(self.List, r) != -1
 | |
| 	return inList == !self.Not
 | |
| }
 | |
| 
 | |
| func (self List) Len() int {
 | |
| 	return lenOne
 | |
| }
 | |
| 
 | |
| func (self List) Index(s string) (int, []int) {
 | |
| 	for i, r := range s {
 | |
| 		if self.Not == (runes.IndexRune(self.List, r) == -1) {
 | |
| 			return i, segmentsByRuneLength[utf8.RuneLen(r)]
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return -1, nil
 | |
| }
 | |
| 
 | |
| func (self List) String() string {
 | |
| 	var not string
 | |
| 	if self.Not {
 | |
| 		not = "!"
 | |
| 	}
 | |
| 
 | |
| 	return fmt.Sprintf("<list:%s[%s]>", not, string(self.List))
 | |
| }
 |