github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/op/string_/api.go (about)

     1  // Package string_ provides string utils
     2  package string_
     3  
     4  // WrapNonEmpty returns wrapped the target string if it is non-empty
     5  func WrapNonEmpty(pref, target, post string) string {
     6  	if len(target) == 0 {
     7  		return ""
     8  	}
     9  	return pref + target + post
    10  }
    11  
    12  // JoinNonEmpty returns concatenated string
    13  func JoinNonEmpty(first, joiner, second string) string {
    14  	if len(first) == 0 || len(second) == 0 {
    15  		return first + second
    16  	}
    17  	return first + joiner + second
    18  }
    19  
    20  // Empty checks whether the specified string is empty
    21  func Empty(s string) bool {
    22  	return len(s) == 0
    23  }
    24  
    25  // NotEmpty checks whether the specified string is not empty
    26  func NotEmpty(s string) bool {
    27  	return !Empty(s)
    28  }