processFunctionNode processes query for the XPath function node.
(root *functionNode, props *builderProp)
| 299 | |
| 300 | // processFunctionNode processes query for the XPath function node. |
| 301 | func (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. |
no test coverage detected