github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/pad.go (about)

     1  package functions
     2  
     3  import "strings"
     4  
     5  func PadLeft(args ...interface{}) interface{} {
     6  	if len(args) != 3 {
     7  		return ""
     8  	}
     9  
    10  	input, ok := args[0].(string)
    11  	if !ok {
    12  		return ""
    13  	}
    14  
    15  	length, ok := args[1].(int)
    16  	if !ok {
    17  		return ""
    18  	}
    19  
    20  	pad, ok := args[2].(string)
    21  	if !ok {
    22  		return ""
    23  	}
    24  
    25  	if len(input) >= length {
    26  		return input
    27  	}
    28  
    29  	repeat := (length - len(input)) / len(pad)
    30  
    31  	return strings.Repeat(pad, repeat) + input
    32  }