diff --git a/utils/tags.go b/utils/tags.go index 6bd4bef..275329f 100644 --- a/utils/tags.go +++ b/utils/tags.go @@ -109,6 +109,17 @@ func FindWords(str []byte, offset int) []string { return words } +func SplitWords(str string) ([]string, error) { + offset := 0 + words := make([]string, 0) + for offset < len(str) { + word, i := _findWord([]byte(str), offset, " \n\r\t", isQuoteCharInternal) + words = append(words, word) + offset = i + } + return words, nil +} + func FindWords2(str []byte, offset int, sepChars string, isQuoteChar func(ch byte) (bool, string)) ([]string, error) { words := make([]string, 0) for offset < len(str) { diff --git a/utils/tags_test.go b/utils/tags_test.go index 0b5f364..a809de8 100644 --- a/utils/tags_test.go +++ b/utils/tags_test.go @@ -80,6 +80,31 @@ func TestFindWords(t *testing.T) { } } +func TestSplitWords(t *testing.T) { + cases := []struct { + input string + want []string + }{ + { + input: `'file:///opt/test test.txt' '/data/test test.txt'`, + want: []string{"file:///opt/test test.txt", "/data/test test.txt"}, + }, + { + input: `'file:///opt/test test.txt' /data/testtest.txt`, + want: []string{"file:///opt/test test.txt", "/data/testtest.txt"}, + }, + } + for _, c := range cases { + got, err := SplitWords(c.input) + if err != nil { + t.Errorf("input %s got error %s", c.input, err) + } + if !reflect.DeepEqual(got, c.want) { + t.Errorf("input %s got %#v want %#v", c.input, got, c.want) + } + } +} + func TestSplitCSV(t *testing.T) { cases := []struct { input string