From 2332f0397ab4af7d9a8c218fb5eec62ec4f7f721 Mon Sep 17 00:00:00 2001
From: Cornelius Rautenbach <cornel.rautenbach@gmail.com>
Date: Fri, 17 Sep 2021 14:26:10 +0200
Subject: [PATCH] Added trimP and concatP to string utils

---
 address_utils/address_utils.go |  4 ++--
 string_utils/string_utils.go   | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/address_utils/address_utils.go b/address_utils/address_utils.go
index f955fed..f8c5556 100644
--- a/address_utils/address_utils.go
+++ b/address_utils/address_utils.go
@@ -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)))
diff --git a/string_utils/string_utils.go b/string_utils/string_utils.go
index 5ae232b..2778aea 100644
--- a/string_utils/string_utils.go
+++ b/string_utils/string_utils.go
@@ -82,4 +82,30 @@ func UnwrapString(s *string) string {
 		return ""
 	}
 	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
-- 
GitLab