Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions strings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ func IsNotEmptyP(s *string) bool {
func IsNotEmpty(s string) bool {
return len(s) > 0
}

// PointerValue returns the string value from the pointer or empty string if nil
func PointerValue(s *string) string {
if s == nil {
return ""
}
return *s
}
9 changes: 9 additions & 0 deletions strings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,12 @@ func Test_IsNotEmpty(t *testing.T) {
assert.True(strings.IsNotEmpty("str"))
assert.True(strings.IsNotEmpty(" str "))
}

func Test_PointerValue(t *testing.T) {
assert := assert.New(t)
assert.Equal("", strings.PointerValue(nil))
assert.Equal("", strings.PointerValue(pointer.To("")))
assert.Equal(" ", strings.PointerValue(pointer.To(" ")))
assert.Equal("str", strings.PointerValue(pointer.To("str")))
assert.Equal(" str ", strings.PointerValue(pointer.To(" str ")))
}
Loading