Source file
src/cmd/dist/quoted.go
1
2
3
4
5 package main
6
7 import "fmt"
8
9
10
11
12
13
14
15 func quotedSplit(s string) ([]string, error) {
16
17
18 var f []string
19 for len(s) > 0 {
20 for len(s) > 0 && isSpaceByte(s[0]) {
21 s = s[1:]
22 }
23 if len(s) == 0 {
24 break
25 }
26
27 if s[0] == '"' || s[0] == '\'' {
28 quote := s[0]
29 s = s[1:]
30 i := 0
31 for i < len(s) && s[i] != quote {
32 i++
33 }
34 if i >= len(s) {
35 return nil, fmt.Errorf("unterminated %c string", quote)
36 }
37 f = append(f, s[:i])
38 s = s[i+1:]
39 continue
40 }
41 i := 0
42 for i < len(s) && !isSpaceByte(s[i]) {
43 i++
44 }
45 f = append(f, s[:i])
46 s = s[i:]
47 }
48 return f, nil
49 }
50
51 func isSpaceByte(c byte) bool {
52 return c == ' ' || c == '\t' || c == '\n' || c == '\r'
53 }
54
View as plain text