gitlab.com/evatix-go/core@v1.3.55/coreappend/PrependAppendAnyItemsToStringsUsingFunc.go (about)

     1  package coreappend
     2  
     3  func PrependAppendAnyItemsToStringsUsingFunc(
     4  	isSkipEmptyString bool,
     5  	compilerFunc func(item interface{}) string,
     6  	prependItem, appendItem interface{},
     7  	anyItems ...interface{},
     8  ) []string {
     9  	slice := make([]string, 0, len(anyItems)+3)
    10  
    11  	prependString := compilerFunc(prependItem)
    12  
    13  	if isSkipEmptyString && prependString != "" {
    14  		slice = append(
    15  			slice,
    16  			prependString)
    17  	} else if !isSkipEmptyString {
    18  		slice = append(
    19  			slice,
    20  			prependString)
    21  	}
    22  
    23  	for _, item := range anyItems {
    24  		if item == nil {
    25  			continue
    26  		}
    27  
    28  		currentStr := compilerFunc(item)
    29  
    30  		if isSkipEmptyString && currentStr == "" {
    31  			continue
    32  		}
    33  
    34  		slice = append(
    35  			slice,
    36  			currentStr)
    37  	}
    38  
    39  	appendString := compilerFunc(appendItem)
    40  
    41  	if isSkipEmptyString && appendString != "" {
    42  		slice = append(
    43  			slice,
    44  			appendString)
    45  	} else if !isSkipEmptyString {
    46  		slice = append(
    47  			slice,
    48  			appendString)
    49  	}
    50  
    51  	return slice
    52  }