MCPcopy Create free account
hub / github.com/prometheus/common / readTokenAsLabelValue

Method readTokenAsLabelValue

expfmt/text_parse.go:648–680  ·  view source on GitHub ↗

readTokenAsLabelValue copies a label value from p.buf into p.currentToken. In contrast to the other 'readTokenAs...' functions, which start with the last read byte in p.currentByte, this method ignores p.currentByte and starts with reading a new byte from p.buf. The first byte not part of a label va

()

Source from the content-addressed store, hash-verified

646// with reading a new byte from p.buf. The first byte not part of a label value
647// is still copied into p.currentByte, but not into p.currentToken.
648func (p *TextParser) readTokenAsLabelValue() {
649 p.currentToken.Reset()
650 escaped := false
651 for {
652 if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil {
653 return
654 }
655 if escaped {
656 switch p.currentByte {
657 case '"', '\\':
658 p.currentToken.WriteByte(p.currentByte)
659 case 'n':
660 p.currentToken.WriteByte('\n')
661 default:
662 p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte))
663 return
664 }
665 escaped = false
666 continue
667 }
668 switch p.currentByte {
669 case '"':
670 return
671 case '\n':
672 p.parseError(fmt.Sprintf("label value %q contains unescaped new-line", p.currentToken.String()))
673 return
674 case '\\':
675 escaped = true
676 default:
677 p.currentToken.WriteByte(p.currentByte)
678 }
679 }
680}
681
682func (p *TextParser) setOrCreateCurrentMF() {
683 p.currentIsSummaryCount = false

Callers 1

startLabelValueMethod · 0.95

Calls 3

parseErrorMethod · 0.95
WriteByteMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected