...

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

Documentation: go.einride.tech/aip/resourcename

     1  package resourcename
     2  
     3  // RangeParents iterates over all parents of the provided resource name.
     4  // The iteration order is from root ancestor down to the closest parent.
     5  // Collection segments are included in the iteration, to not require knowing the pattern.
     6  // For full resource names, the service is omitted.
     7  func RangeParents(name string, fn func(parent string) bool) {
     8  	var sc Scanner
     9  	sc.Init(name)
    10  	// First segment: special-case to handle full resource names.
    11  	if !sc.Scan() {
    12  		return
    13  	}
    14  	start := sc.Start()
    15  	if sc.End() != len(name) && !fn(name[start:sc.End()]) {
    16  		return
    17  	}
    18  	// Scan remaining segments.
    19  	for sc.Scan() {
    20  		if sc.End() != len(name) && !fn(name[start:sc.End()]) {
    21  			return
    22  		}
    23  	}
    24  }
    25  

View as plain text