Skip to content
Snippets Groups Projects
Commit 2332f039 authored by Cornel Rautenbach's avatar Cornel Rautenbach
Browse files

Added trimP and concatP to string utils

parent 22d978fe
Branches
Tags v1.1.4
No related merge requests found
......@@ -8,7 +8,7 @@ import (
"strings"
)
// MD5HashOfAddress calculates and returns the MD5 hash of the entered address, lat and lng concatenated together. If lat and lng is blank, it is only the hash of the entered address
// MD5HashOfAddress m(E,L,L) - calculates and returns the MD5 hash of the entered address, lat and lng concatenated together. If lat and lng is blank, it is only the hash of the entered address
func MD5HashOfAddress(enteredAddress string, lat *float64, lng *float64) string {
valueToHash := enteredAddress
if lat != nil && lng != nil {
......@@ -18,7 +18,7 @@ func MD5HashOfAddress(enteredAddress string, lat *float64, lng *float64) string
return fmt.Sprintf("%X", md5.Sum([]byte(valueToHash)))
}
// MD5HashOfLowerCaseEnteredAddress calculates and returns the MD5 hash of a string after preparing the string properly.
// MD5HashOfLowerCaseEnteredAddress m(e) - calculates and returns the MD5 hash of a string after preparing the string properly.
func MD5HashOfLowerCaseEnteredAddress(enteredAddress string) string {
valueToHash := cleanLowerCaseAddress(enteredAddress)
return fmt.Sprintf("%X", md5.Sum([]byte(valueToHash)))
......
......@@ -83,3 +83,29 @@ func UnwrapString(s *string) string {
}
return *s
}
//trim specified strings, replacing empty string with nil
func Trimp(sp *string) *string {
if sp == nil {
return nil
}
s := strings.TrimSpace(*sp)
if s == "" {
return nil
}
return &s
}
//concatenate all specified non-empty strings with ", " separators
func Concatp(args ...*string) string {
s := ""
for _, arg := range args {
if args != nil && *arg != "" {
if s != "" {
s += ", "
}
s += *arg
}
}
return s
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment