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

Method parseNumber

go/signedexchange/structuredheader/parser.go:221–239  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

219
220// https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.8
221func (p *parser) parseNumber() (int64, error) {
222 if p.isEmpty() {
223 return 0, errors.New("structuredheader: number expected, got EOS")
224 }
225 if p.input[0] != '-' && !isDigit(p.input[0]) {
226 return 0, fmt.Errorf("structuredheader: number expected, got '%c'", p.input[0])
227 }
228 // TODO: Support Floats.
229 i := 1
230 for i < len(p.input) && isDigit(p.input[i]) {
231 i++
232 }
233 s := p.getString(i)
234 n, err := strconv.ParseInt(s, 10, 64)
235 if err != nil {
236 return 0, fmt.Errorf("structuredheader: couldn't parse %q as number: %v", s, err)
237 }
238 return n, nil
239}
240
241// https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.9
242func (p *parser) parseString() (string, error) {

Callers 2

TestParseNumberFunction · 0.95
parseItemMethod · 0.95

Calls 3

isEmptyMethod · 0.95
getStringMethod · 0.95
isDigitFunction · 0.85

Tested by 1

TestParseNumberFunction · 0.76