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

Function normalizespaceFunc

func.go:412–446  ·  view source on GitHub ↗

normalizespaceFunc is XPath functions normalize-space(string?)

(arg1 query)

Source from the content-addressed store, hash-verified

410
411// normalizespaceFunc is XPath functions normalize-space(string?)
412func normalizespaceFunc(arg1 query) func(query, iterator) interface{} {
413 return func(_ query, t iterator) interface{} {
414 var m string
415 switch typ := functionArgs(arg1).Evaluate(t).(type) {
416 case string:
417 m = typ
418 case query:
419 node := typ.Select(t)
420 if node == nil {
421 return ""
422 }
423 m = node.Value()
424 }
425 var b = builderPool.Get().(stringBuilder)
426 b.Grow(len(m))
427
428 runeStr := []rune(strings.TrimSpace(m))
429 l := len(runeStr)
430 for i := range runeStr {
431 r := runeStr[i]
432 isSpace := unicode.IsSpace(r)
433 if !(isSpace && (i+1 < l && unicode.IsSpace(runeStr[i+1]))) {
434 if isSpace {
435 r = ' '
436 }
437 b.WriteRune(r)
438 }
439 }
440 result := b.String()
441 b.Reset()
442 builderPool.Put(b)
443
444 return result
445 }
446}
447
448// substringFunc is XPath functions substring function returns a part of a given string.
449func substringFunc(arg1, arg2, arg3 query) func(query, iterator) interface{} {

Callers 2

processFunctionMethod · 0.85

Calls 8

functionArgsFunction · 0.85
GrowMethod · 0.80
WriteRuneMethod · 0.80
ResetMethod · 0.80
EvaluateMethod · 0.65
SelectMethod · 0.65
ValueMethod · 0.65
StringMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…