4 module Puppet::Parser::Functions
5 newfunction(:regexpescape, :type => :rvalue, :doc => <<-DOC
6 Regexp escape a string or array of strings.
7 Requires either a single string or an array as an input.
9 ) do |arguments| # rubocop:disable Layout/ClosingParenthesisIndentation
10 raise(Puppet::ParseError, "regexpescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
14 unless value.is_a?(Array) || value.is_a?(String)
15 raise(Puppet::ParseError, 'regexpescape(): Requires either array or string to work with')
18 result = if value.is_a?(Array)
19 # Numbers in Puppet are often string-encoded which is troublesome ...
20 value.map { |i| i.is_a?(String) ? Regexp.escape(i) : i }
29 # vim: set ts=2 sw=2 et :