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

Function substringIndFunc

func.go:505–542  ·  view source on GitHub ↗

substringIndFunc is XPath functions substring-before/substring-after function returns a part of a given string.

(arg1, arg2 query, after bool)

Source from the content-addressed store, hash-verified

503
504// substringIndFunc is XPath functions substring-before/substring-after function returns a part of a given string.
505func substringIndFunc(arg1, arg2 query, after bool) func(query, iterator) interface{} {
506 return func(_ query, t iterator) interface{} {
507 var str string
508 switch v := functionArgs(arg1).Evaluate(t).(type) {
509 case string:
510 str = v
511 case query:
512 node := v.Select(t)
513 if node == nil {
514 return ""
515 }
516 str = node.Value()
517 }
518 var word string
519 switch v := functionArgs(arg2).Evaluate(t).(type) {
520 case string:
521 word = v
522 case query:
523 node := v.Select(t)
524 if node == nil {
525 return ""
526 }
527 word = node.Value()
528 }
529 if word == "" {
530 return ""
531 }
532
533 i := strings.Index(str, word)
534 if i < 0 {
535 return ""
536 }
537 if after {
538 return str[i+len(word):]
539 }
540 return str[:i]
541 }
542}
543
544// stringLengthFunc is XPATH string-length( [string] ) function that returns a number
545// equal to the number of characters in a given string.

Callers 1

processFunctionMethod · 0.85

Calls 4

functionArgsFunction · 0.85
EvaluateMethod · 0.65
SelectMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…