readTokenAsLabelName copies a label name from p.buf into p.currentToken. The first byte considered is the byte already read (now in p.currentByte). The first byte not part of a label name is still copied into p.currentByte, but not into p.currentToken.
()
| 815 | // The first byte not part of a label name is still copied into p.currentByte, |
| 816 | // but not into p.currentToken. |
| 817 | func (p *TextParser) readTokenAsLabelName() { |
| 818 | p.currentToken.Reset() |
| 819 | // A UTF-8 label name must be quoted and may have escaped characters. |
| 820 | quoted := false |
| 821 | escaped := false |
| 822 | if !isValidLabelNameStart(p.currentByte) { |
| 823 | return |
| 824 | } |
| 825 | for p.err == nil { |
| 826 | if escaped { |
| 827 | switch p.currentByte { |
| 828 | case '\\': |
| 829 | p.currentToken.WriteByte(p.currentByte) |
| 830 | case 'n': |
| 831 | p.currentToken.WriteByte('\n') |
| 832 | case '"': |
| 833 | p.currentToken.WriteByte('"') |
| 834 | default: |
| 835 | p.parseError(fmt.Sprintf("invalid escape sequence '\\%c'", p.currentByte)) |
| 836 | return |
| 837 | } |
| 838 | escaped = false |
| 839 | } else { |
| 840 | switch p.currentByte { |
| 841 | case '"': |
| 842 | quoted = !quoted |
| 843 | if !quoted { |
| 844 | p.currentByte, p.err = p.buf.ReadByte() |
| 845 | return |
| 846 | } |
| 847 | case '\n': |
| 848 | p.parseError(fmt.Sprintf("label name %q contains unescaped new-line", p.currentToken.String())) |
| 849 | return |
| 850 | case '\\': |
| 851 | escaped = true |
| 852 | default: |
| 853 | p.currentToken.WriteByte(p.currentByte) |
| 854 | } |
| 855 | } |
| 856 | p.currentByte, p.err = p.buf.ReadByte() |
| 857 | if !isValidLabelNameContinuation(p.currentByte, quoted) || (!quoted && p.currentByte == '=') { |
| 858 | return |
| 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | // readTokenAsLabelValue copies a label value from p.buf into p.currentToken. |
| 864 | // In contrast to the other 'readTokenAs...' functions, which start with the |
no test coverage detected