MCPcopy Create free account
hub / github.com/WICG/webpackage / parseString

Method parseString

go/signedexchange/structuredheader/parser.go:242–271  ·  view source on GitHub ↗

https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.9

()

Source from the content-addressed store, hash-verified

240
241// https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.9
242func (p *parser) parseString() (string, error) {
243 if p.isEmpty() {
244 return "", errors.New("structuredheader: string expected, got EOS")
245 }
246 if !p.consumeChar('"') {
247 return "", fmt.Errorf("structuredheader: '\"' expected, got '%c'", p.input[0])
248 }
249
250 var b strings.Builder
251 for !p.isEmpty() {
252 c := p.getChar()
253 if c == '\\' {
254 if p.isEmpty() {
255 break
256 }
257 c = p.getChar()
258 if c != '"' && c != '\\' {
259 return "", fmt.Errorf("structuredheader: invalid escape \\%c", c)
260 }
261 b.WriteByte(c)
262 } else if c == '"' {
263 return b.String(), nil
264 } else if c < ' ' || c > '~' {
265 return "", fmt.Errorf("structuredheader: invalid character \\x%02x", c)
266 } else {
267 b.WriteByte(c)
268 }
269 }
270 return "", errors.New("structuredheader: missing closing '\"'")
271}
272
273// https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.10
274func (p *parser) parseToken() (Token, error) {

Callers 2

TestParseStringFunction · 0.95
parseItemMethod · 0.95

Calls 4

isEmptyMethod · 0.95
consumeCharMethod · 0.95
getCharMethod · 0.95
StringMethod · 0.45

Tested by 1

TestParseStringFunction · 0.76