github.com/tencent/goom@v1.0.1/internal/patch/generics_18.go (about)

     1  //go:build go1.18 && !go1.20
     2  // +build go1.18,!go1.20
     3  
     4  package patch
     5  
     6  import (
     7  	"fmt"
     8  	"regexp"
     9  	"strings"
    10  )
    11  
    12  var (
    13  	nameMatch = "\\.func(\\d)*(\\.\\d+)*$"
    14  	nameReg   = regexp.MustCompile(nameMatch)
    15  )
    16  
    17  func init() {
    18  	//解析正则表达式,如果成功返回解释器
    19  	if nameReg == nil {
    20  		fmt.Println("regexp err")
    21  		return
    22  	}
    23  }
    24  
    25  // IsGenericsFunc 是否为泛型函数
    26  func IsGenericsFunc(name string) bool {
    27  	if isGenericsFunc20(name) {
    28  		return true
    29  	}
    30  	result := nameReg.FindString(name)
    31  	return len(result) > 0
    32  }
    33  
    34  // isGenericsFunc20 是否为泛型函数,同时兼容20版本的命名格式
    35  func isGenericsFunc20(name string) bool {
    36  	return strings.Contains(name, "[...]")
    37  }