gitlab.com/evatix-go/core@v1.3.55/coreutils/stringutil/SafeSubstringEnds.go (about) 1 package stringutil 2 3 import "gitlab.com/evatix-go/core/constants" 4 5 // SafeSubstringEnds 6 // 7 // content[:endingLen] 8 // 9 // -1 meaning upto the length 10 func SafeSubstringEnds( 11 content string, 12 endingLen int, 13 ) string { 14 length := len(content) 15 16 if length == 0 { 17 return constants.EmptyString 18 } 19 20 if length <= endingLen || endingLen == -1 { 21 return content[:length] 22 } 23 24 return content[:endingLen] 25 }