4 module Puppet::Parser::Functions
5 newfunction(:chop, :type => :rvalue, :doc => <<-DOC
6 Returns a new string with the last character removed. If the string ends
7 with `\r\n`, both characters are removed. Applying chop to an empty
8 string returns an empty string. If you wish to merely remove record
9 separators then you should use the `chomp` function.
10 Requires a string or array of strings as input.
12 Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
13 will be used instead of this function.
17 raise(Puppet::ParseError, "chop(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
21 unless value.is_a?(Array) || value.is_a?(String)
22 raise(Puppet::ParseError, 'chop(): Requires either an array or string to work with')
25 result = if value.is_a?(Array)
26 # Numbers in Puppet are often string-encoded which is troublesome ...
27 value.map { |i| i.is_a?(String) ? i.chop : i }
36 # vim: set ts=2 sw=2 et :