4 module Puppet::Parser::Functions
5 newfunction(:regexpescape, :type => :rvalue, :doc => <<-DOC
7 Regexp escape a string or array of strings.
8 Requires either a single string or an array as an input.
10 A string of characters with metacharacters converted to their escaped form.
12 ) do |arguments| # rubocop:disable Layout/ClosingParenthesisIndentation
13 raise(Puppet::ParseError, "regexpescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
17 unless value.is_a?(Array) || value.is_a?(String)
18 raise(Puppet::ParseError, 'regexpescape(): Requires either array or string to work with')
21 result = if value.is_a?(Array)
22 # Numbers in Puppet are often string-encoded which is troublesome ...
23 value.map { |i| i.is_a?(String) ? Regexp.escape(i) : i }
32 # vim: set ts=2 sw=2 et :