gitlab.com/evatix-go/core@v1.3.55/coreutils/stringutil/SafeSubstring.go (about)

     1  package stringutil
     2  
     3  import "gitlab.com/evatix-go/core/constants"
     4  
     5  // SafeSubstring content[startAt:endAt]
     6  func SafeSubstring(
     7  	content string,
     8  	startAt, endingLength int,
     9  ) string {
    10  	if startAt == -1 && endingLength == -1 {
    11  		return content
    12  	}
    13  
    14  	length := len(content)
    15  
    16  	if length == 0 {
    17  		return content
    18  	}
    19  
    20  	if startAt == -1 {
    21  		return SafeSubstringEnds(content, endingLength)
    22  	}
    23  
    24  	if endingLength == -1 {
    25  		return SafeSubstringStarts(content, startAt)
    26  	}
    27  
    28  	if startAt < length && endingLength <= length && startAt <= endingLength {
    29  		return content[startAt:endingLength]
    30  	}
    31  
    32  	return constants.EmptyString
    33  }