From fe41b2cd7c8b466e35e81d9a98e43e6ff465280e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 12 Mar 2013 04:19:18 -0400 Subject: to_s functions added --- misc/freeswitch/scripts/common/array.lua | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/array.lua b/misc/freeswitch/scripts/common/array.lua index b93ef69..5683dce 100644 --- a/misc/freeswitch/scripts/common/array.lua +++ b/misc/freeswitch/scripts/common/array.lua @@ -45,10 +45,35 @@ function expand_variable(variable_path, variable_sets) end end - +-- replace variables in a string by array values function expand_variables(line, ...) local variable_sets = {...}; return (line:gsub('{([%a%d%._]+)}', function(captured) return expand_variable(captured, variable_sets); end)) end + + +-- concatenate array values +function to_s(array, separator, prefix, suffix) + require 'common.str'; + + local buffer = ''; + for key, value in pairs(array) do + buffer = common.str.append(buffer, value, separator, prefix, suffix); + end + + return buffer; +end + +-- concatenate array keys +function keys_to_s(array, separator, prefix, suffix) + require 'common.str'; + + local buffer = ''; + for key, value in pairs(array) do + buffer = common.str.append(buffer, key, separator, prefix, suffix); + end + + return buffer; +end -- cgit v1.2.3