consumeExtensionOrAnyName consumes an extension name or an Any type URL and the following ']'. It returns the name or URL consumed.
()
| 489 | // consumeExtensionOrAnyName consumes an extension name or an Any type URL and |
| 490 | // the following ']'. It returns the name or URL consumed. |
| 491 | func (p *textParser) consumeExtensionOrAnyName() (string, error) { |
| 492 | tok := p.next() |
| 493 | if tok.err != nil { |
| 494 | return "", tok.err |
| 495 | } |
| 496 | |
| 497 | // If extension name or type url is quoted, it's a single token. |
| 498 | if len(tok.value) > 2 && isQuote(tok.value[0]) && tok.value[len(tok.value)-1] == tok.value[0] { |
| 499 | name, err := unquoteC(tok.value[1:len(tok.value)-1], rune(tok.value[0])) |
| 500 | if err != nil { |
| 501 | return "", err |
| 502 | } |
| 503 | return name, p.consumeToken("]") |
| 504 | } |
| 505 | |
| 506 | // Consume everything up to "]" |
| 507 | var parts []string |
| 508 | for tok.value != "]" { |
| 509 | parts = append(parts, tok.value) |
| 510 | tok = p.next() |
| 511 | if tok.err != nil { |
| 512 | return "", p.errorf("unrecognized type_url or extension name: %s", tok.err) |
| 513 | } |
| 514 | if p.done && tok.value != "]" { |
| 515 | return "", p.errorf("unclosed type_url or extension name") |
| 516 | } |
| 517 | } |
| 518 | return strings.Join(parts, ""), nil |
| 519 | } |
| 520 | |
| 521 | // consumeOptionalSeparator consumes an optional semicolon or comma. |
| 522 | // It is used in unmarshalMessage to provide backward compatibility. |
no test coverage detected