3 # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085.
5 module Puppet::Parser::Functions
6 newfunction(:swapcase, :type => :rvalue, :doc => <<-DOC
8 This function will swap the existing case of a string.
11 string with uppercase alphabetic characters converted to lowercase and lowercase characters converted to uppercase
16 Would result in: "AbCd"
20 raise(Puppet::ParseError, "swapcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
24 unless value.is_a?(Array) || value.is_a?(String)
25 raise(Puppet::ParseError, 'swapcase(): Requires either array or string to work with')
28 result = if value.is_a?(Array)
29 # Numbers in Puppet are often string-encoded which is troublesome ...
30 value.map { |i| i.is_a?(String) ? i.swapcase : i }
39 # vim: set ts=2 sw=2 et :