parseString parses as defined in https://httpwg.org/specs/rfc9651.html#parse-string.
(s *scanner)
| 43 | // parseString parses as defined in |
| 44 | // https://httpwg.org/specs/rfc9651.html#parse-string. |
| 45 | func parseString(s *scanner) (string, error) { |
| 46 | if s.eof() || s.data[s.off] != '"' { |
| 47 | return "", &UnmarshalError{s.off, ErrInvalidStringFormat} |
| 48 | } |
| 49 | s.off++ |
| 50 | |
| 51 | var b strings.Builder |
| 52 | |
| 53 | for !s.eof() { |
| 54 | c := s.data[s.off] |
| 55 | s.off++ |
| 56 | |
| 57 | switch c { |
| 58 | case '\\': |
| 59 | if s.eof() { |
| 60 | return "", &UnmarshalError{s.off, ErrInvalidStringFormat} |
| 61 | } |
| 62 | |
| 63 | n := s.data[s.off] |
| 64 | if n != '"' && n != '\\' { |
| 65 | return "", &UnmarshalError{s.off, ErrInvalidStringFormat} |
| 66 | } |
| 67 | s.off++ |
| 68 | |
| 69 | if err := b.WriteByte(n); err != nil { |
| 70 | return "", err |
| 71 | } |
| 72 | |
| 73 | continue |
| 74 | case '"': |
| 75 | return b.String(), nil |
| 76 | default: |
| 77 | if c <= '\u001F' || c >= unicode.MaxASCII { |
| 78 | return "", &UnmarshalError{s.off, ErrInvalidStringFormat} |
| 79 | } |
| 80 | |
| 81 | if err := b.WriteByte(c); err != nil { |
| 82 | return "", err |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return "", &UnmarshalError{s.off, ErrInvalidStringFormat} |
| 88 | } |
searching dependent graphs…