MCPcopy Create free account
hub / github.com/antchfx/xpath / processFunction

Method processFunction

build.go:301–601  ·  view source on GitHub ↗

processFunctionNode processes query for the XPath function node.

(root *functionNode, props *builderProp)

Source from the content-addressed store, hash-verified

299
300// processFunctionNode processes query for the XPath function node.
301func (b *builder) processFunction(root *functionNode, props *builderProp) (query, error) {
302 // Reset builder props
303 *props = builderProps.None
304
305 var qyOutput query
306 switch root.FuncName {
307 case "lower-case":
308 arg, err := b.processNode(root.Args[0], flagsEnum.None, props)
309 if err != nil {
310 return nil, err
311 }
312 qyOutput = &functionQuery{Func: lowerCaseFunc(arg)}
313 case "starts-with":
314 arg1, err := b.processNode(root.Args[0], flagsEnum.None, props)
315 if err != nil {
316 return nil, err
317 }
318 arg2, err := b.processNode(root.Args[1], flagsEnum.None, props)
319 if err != nil {
320 return nil, err
321 }
322 qyOutput = &functionQuery{Func: startwithFunc(arg1, arg2)}
323 case "ends-with":
324 arg1, err := b.processNode(root.Args[0], flagsEnum.None, props)
325 if err != nil {
326 return nil, err
327 }
328 arg2, err := b.processNode(root.Args[1], flagsEnum.None, props)
329 if err != nil {
330 return nil, err
331 }
332 qyOutput = &functionQuery{Func: endwithFunc(arg1, arg2)}
333 case "contains":
334 arg1, err := b.processNode(root.Args[0], flagsEnum.None, props)
335 if err != nil {
336 return nil, err
337 }
338 arg2, err := b.processNode(root.Args[1], flagsEnum.None, props)
339 if err != nil {
340 return nil, err
341 }
342 qyOutput = &functionQuery{Func: containsFunc(arg1, arg2)}
343 case "matches":
344 //matches(string , pattern)
345 if len(root.Args) != 2 {
346 return nil, errors.New("xpath: matches function must have two parameters")
347 }
348 var (
349 arg1, arg2 query
350 err error
351 )
352 if arg1, err = b.processNode(root.Args[0], flagsEnum.None, props); err != nil {
353 return nil, err
354 }
355 if arg2, err = b.processNode(root.Args[1], flagsEnum.None, props); err != nil {
356 return nil, err
357 }
358 // Issue #92, testing the regular expression before.

Callers 1

processNodeMethod · 0.95

Calls 15

processNodeMethod · 0.95
lowerCaseFuncFunction · 0.85
startwithFuncFunction · 0.85
endwithFuncFunction · 0.85
containsFuncFunction · 0.85
getRegexpFunction · 0.85
matchesFuncFunction · 0.85
substringFuncFunction · 0.85
substringIndFuncFunction · 0.85
stringLengthFuncFunction · 0.85
newAxisNodeFunction · 0.85
normalizespaceFuncFunction · 0.85

Tested by

no test coverage detected