Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
pr feadback. replaced clean string function with call to
Browse files Browse the repository at this point in the history
strings.TrimSpace + strings.Trim
  • Loading branch information
jsirianni committed Mar 30, 2022
1 parent 4e85f4b commit c182e23
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 36 deletions.
33 changes: 4 additions & 29 deletions operator/parser/keyvalue/keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c KVParserConfig) Build(logger *zap.SugaredLogger) (operator.Operator, err
return nil, errors.New("delimiter and pair_delimiter cannot be the same value")
}

if len(c.Delimiter) == 0 {
if c.Delimiter == "" {
return nil, errors.New("delimiter is a required parameter")
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (kv *KVParser) parse(value interface{}) (interface{}, error) {
}

func (kv *KVParser) parser(input string, delimiter string) (map[string]interface{}, error) {
if len(input) == 0 {
if input == "" {
return nil, fmt.Errorf("parse from field %s is empty", kv.ParseFrom.String())
}

Expand All @@ -117,8 +117,8 @@ func (kv *KVParser) parser(input string, delimiter string) (map[string]interface
continue
}

key := cleanString(m[0])
value := cleanString(m[1])
key := strings.TrimSpace(strings.Trim(m[0], "\"'"))
value := strings.TrimSpace(strings.Trim(m[1], "\"'"))

parsed[key] = value
}
Expand All @@ -137,28 +137,3 @@ func splitStringByWhitespace(input string) []string {
})
return raw
}

// remove surrounding quotes and trim leading and trailing space
func cleanString(input string) string {
if len(input) < 1 {
return input
}

if input[0] == '"' {
input = input[1:]
}

if input[len(input)-1] == '"' {
input = input[:len(input)-1]
}

if input[0] == '\'' {
input = input[1:]
}

if input[len(input)-1] == '\'' {
input = input[:len(input)-1]
}

return strings.TrimSpace(input)
}
7 changes: 0 additions & 7 deletions operator/parser/keyvalue/keyvalue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,3 @@ func TestSplitStringByWhitespace(t *testing.T) {
})
}
}

func TestCleanString(t *testing.T) {
t.Run("empty", func(t *testing.T) {
x := ""
require.Equal(t, x, cleanString(x))
})
}

0 comments on commit c182e23

Please sign in to comment.