fields returns a list of the groups of text separated by blanks, keeping all text surrounded by / as a group.
(s string)
| 65 | // fields returns a list of the groups of text separated by blanks, |
| 66 | // keeping all text surrounded by / as a group. |
| 67 | func fields(s string) ([]string, error) { |
| 68 | var args []string |
| 69 | |
| 70 | for s = strings.TrimSpace(s); len(s) > 0; s = strings.TrimSpace(s) { |
| 71 | if s[0] == '/' { |
| 72 | sep := nextSlash(s[1:]) |
| 73 | if sep < 0 { |
| 74 | return nil, errors.New("unbalanced /") |
| 75 | } |
| 76 | args, s = append(args, s[:sep+2]), s[sep+2:] |
| 77 | } else { |
| 78 | sep := strings.IndexByte(s[1:], ' ') |
| 79 | if sep < 0 { |
| 80 | return append(args, s), nil |
| 81 | } |
| 82 | args, s = append(args, s[:sep+1]), s[sep+1:] |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return args, nil |
| 87 | } |
| 88 | |
| 89 | // nextSlash will find the index of the next unescaped slash in a string. |
| 90 | func nextSlash(s string) int { |
no test coverage detected
searching dependent graphs…