4 module Puppet::Parser::Functions
5 newfunction(:chop, :type => :rvalue, :doc => <<-DOC
7 **Deprecated** Returns a new string with the last character removed.
9 If the string ends with `\r\n`, both characters are removed. Applying
10 chop to an empty string returns an empty string. If you wish to merely
11 remove record separators then you should use the `chomp` function.
12 Requires a string or array of strings as input.
14 > *Note:* **Deprecated** from Puppet 6.0.0, this function has been replaced with a
15 built-in [`chop`](https://puppet.com/docs/puppet/latest/function.html#chop) function.
17 @return [String] The given String, sans the last character.
21 raise(Puppet::ParseError, "chop(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
25 unless value.is_a?(Array) || value.is_a?(String)
26 raise(Puppet::ParseError, 'chop(): Requires either an array or string to work with')
29 result = if value.is_a?(Array)
30 # Numbers in Puppet are often string-encoded which is troublesome ...
31 value.map { |i| i.is_a?(String) ? i.chop : i }
40 # vim: set ts=2 sw=2 et :