MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / parseKeyword

Method parseKeyword

internal/re/regexp.go:229–298  ·  view source on GitHub ↗
(subExp string)

Source from the content-addressed store, hash-verified

227}
228
229func (this *Regexp) parseKeyword(subExp string) (result []rune) {
230 if len(subExp) == 0 {
231 return nil
232 }
233
234 // 去除开始和结尾的()
235 if subExp[0] == '(' && subExp[len(subExp)-1] == ')' {
236 subExp = subExp[1 : len(subExp)-1]
237 if len(subExp) == 0 {
238 return
239 }
240 }
241
242 var runes = []rune(subExp)
243
244 for index, r := range runes {
245 if r == '[' || r == '{' || r == '.' || r == '+' || r == '$' {
246 if index == 0 {
247 return
248 }
249 if runes[index-1] != '\\' {
250 if r == '{' && (braceZeroReg.MatchString(subExp[index:])) || braceZeroReg2.MatchString(subExp[index:]) { // r {0, ...}
251 if len(result) == 0 {
252 return nil
253 }
254 return result[:len(result)-1]
255 }
256
257 return
258 }
259 }
260 if r == '?' || r == '*' {
261 if index == 0 {
262 return
263 }
264 if runes[index-1] != '\\' {
265 if len(result) > 0 {
266 return result[:len(result)-1]
267 }
268 return
269 }
270 }
271
272 if (r == 'n' || r == 't' || r == 'a' || r == 'f' || r == 'r' || r == 'v' || r == 'x') && index > 0 && runes[index-1] == '\\' {
273 switch r {
274 case 'n':
275 r = '\n'
276 case 't':
277 r = '\t'
278 case 'f':
279 r = '\f'
280 case 'r':
281 r = '\r'
282 case 'v':
283 r = '\v'
284 case 'a':
285 r = '\a'
286 case 'x':

Callers 1

ParseKeywordsMethod · 0.95

Calls 1

MatchStringMethod · 0.80

Tested by

no test coverage detected