Skip to content

Commit d10a312

Browse files
authored
[collection] exposing ParseListWithCleanup (#70)
1 parent cf9814b commit d10a312

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

changes/202204061624.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[collection] `ParseListWithCleanup` is now available for parsing strings containing lists

utils/collection/parseLists.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ package collection
66

77
import "strings"
88

9-
// Removes spaces leaving only the strings
10-
func parseListWithCleanup(input string, sep string) (newS []string) {
9+
// ParseListWithCleanup splits a string into a list like strings.Split but also removes any whitespace surrounding the different items
10+
// for example,
11+
// ParseListWithCleanup("a, b , c", ",") returns []{"a","b","c"}
12+
func ParseListWithCleanup(input string, sep string) (newS []string) {
1113
if len(input) == 0 {
1214
newS = []string{} // initialisation of empty arrays in function returns []string(nil) instead of []string{}
1315
return
@@ -22,6 +24,7 @@ func parseListWithCleanup(input string, sep string) (newS []string) {
2224
return
2325
}
2426

27+
// ParseCommaSeparatedList returns the list of string separated by a comma
2528
func ParseCommaSeparatedList(input string) []string {
26-
return parseListWithCleanup(input, ",")
29+
return ParseListWithCleanup(input, ",")
2730
}

utils/collection/parseLists_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestParseCommaSeparatedListWordsOnly(t *testing.T) {
3131
require.Equal(t, stringArray, finalList)
3232
}
3333

34-
// Test to makje sure that spaces that show up within the words aren't removed
34+
// Test to make sure that spaces that show up within the words aren't removed
3535
func TestParseCommaSeparatedListWithSpacesBetweenWords(t *testing.T) {
3636
stringList := ""
3737
stringArray := []string{}

0 commit comments

Comments
 (0)