github.com/tobgu/qframe@v0.4.0/function/string.go (about) 1 package function 2 3 import "strings" 4 5 func nilSafe(f func(string) string) func(*string) *string { 6 return func(s *string) *string { 7 if s == nil { 8 return nil 9 } 10 11 result := f(*s) 12 return &result 13 } 14 } 15 16 // UpperS returns the upper case representation of s. 17 var UpperS = nilSafe(strings.ToUpper) 18 19 // LowerS returns the lower case representation of s. 20 var LowerS = nilSafe(strings.ToLower) 21 22 // StrS returns s. 23 // 24 // This may appear useless but this can be used to convert enum columns to string 25 // columns so that the two can be used as input to other functions. It is 26 // currently not possible to combine enum and string as input. 27 func StrS(s *string) *string { 28 return s 29 } 30 31 // LenS returns the length of s. 32 func LenS(s *string) int { 33 if s == nil { 34 return 0 35 } 36 37 return len(*s) 38 } 39 40 // ConcatS returns the concatenation of x and y. 41 func ConcatS(x, y *string) *string { 42 if x == nil { 43 return y 44 } 45 46 if y == nil { 47 return x 48 } 49 50 result := *x + *y 51 return &result 52 }