nextTokenOrQuoted returns the leading token or quoted string per RFC 2616 and the string following the token or quoted string.
(s string)
| 139 | // nextTokenOrQuoted returns the leading token or quoted string per RFC 2616 |
| 140 | // and the string following the token or quoted string. |
| 141 | func nextTokenOrQuoted(s string) (value string, rest string) { |
| 142 | if !strings.HasPrefix(s, "\"") { |
| 143 | return nextToken(s) |
| 144 | } |
| 145 | s = s[1:] |
| 146 | for i := 0; i < len(s); i++ { |
| 147 | switch s[i] { |
| 148 | case '"': |
| 149 | return s[:i], s[i+1:] |
| 150 | case '\\': |
| 151 | p := make([]byte, len(s)-1) |
| 152 | j := copy(p, s[:i]) |
| 153 | escape := true |
| 154 | for i = i + 1; i < len(s); i++ { |
| 155 | b := s[i] |
| 156 | switch { |
| 157 | case escape: |
| 158 | escape = false |
| 159 | p[j] = b |
| 160 | j++ |
| 161 | case b == '\\': |
| 162 | escape = true |
| 163 | case b == '"': |
| 164 | return string(p[:j]), s[i+1:] |
| 165 | default: |
| 166 | p[j] = b |
| 167 | j++ |
| 168 | } |
| 169 | } |
| 170 | return "", "" |
| 171 | } |
| 172 | } |
| 173 | return "", "" |
| 174 | } |
| 175 | |
| 176 | // equalASCIIFold returns true if s is equal to t with ASCII case folding as |
| 177 | // defined in RFC 4790. |
no test coverage detected