...

Source file src/go.einride.tech/aip/resourcename/ancestor.go

Documentation: go.einride.tech/aip/resourcename

     1  package resourcename
     2  
     3  // Ancestor extracts an ancestor from the provided name, using a pattern for the ancestor.
     4  func Ancestor(name, pattern string) (string, bool) {
     5  	if name == "" || pattern == "" {
     6  		return "", false
     7  	}
     8  	var scName, scPattern Scanner
     9  	scName.Init(name)
    10  	scPattern.Init(pattern)
    11  	for scPattern.Scan() {
    12  		if !scName.Scan() {
    13  			return "", false
    14  		}
    15  		segment := scPattern.Segment()
    16  		if segment.IsWildcard() {
    17  			return "", false // wildcards not supported in patterns
    18  		}
    19  		if !segment.IsVariable() && segment != scName.Segment() {
    20  			return "", false // not a match
    21  		}
    22  	}
    23  	return name[:scName.end], true
    24  }
    25  

View as plain text