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

Method readTokenAsLabelValue

expfmt/text_parse.go:868–901  ·  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

866// with reading a new byte from p.buf. The first byte not part of a label value
867// is still copied into p.currentByte, but not into p.currentToken.
868func (p *TextParser) readTokenAsLabelValue() {
869 p.currentToken.Reset()
870 escaped := false
871 for {
872 if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil {
873 return
874 }
875 if escaped {
876 switch p.currentByte {
877 case '"', '\\':
878 p.currentToken.WriteByte(p.currentByte)
879 case 'n':
880 p.currentToken.WriteByte('\n')
881 default:
882 p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte))
883 p.currentLabelPairs = nil
884 return
885 }
886 escaped = false
887 continue
888 }
889 switch p.currentByte {
890 case '"':
891 return
892 case '\n':
893 p.parseError(fmt.Sprintf("label value %q contains unescaped new-line", p.currentToken.String()))
894 return
895 case '\\':
896 escaped = true
897 default:
898 p.currentToken.WriteByte(p.currentByte)
899 }
900 }
901}
902
903func (p *TextParser) setOrCreateCurrentMF() {
904 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