@@ -39,9 +39,29 @@ import (
39
39
// to use spaces in a single element of the split using quote characters.
40
40
//
41
41
// For example the call:
42
- // SplitQuotedString(`This 'is an' "Hello World!" example`, `'"`, false)
42
+ //
43
+ // SplitQuotedString(`This 'is an' "Hello World!" example`, `'"`, false)
44
+ //
43
45
// returns the following array:
44
- // []string{"This", "is an", "Hello World!", "example"}
46
+ //
47
+ // []string{"This", "is an", "Hello World!", "example"}
48
+ //
49
+ // The quoteChars parameter is a string containing all the characters that
50
+ // are considered as quote characters. If a quote character is found, the
51
+ // function will consider the text between the quote character and the next
52
+ // quote character as a single element of the split.
53
+ //
54
+ // The acceptEmptyArguments parameter is a boolean that indicates if the
55
+ // function should consider empty arguments as valid elements of the split.
56
+ // If set to false, the function will ignore empty arguments.
57
+ //
58
+ // If the function finds an opening quote character and does not find the
59
+ // closing quote character, it will return an error. In any case, the function
60
+ // will return the split array up to the point where the error occurred.
61
+ //
62
+ // The function does not support escaping of quote characters.
63
+ //
64
+ // The function is UTF-8 safe.
45
65
func SplitQuotedString (src string , quoteChars string , acceptEmptyArguments bool ) ([]string , error ) {
46
66
// Make a map of valid quote runes
47
67
isQuote := map [rune ]bool {}
@@ -83,7 +103,7 @@ func SplitQuotedString(src string, quoteChars string, acceptEmptyArguments bool)
83
103
}
84
104
85
105
if escapingChar != 0 {
86
- return nil , fmt .Errorf ("invalid quoting, no closing `%c` char found" , escapingChar )
106
+ return result , fmt .Errorf ("invalid quoting, no closing `%c` char found" , escapingChar )
87
107
}
88
108
89
109
return result , nil
0 commit comments