MCPcopy Create free account
hub / github.com/andybalholm/cascadia / parseName

Method parseName

parser.go:126–157  ·  view source on GitHub ↗

parseName parses a name (which is like an identifier, but doesn't have extra restrictions on the first character).

()

Source from the content-addressed store, hash-verified

124// parseName parses a name (which is like an identifier, but doesn't have
125// extra restrictions on the first character).
126func (p *parser) parseName() (result string, err error) {
127 i := p.i
128loop:
129 for i < len(p.s) {
130 c := p.s[i]
131 switch {
132 case nameChar(c):
133 start := i
134 for i < len(p.s) && nameChar(p.s[i]) {
135 i++
136 }
137 result += p.s[start:i]
138 case c == '\\':
139 p.i = i
140 val, err := p.parseEscape()
141 if err != nil {
142 return "", err
143 }
144 i = p.i
145 result += val
146 default:
147 break loop
148 }
149 }
150
151 if result == "" {
152 return "", errors.New("expected name, found EOF instead")
153 }
154
155 p.i = i
156 return result, nil
157}
158
159// parseString parses a single- or double-quoted string.
160func (p *parser) parseString() (result string, err error) {

Callers 3

parseIdentifierMethod · 0.95
parseIDSelectorMethod · 0.95
parseNthMethod · 0.95

Calls 2

parseEscapeMethod · 0.95
nameCharFunction · 0.85

Tested by

no test coverage detected