From 728bd45e488fb5aced20fe863d2794959d5566f1 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 18 Aug 2015 14:48:42 +0200 Subject: [PATCH] XPath compiler support for string-length() --- lib/oga/xpath/compiler.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index f1ef376..6c99a6f 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -967,6 +967,25 @@ module Oga end end + # @param [Oga::Ruby::Node] input + # @param [AST::Node] arg + # @return [Oga::Ruby::Node] + def on_call_string_length(input, arg = nil) + convert_var = unique_literal(:convert) + conversion = literal(Conversion) + + argument_or_first_node(input, arg) do |arg_var| + convert_var.assign(conversion.to_string(arg_var).length) + .followed_by do + if block_given? + convert_var.zero?.not.if_true { yield } + else + convert_var.to_f + end + end + end + end + ## # Delegates type tests to specific handlers. #