mirror of
git://git.sv.gnu.org/autoconf
synced 2025-02-11 13:51:04 +08:00
Change m4_join to match libtool's ltsugar semantics.
* lib/m4sugar/m4sugar.m4 (m4_join): Just define this, not defun. Ignore empty arguments, using... (_m4_join): ...this new helper. * tests/m4sugar.at (m4@&t@_join): New test. * doc/autoconf.texi (Text processing Macros): Document new semantics of m4_join. Signed-off-by: Eric Blake <ebb9@byu.net>
This commit is contained in:
parent
6e1d6e2c5b
commit
72431d8c84
@ -1,5 +1,13 @@
|
||||
2007-10-13 Eric Blake <ebb9@byu.net>
|
||||
|
||||
Change m4_join to match libtool's ltsugar semantics.
|
||||
* lib/m4sugar/m4sugar.m4 (m4_join): Just define this, not defun.
|
||||
Ignore empty arguments, using...
|
||||
(_m4_join): ...this new helper.
|
||||
* tests/m4sugar.at (m4@&t@_join): New test.
|
||||
* doc/autoconf.texi (Text processing Macros): Document new
|
||||
semantics of m4_join.
|
||||
|
||||
Make AC_PREREQ faster and more robust.
|
||||
* lib/m4sugar/m4sugar.m4 (m4_ignore, m4_unquote): New macros.
|
||||
(m4_version_prereq): Inline constant expansions.
|
||||
|
@ -10832,8 +10832,14 @@ still a quoted string.
|
||||
|
||||
@defmac m4_join (@ovar{separator}, @var{args}@dots{})
|
||||
@msindex{join}
|
||||
Concatenate each @var{arg}, separated by @var{separator}. The result is
|
||||
a quoted string.
|
||||
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.
|
||||
@example
|
||||
m4_define([active], [ACTIVE])dnl
|
||||
m4_join([|], [one], [], [active], [two])
|
||||
@result{}one|active|two
|
||||
@end example
|
||||
@end defmac
|
||||
|
||||
@defmac m4_newline
|
||||
|
@ -1663,13 +1663,24 @@ m4_define([m4_normalize],
|
||||
|
||||
# m4_join(SEP, ARG1, ARG2...)
|
||||
# ---------------------------
|
||||
# Produce ARG1SEPARG2...SEPARGn.
|
||||
m4_defun([m4_join],
|
||||
[m4_case([$#],
|
||||
[1], [],
|
||||
[2], [[$2]],
|
||||
[[$2][$1]$0([$1], m4_shift2($@))])])
|
||||
|
||||
# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG
|
||||
# is the empty string.
|
||||
#
|
||||
# Since the number of arguments to join can be arbitrarily long, we
|
||||
# want to avoid having more than one $@ in the macro definition;
|
||||
# otherwise, the expansion would require twice the memory of the already
|
||||
# long list. Hence, m4_join merely looks for the first non-empty element,
|
||||
# and outputs just that element; while _m4_join looks for all non-empty
|
||||
# elements, and outputs them following a separator. The final trick to
|
||||
# note is that we decide between recursing with $0 or _$0 based on the
|
||||
# nested m4_if ending with `_'.
|
||||
m4_define([m4_join],
|
||||
[m4_if([$#], [1], [],
|
||||
[$#], [2], [[$2]],
|
||||
[m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift2($@))])])
|
||||
m4_define([_m4_join],
|
||||
[m4_if([$#$2], [2], [],
|
||||
[m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])])
|
||||
|
||||
|
||||
# m4_append(MACRO-NAME, STRING, [SEPARATOR])
|
||||
|
@ -44,6 +44,8 @@ AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
|
||||
#
|
||||
# - m4_append
|
||||
#
|
||||
# - m4_join
|
||||
#
|
||||
# - m4_text_wrap
|
||||
# uses m4_split code.
|
||||
|
||||
@ -251,6 +253,43 @@ one, two, three
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## --------- ##
|
||||
## m4_join. ##
|
||||
## --------- ##
|
||||
|
||||
AT_SETUP([m4@&t@_join])
|
||||
|
||||
AT_CHECK_M4SUGAR_TEXT(
|
||||
[[m4_define([active], [ACTIVE])
|
||||
m4_join
|
||||
m4_join([|])
|
||||
m4_join([, ], [one], [two])
|
||||
m4_dquote(m4_join([, ], [one], [two]))
|
||||
m4_join([|], [active], [active])
|
||||
m4_join([|], ,,,[one])
|
||||
m4_join([|], [one],,,)
|
||||
m4_join([], ,,,[two])
|
||||
m4_join([], [two],,,)
|
||||
m4_join([ active ], [one], , [two])
|
||||
m4_join([], [one], [two])
|
||||
]],
|
||||
[[
|
||||
|
||||
|
||||
one, two
|
||||
[one, two]
|
||||
active|active
|
||||
one
|
||||
one
|
||||
two
|
||||
two
|
||||
one active two
|
||||
onetwo
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## -------------- ##
|
||||
## m4_text_wrap. ##
|
||||
## -------------- ##
|
||||
|
Loading…
Reference in New Issue
Block a user