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

Method parseName

parser.go:101–132  ·  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

99// parseName parses a name (which is like an identifier, but doesn't have
100// extra restrictions on the first character).
101func (p *parser) parseName() (result string, err error) {
102 i := p.i
103loop:
104 for i < len(p.s) {
105 c := p.s[i]
106 switch {
107 case nameChar(c):
108 start := i
109 for i < len(p.s) && nameChar(p.s[i]) {
110 i++
111 }
112 result += p.s[start:i]
113 case c == '\\':
114 p.i = i
115 val, err := p.parseEscape()
116 if err != nil {
117 return "", err
118 }
119 i = p.i
120 result += val
121 default:
122 break loop
123 }
124 }
125
126 if result == "" {
127 return "", errors.New("expected name, found EOF instead")
128 }
129
130 p.i = i
131 return result, nil
132}
133
134// parseString parses a single- or double-quoted string.
135func (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