2019-12-25 01:11:04 +00:00
|
|
|
package yqlib
|
|
|
|
|
2020-02-07 05:32:39 +00:00
|
|
|
func ReadNavigationStrategy(deeplyTraverseArrays bool) NavigationStrategy {
|
2019-12-28 07:19:37 +00:00
|
|
|
return &NavigationStrategyImpl{
|
|
|
|
visitedNodes: []*NodeContext{},
|
2020-01-11 08:30:27 +00:00
|
|
|
pathParser: NewPathParser(),
|
2019-12-28 07:19:37 +00:00
|
|
|
visit: func(nodeContext NodeContext) error {
|
2019-12-25 01:11:04 +00:00
|
|
|
return nil
|
|
|
|
},
|
2020-02-07 05:32:39 +00:00
|
|
|
shouldDeeplyTraverse: func(nodeContext NodeContext) bool {
|
|
|
|
var isInArray = false
|
|
|
|
if len(nodeContext.PathStack) > 0 {
|
|
|
|
var lastElement = nodeContext.PathStack[len(nodeContext.PathStack)-1]
|
|
|
|
switch lastElement.(type) {
|
|
|
|
case int:
|
|
|
|
isInArray = true
|
|
|
|
default:
|
|
|
|
isInArray = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deeplyTraverseArrays || !isInArray
|
|
|
|
},
|
2019-12-25 01:11:04 +00:00
|
|
|
}
|
|
|
|
}
|