readTokenUntilNewline copies bytes from p.buf into p.currentToken. The first byte considered is the byte already read (now in p.currentByte). The first newline byte encountered is still copied into p.currentByte, but not into p.currentToken. If recognizeEscapeSequence is true, two escape sequences
(recognizeEscapeSequence bool)
| 730 | // recognized: '\\' translates into '\', and '\n' into a line-feed character. |
| 731 | // All other escape sequences are invalid and cause an error. |
| 732 | func (p *TextParser) readTokenUntilNewline(recognizeEscapeSequence bool) { |
| 733 | p.currentToken.Reset() |
| 734 | escaped := false |
| 735 | for p.err == nil { |
| 736 | if recognizeEscapeSequence && escaped { |
| 737 | switch p.currentByte { |
| 738 | case '\\': |
| 739 | p.currentToken.WriteByte(p.currentByte) |
| 740 | case 'n': |
| 741 | p.currentToken.WriteByte('\n') |
| 742 | case '"': |
| 743 | p.currentToken.WriteByte('"') |
| 744 | default: |
| 745 | p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte)) |
| 746 | return |
| 747 | } |
| 748 | escaped = false |
| 749 | } else { |
| 750 | switch p.currentByte { |
| 751 | case '\n': |
| 752 | return |
| 753 | case '\\': |
| 754 | escaped = true |
| 755 | default: |
| 756 | p.currentToken.WriteByte(p.currentByte) |
| 757 | } |
| 758 | } |
| 759 | p.currentByte, p.err = p.buf.ReadByte() |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // readTokenAsMetricName copies a metric name from p.buf into p.currentToken. |
| 764 | // The first byte considered is the byte already read (now in p.currentByte). |
no test coverage detected