2011-04-30 15:36:25 +02:00
|
|
|
#
|
|
|
|
# squeeze.rb
|
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
|
|
|
newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS
|
2011-07-29 23:18:56 +02:00
|
|
|
Returns a new string where runs of the same character that occur in this set are replaced by a single character.
|
2011-04-30 15:36:25 +02:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
2011-06-29 22:21:55 +02:00
|
|
|
|
2011-07-24 01:39:17 +02:00
|
|
|
if ((arguments.size != 2) and (arguments.size != 1)) then
|
2011-06-29 22:21:55 +02:00
|
|
|
raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+
|
2011-07-24 01:39:17 +02:00
|
|
|
"given #{arguments.size} for 2 or 1")
|
|
|
|
end
|
|
|
|
|
|
|
|
item = arguments[0]
|
2012-11-09 18:08:24 +01:00
|
|
|
squeezeval = arguments[1]
|
2011-07-24 01:39:17 +02:00
|
|
|
|
2012-11-09 18:08:24 +01:00
|
|
|
if item.is_a?(Array) then
|
2011-07-24 01:39:17 +02:00
|
|
|
if squeezeval then
|
|
|
|
item.collect { |i| i.squeeze(squeezeval) }
|
|
|
|
else
|
|
|
|
item.collect { |i| i.squeeze }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if squeezeval then
|
|
|
|
item.squeeze(squeezeval)
|
|
|
|
else
|
|
|
|
item.squeeze
|
|
|
|
end
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2011-04-30 15:36:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|