MCPcopy Index your code
hub / github.com/dunglas/httpsfv / parseString

Function parseString

string.go:45–88  ·  view source on GitHub ↗

parseString parses as defined in https://httpwg.org/specs/rfc9651.html#parse-string.

(s *scanner)

Source from the content-addressed store, hash-verified

43// parseString parses as defined in
44// https://httpwg.org/specs/rfc9651.html#parse-string.
45func 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}

Callers 2

TestParseStringFunction · 0.85
parseBareItemFunction · 0.85

Calls 1

eofMethod · 0.80

Tested by 1

TestParseStringFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…