# File rexml/functions.rb, line 148 def Functions::substring( string, start, length=0 ) puts "SUBSTRING WITH #{string}, #{start}, #{length}" ruby_string = string(string) ruby_length = if length.nil? string.length else number(length) end ruby_start = number(start) # Handle the special cases puts "\t#{ruby_start}\t<->\t#{ruby_length}" return '' if ( ruby_length == 'NaN' or ruby_start == 'NaN' or ruby_start.to_s =~ /infinity/ ) ruby_length = ruby_string.length if ruby_length == 'infinity' # Now, get the bounds. The XPath bounds are 1..length; the ruby bounds # are 0..length. Therefore, we have to offset the bounds by one. ruby_start = ruby_start.round - 1 ruby_length = ruby_length.round if ruby_start < 0 ruby_length += ruby_start ruby_start = 0 end return '' if ruby_length <= 0 ruby_string[ruby_start,ruby_length] end