def QuickPath::filter elements, path
return elements if path.nil? or path == '' or elements.size == 0
case path
when /^\/\//u
return axe( elements, "descendant-or-self", $' )
when /^\/?\b(\w[-\w]*)\b::/u
axe_name = $1
rest = $'
return axe( elements, $1, $' )
when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u
rest = $'
results = []
elements.each do |element|
results |= filter( element.to_a, rest )
end
return results
when /^\/?(\w[-\w]*)\(/u
return function( elements, $1, $' )
when Namespace::NAMESPLIT
name = $2
ns = $1
rest = $'
elements.delete_if do |element|
!(element.kind_of? Element and
(element.expanded_name == name or
(element.name == name and
element.namespace == Functions.namespace_context[ns])))
end
return filter( elements, rest )
when /^\/\[/u
matches = []
elements.each do |element|
matches |= predicate( element.to_a, path[1..-1] ) if element.kind_of? Element
end
return matches
when /^\[/u
return predicate( elements, path )
when /^\/?\.\.\./u
return axe( elements, "ancestor", $' )
when /^\/?\.\./u
return filter( elements.collect{|e|e.parent}, $' )
when /^\/?\./u
return filter( elements, $' )
when /^\*/u
results = []
elements.each do |element|
results |= filter( [element], $' ) if element.kind_of? Element
end
return results
end
return []
end