XPath compiler support for substring-after()

This commit is contained in:
Yorick Peterse 2015-08-18 14:53:39 +02:00
parent d6b3461a9a
commit eeab14af4d
1 changed files with 29 additions and 0 deletions

View File

@ -1005,6 +1005,35 @@ module Oga
end end
end end
# @param [Oga::Ruby::Node] input
# @param [AST::Node] haystack
# @param [AST::Node] needle
# @return [Oga::Ruby::Node]
def on_call_substring_after(input, haystack, needle)
haystack_var = unique_literal(:haystack)
needle_var = unique_literal(:needle)
conversion = literal(Conversion)
before = unique_literal(:before)
sep = unique_literal(:sep)
after = unique_literal(:after)
haystack_var.assign(try_match_first_node(haystack, input))
.followed_by do
needle_var.assign(try_match_first_node(needle, input))
end
.followed_by do
converted = conversion.to_string(haystack_var)
.partition(conversion.to_string(needle_var))
mass_assign([before, sep, after], converted).followed_by do
sep.empty?
.if_true { sep }
.else { block_given? ? yield : after }
end
end
end
## ##
# Delegates type tests to specific handlers. # Delegates type tests to specific handlers.
# #