Add m4_joinall.

* lib/m4sugar/m4sugar.m4 (m4_joinall, _m4_joinall): New macros.
* tests/m4sugar.at (m4@&t@_join): Test them.
* doc/autoconf.texi (Text processing Macros) <m4_join>: Document
m4_joinall.
* NEWS: Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
This commit is contained in:
Eric Blake 2008-07-18 08:30:07 -06:00
parent 6d04538831
commit 65ff0e8f88
5 changed files with 41 additions and 3 deletions

View File

@ -1,3 +1,12 @@
2008-07-18 Eric Blake <ebb9@byu.net>
Add m4_joinall.
* lib/m4sugar/m4sugar.m4 (m4_joinall, _m4_joinall): New macros.
* tests/m4sugar.at (m4@&t@_join): Test them.
* doc/autoconf.texi (Text processing Macros) <m4_join>: Document
m4_joinall.
* NEWS: Likewise.
2008-07-17 Stepan Kasal <skasal@redhat.com>
and Eric Blake <ebb9@byu.net>

3
NEWS
View File

@ -19,6 +19,9 @@ GNU Autoconf NEWS - User visible changes.
** Two new quadrigraphs have been introduced: @{:@ for (, and @:}@ for ),
allowing the output of unbalanced parantheses in more contexts.
** The following m4sugar macros are new:
m4_joinall
** AT_KEYWORDS once again performs expansion on its argument, such that
AT_KEYWORDS([m4_if([$1], [], [default])]) no longer complains about
the possibly unexpanded m4_if [regression introduced in 2.62].

View File

@ -11163,14 +11163,19 @@ still a quoted string.
@end defmac
@defmac m4_join (@ovar{separator}, @var{args}@dots{})
@defmacx m4_joinall (@ovar{separator}, @var{args}@dots{})
@msindex{join}
Concatenate each @var{arg}, separated by @var{separator}, with the
exception that no back-to-back separators are issued for empty
arguments. The result is a quoted string.
@msindex{joinall}
Concatenate each @var{arg}, separated by @var{separator}.
@code{joinall} uses every argument, while @code{join} omits empty
arguments so that there are no back-to-back separators in the output.
The result is a quoted string.
@example
m4_define([active], [ACTIVE])dnl
m4_join([|], [one], [], [active], [two])
@result{}one|active|two
m4_joinall([|], [one], [], [active], [two])
@result{}one||active|two
@end example
Note that if all you intend to do is join @var{args} with commas between

View File

@ -1846,6 +1846,13 @@ m4_define([_m4_join],
[m4_if([$#$2], [2], [],
[m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])])
# m4_joinall(SEP, ARG1, ARG2...)
# ------------------------------
# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP.
# No expansion is performed on SEP or ARGs.
m4_define([m4_joinall], [[$2]_$0([$1], m4_shift($@))])
m4_define([_m4_joinall],
[m4_if([$#], [2], [], [[$1$3]$0([$1], m4_shift2($@))])])
# m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX...)
# --------------------------------------------------------

View File

@ -284,6 +284,8 @@ AT_CLEANUP
AT_SETUP([m4@&t@_join])
AT_KEYWORDS([m4@&t@_joinall])
AT_CHECK_M4SUGAR_TEXT(
[[m4_define([active], [ACTIVE])
m4_join
@ -297,6 +299,12 @@ m4_join([], ,,,[two])
m4_join([], [two],,,)
m4_join([ active ], [one], , [two])
m4_join([], [one], [two])
m4_joinall([-], [one], [], [two])
m4_joinall([-], [], [], [three], [], [])
m4_joinall([], [one], [], [two])
m4_joinall
m4_joinall([-])
m4_joinall([-], [one])
]],
[[
@ -310,6 +318,12 @@ two
two
one active two
onetwo
one--two
--three--
onetwo
one
]])
AT_CLEANUP