[PATCH 3/4] email-sh-functions: make 'merge_addresses' more flexible

Keller, Jacob E jacob.e.keller at intel.com
Tue Feb 11 09:15:40 PST 2014


If we're going to go this route, we should make this use any number of
arguments. I think this can be done, so I will respin this one up to
support variable number of arguments.

Regards,
Jake

On Mon, 2014-02-10 at 11:18 +0200, Artem Bityutskiy wrote:
> From: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
> 
> Jacob made 'merge_addresses()' to be able to merge multi-line input. And this
> basically makes the second argument of the function optional. Indeed, now one
> can call 'merge_addresses()' with a single argument like:
> 
> email1,email2
> email3,email4
> 
> and the function would merge this. And this is actally how Jacob is going to
> use this in his next patch.
> 
> So let's just do this - make the second argument optional.
> 
> Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
> ---
>  email/aiaiai-email-sh-functions | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions
> index b36a4a7..aceeade 100644
> --- a/email/aiaiai-email-sh-functions
> +++ b/email/aiaiai-email-sh-functions
> @@ -103,19 +103,22 @@ fetch_project_name()
>  	printf "%s" "$list" | LC_ALL=C sed -n -e "s/.*$l+\([^@]\+\)@$d.*/\1/p" | head -n1
>  }
>  
> -# Merge e-mail addresses into a comma-separated list
> +# Merge e-mail addresses into a comma-separated list. This function may have
> +# one or two input arguments. Each input argument is expected to contain
> +# multiple lines of comma-separated e-mail addresses. This function will merge
> +# them all into one single comma-separated line and print it.
>  # Usage: merge_addresses "addr1" "addr2"
>  merge_addresses()
>  {
>  	local addr1="$1"; shift
> -	local addr2="$1"; shift
> +	local addr2="${1:-}"
>  	local list
>  
>  	# We assume that the input arguments may have multiple lines
>  	list="$(printf "%s" "${addr1}${__br}${addr2}" | LC_ALL=C tr "\n" ",")"
>  
> -	printf "%s" "$list" | LC_ALL=C sed -e "s/,,/,/g" -e "s/^,//" \
> -		                           -e "s/,$//" -e "s/[[:blank:]]\+/ /g"
> +	printf "%s" "$list" | LC_ALL=C sed -e "s/,\+/,/g" -e "s/^,\+//" \
> +		                           -e "s/,\+$//" -e "s/[[:blank:]]\+/ /g"
>  }
>  
>  # A helper function for 'ini_config_get()' (from libshell) which fails when




More information about the aiaiai mailing list