[latex3-commits] [git/LaTeX3-latex3-latex3] gh900: Implement \str_map_tokens:nn (see #900) (48719c73c)
Bruno Le Floch
blflatex at gmail.com
Wed May 5 00:09:54 CEST 2021
Repository : https://github.com/latex3/latex3
On branch : gh900
Link : https://github.com/latex3/latex3/commit/48719c73cecf09b36d629a8ec965197b6db0c7d3
>---------------------------------------------------------------
commit 48719c73cecf09b36d629a8ec965197b6db0c7d3
Author: Bruno Le Floch <blflatex at gmail.com>
Date: Wed May 5 00:08:49 2021 +0200
Implement \str_map_tokens:nn (see #900)
>---------------------------------------------------------------
48719c73cecf09b36d629a8ec965197b6db0c7d3
l3kernel/l3candidates.dtx | 39 +++++++++++++++++++++++++++++++++++++++
l3kernel/l3str.dtx | 10 +++++-----
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 6cfb0d745..7e963e4eb 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -470,6 +470,21 @@
% assigned locally for |pop| or globally for |gpop| functions.
% \end{function}
%
+% \section{Additions to \pkg{l3str}}
+%
+% \begin{function}[rEXP, added = 2021-05-05]
+% {\str_map_tokens:nn, \str_map_tokens:Nn, \str_map_tokens:cn}
+% \begin{syntax}
+% \cs{str_map_tokens:nn} \Arg{token list} \Arg{code}
+% \cs{str_map_tokens:Nn} \meta{str~var} \Arg{code}
+% \end{syntax}
+% Converts the \meta{token list} to a \meta{string} then applies
+% \meta{code} to every \meta{character} in the \meta{string} including
+% spaces. The \meta{code} receives each character as a trailing brace
+% group. This is equivalent to \cs{str_map_function:nN} if the
+% \meta{code} consists of a single function.
+% \end{function}
+%
% \section{Additions to \pkg{l3sys}}
%
% \begin{variable}[added = 2018-05-02]{\c_sys_engine_version_str}
@@ -1333,6 +1348,30 @@
% \end{macro}
% \end{macro}
%
+% \subsection{Additions to \pkg{l3str}}
+%
+% \begin{macrocode}
+%<@@=str>
+% \end{macrocode}
+%
+% \begin{macro}[rEXP]{\str_map_tokens:Nn, \str_map_tokens:cn}
+% \begin{macro}[rEXP]{\str_map_tokens:nn}
+% Uses an auxiliary of \cs{str_map_function:NN}.
+% \begin{macrocode}
+\cs_new:Npn \str_map_tokens:nn #1#2
+ {
+ \exp_args:Nno \use:nn
+ { \@@_map_function:w \@@_map_function:nn {#2} }
+ { \__kernel_tl_to_str:w {#1} }
+ \q_@@_recursion_tail ? ~
+ \prg_break_point:Nn \str_map_break: { }
+ }
+\cs_new:Npn \str_map_tokens:Nn { \exp_args:No \str_map_tokens:nn }
+\cs_generate_variant:Nn \str_map_tokens:Nn { c }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \subsection{Additions to \pkg{l3sys}}
%
% \begin{macrocode}
diff --git a/l3kernel/l3str.dtx b/l3kernel/l3str.dtx
index 0a72fa7dd..290b6a083 100644
--- a/l3kernel/l3str.dtx
+++ b/l3kernel/l3str.dtx
@@ -1247,7 +1247,7 @@
% \begin{macro}{\str_map_variable:nNn}
% \begin{macro}{\str_map_break:}
% \begin{macro}{\str_map_break:n}
-% \begin{macro}[rEXP]{\@@_map_function:w, \@@_map_function:Nn}
+% \begin{macro}[rEXP]{\@@_map_function:w, \@@_map_function:nn}
% \begin{macro}{\@@_map_inline:NN, \@@_map_variable:NnN}
% The inline and variable mappings are similar to the usual token list
% mappings but start out by turning the argument to an ``other
@@ -1255,7 +1255,7 @@
% require \cs{__kernel_str_to_other:n}, quadratic in the string length. To deal
% with spaces in that case, \cs{@@_map_function:w} replaces the
% following space by a braced space and a further call to itself.
-% These are received by \cs{@@_map_function:Nn}, which passes
+% These are received by \cs{@@_map_function:nn}, which passes
% the space to |#1| and calls \cs{@@_map_function:w} to deal with the
% next space. The space before the braced space allows to optimize
% the \cs{q_@@_recursion_tail} test. Of course we need to include a
@@ -1273,7 +1273,7 @@
\cs_new:Npn \str_map_function:nN #1#2
{
\exp_after:wN \@@_map_function:w
- \exp_after:wN \@@_map_function:Nn \exp_after:wN #2
+ \exp_after:wN \@@_map_function:nn \exp_after:wN #2
\__kernel_tl_to_str:w {#1}
\q_@@_recursion_tail ? ~
\prg_break_point:Nn \str_map_break: { }
@@ -1282,12 +1282,12 @@
{ \exp_args:No \str_map_function:nN }
\cs_new:Npn \@@_map_function:w #1 ~
{ #1 { ~ { ~ } \@@_map_function:w } }
-\cs_new:Npn \@@_map_function:Nn #1#2
+\cs_new:Npn \@@_map_function:nn #1#2
{
\if_meaning:w \q_@@_recursion_tail #2
\exp_after:wN \str_map_break:
\fi:
- #1 #2 \@@_map_function:Nn #1
+ #1 #2 \@@_map_function:nn {#1}
}
\cs_generate_variant:Nn \str_map_function:NN { c }
\cs_new_protected:Npn \str_map_inline:nn #1#2
More information about the latex3-commits
mailing list.