splitString splits a string along the specified separator, but it ignores anything between double quotes for splitting. We do simple inside/outside quote counting. Quotes are not stripped from output.
(s string, sep rune)
| 51 | // ignores anything between double quotes for splitting. We do simple |
| 52 | // inside/outside quote counting. Quotes are not stripped from output. |
| 53 | func splitString(s string, sep rune) []string { |
| 54 | const escapeChar rune = '"' |
| 55 | |
| 56 | var parts []string |
| 57 | var part string |
| 58 | inQuotes := false |
| 59 | |
| 60 | for _, c := range s { |
| 61 | if c == escapeChar { |
| 62 | if inQuotes { |
| 63 | inQuotes = false |
| 64 | } else { |
| 65 | inQuotes = true |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // If we've gotten the separator rune, consider the previous part |
| 70 | // complete, but only if we're outside of quoted sections |
| 71 | if c == sep && !inQuotes { |
| 72 | parts = append(parts, part) |
| 73 | part = "" |
| 74 | continue |
| 75 | } |
| 76 | part += string(c) |
| 77 | } |
| 78 | return append(parts, part) |
| 79 | } |
no outgoing calls