[latex3-commits] [git/LaTeX3-latex3-latex3] main: Add \seq_set_split_keep_spaces:Nnn (closes #784) (#857) (a03c65135)

GitHub noreply at github.com
Wed Mar 24 08:50:31 CET 2021


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/a03c65135041915cd1e03630e8b905d7660b558e

>---------------------------------------------------------------

commit a03c65135041915cd1e03630e8b905d7660b558e
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed Mar 24 07:50:31 2021 +0000

    Add \seq_set_split_keep_spaces:Nnn (closes #784) (#857)


>---------------------------------------------------------------

a03c65135041915cd1e03630e8b905d7660b558e
 l3kernel/CHANGELOG.md           |  1 +
 l3kernel/l3seq.dtx              | 63 +++++++++++++++++++++++++++++++----------
 l3kernel/testfiles/m3seq004.lvt | 17 +++++++++++
 l3kernel/testfiles/m3seq004.tlg | 42 ++++++++++++++++++++++++++-
 4 files changed, 107 insertions(+), 16 deletions(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 4ab203fb7..a794de59a 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -8,6 +8,7 @@ this project uses date-based 'snapshot' version identifiers.
 ## [Unreleased]
 
 ### Added
+- `\seq_set_split_keep_spaces:Nnn` (see #784)
 - `\tracingstacklevels`
 - Color export in comma-separated format
 
diff --git a/l3kernel/l3seq.dtx b/l3kernel/l3seq.dtx
index ac195a07f..2a5978eaa 100644
--- a/l3kernel/l3seq.dtx
+++ b/l3kernel/l3seq.dtx
@@ -146,6 +146,27 @@
 %   into \meta{items} as a \meta{token list}.
 % \end{function}
 %
+% \begin{function}[added = 2021-03-24]
+%   {
+%     \seq_set_split_keep_spaces:Nnn , \seq_set_split_keep_spaces:NnV ,
+%     \seq_gset_split_keep_spaces:Nnn, \seq_gset_split:_keep_spaces:NnV
+%   }
+%   \begin{syntax}
+%     \cs{seq_set_split_keep_spaces:Nnn} \meta{sequence} \Arg{delimiter} \Arg{token list}
+%   \end{syntax}
+%   Splits the \meta{token list} into \meta{items} separated
+%   by \meta{delimiter}, and assigns the result to the \meta{sequence}.
+%   One set of outer braces is removed (if any) but any surround spaces
+%   are retained: a single set of braces \emph{inside} one or more spaces are
+%   therefore kept. Empty \meta{items} are preserved by
+%   \cs{seq_set_split_keep_spaces:Nnn}, and can be removed afterwards using
+%   \cs{seq_remove_all:Nn} \meta{sequence} |{}|.
+%   The \meta{delimiter} may not contain |{|, |}| or |#|
+%   (assuming \TeX{}'s normal category code r\'egime).
+%   If the \meta{delimiter} is empty, the \meta{token list} is split
+%   into \meta{items} as a \meta{token list}.
+% \end{function}
+%
 % \begin{function}
 %   {\seq_concat:NNN, \seq_concat:ccc, \seq_gconcat:NNN, \seq_gconcat:ccc}
 %   \begin{syntax}
@@ -1210,10 +1231,15 @@
 %     \seq_set_split:Nnn , \seq_set_split:NnV ,
 %     \seq_gset_split:Nnn, \seq_gset_split:NnV
 %   }
+% \begin{macro}
+%   {
+%     \seq_set_split_keep_spaces:Nnn , \seq_set_split_keep_spaces:NnV ,
+%     \seq_gset_split_keep_spaces:Nnn, \seq_gset_split_keep_spaces:NnV
+%   }
 % \begin{macro}{\@@_set_split:NNnn}
 % \begin{macro}
 %   {
-%     \@@_set_split_auxi:w, \@@_set_split_auxii:w,
+%     \@@_set_split:Nw, \@@_set_split:w,
 %     \@@_set_split_end:
 %   }
 %   When the separator is empty, everything is very simple, just map
@@ -1238,46 +1264,53 @@
 %   braces which are outermost after space trimming.
 %    \begin{macrocode}
 \cs_new_protected:Npn \seq_set_split:Nnn
-  { \@@_set_split:NNnn \__kernel_tl_set:Nx }
+  { \@@_set_split:NNNnn \__kernel_tl_set:Nx \tl_trim_spaces:n }
 \cs_new_protected:Npn \seq_gset_split:Nnn
-  { \@@_set_split:NNnn \__kernel_tl_gset:Nx }
-\cs_new_protected:Npn \@@_set_split:NNnn #1#2#3#4
+  { \@@_set_split:NNNnn \__kernel_tl_gset:Nx \tl_trim_spaces:n }
+\cs_new_protected:Npn \seq_set_split_keep_spaces:Nnn
+  { \@@_set_split:NNNnn \__kernel_tl_set:Nx \exp_not:n }
+\cs_new_protected:Npn \seq_gset_split_keep_spaces:Nnn
+  { \@@_set_split:NNNnn \__kernel_tl_gset:Nx \exp_not:n }
+\cs_new_protected:Npn \@@_set_split:NNNnn #1#2#3#4#5
   {
-    \tl_if_empty:nTF {#3}
+    \tl_if_empty:nTF {#4}
       {
         \tl_set:Nn \l_@@_internal_a_tl
-          { \tl_map_function:nN {#4} \@@_wrap_item:n }
+          { \tl_map_function:nN {#5} \@@_wrap_item:n }
       }
       {
         \tl_set:Nn \l_@@_internal_a_tl
           {
-            \@@_set_split_auxi:w \prg_do_nothing:
-            #4
+            \@@_set_split:Nw #2 \prg_do_nothing:
+            #5
             \@@_set_split_end:
           }
-        \tl_replace_all:Nnn \l_@@_internal_a_tl { #3 }
+        \tl_replace_all:Nnn \l_@@_internal_a_tl {#4}
           {
             \@@_set_split_end:
-            \@@_set_split_auxi:w \prg_do_nothing:
+            \@@_set_split:Nw #2 \prg_do_nothing:
           }
         \__kernel_tl_set:Nx \l_@@_internal_a_tl { \l_@@_internal_a_tl }
       }
-    #1 #2 { \s_@@ \l_@@_internal_a_tl }
+    #1 #3 { \s_@@ \l_@@_internal_a_tl }
   }
-\cs_new:Npn \@@_set_split_auxi:w #1 \@@_set_split_end:
+\cs_new:Npn \@@_set_split:Nw #1#2 \@@_set_split_end:
   {
-    \exp_not:N \@@_set_split_auxii:w
-    \exp_args:No \tl_trim_spaces:n {#1}
+    \exp_not:N \@@_set_split:w
+    \exp_args:No #1 {#2}
     \exp_not:N \@@_set_split_end:
   }
-\cs_new:Npn \@@_set_split_auxii:w #1 \@@_set_split_end:
+\cs_new:Npn \@@_set_split:w #1 \@@_set_split_end:
   { \@@_wrap_item:n {#1} }
 \cs_generate_variant:Nn \seq_set_split:Nnn  { NnV }
 \cs_generate_variant:Nn \seq_gset_split:Nnn { NnV }
+\cs_generate_variant:Nn \seq_set_split_keep_spaces:Nnn  { NnV }
+\cs_generate_variant:Nn \seq_gset_split_keep_spaces:Nnn { NnV }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
 % \end{macro}
+% \end{macro}
 %
 % \begin{macro}{\seq_concat:NNN, \seq_concat:ccc}
 % \UnitTested
diff --git a/l3kernel/testfiles/m3seq004.lvt b/l3kernel/testfiles/m3seq004.lvt
index 290bfd941..6c34e5833 100644
--- a/l3kernel/testfiles/m3seq004.lvt
+++ b/l3kernel/testfiles/m3seq004.lvt
@@ -63,6 +63,23 @@
   \seq_log:N \l_my_seq
 }
 
+\TEST{seq_set_split_keep_spaces:Nnn}{
+  \seq_set_split_keep_spaces:Nnn \l_my_seq { | } { }
+  \seq_log:N \l_my_seq
+  \seq_set_split_keep_spaces:Nnn \l_my_seq { , } { a, }
+  \seq_log:N \l_my_seq
+  \seq_set_split_keep_spaces:Nnn \l_my_seq { , } { a~,~b }
+  \seq_log:N \l_my_seq
+  \seq_set_split_keep_spaces:Nnn \l_my_seq { | }
+    { ~ a | b | ~c~ | {|} | ~{~|{}~} | d ~ }
+  \seq_log:N \l_my_seq
+  \seq_set_split_keep_spaces:Nnn \l_my_seq { ~ }
+    { Hello,~world,~my~name~is~LaTeX3! }
+  \seq_log:N \l_my_seq
+  \seq_set_split_keep_spaces:Nnn \l_my_seq { } { abcdefghijklm }
+  \seq_log:N \l_my_seq
+}
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 \TEST{seq_set_(filter|map):NNn}{
diff --git a/l3kernel/testfiles/m3seq004.tlg b/l3kernel/testfiles/m3seq004.tlg
index a0dab4fc6..8d721efd2 100644
--- a/l3kernel/testfiles/m3seq004.tlg
+++ b/l3kernel/testfiles/m3seq004.tlg
@@ -68,7 +68,47 @@ The sequence \l_my_seq contains the items (without outer braces):
 >  {m}.
 ============================================================
 ============================================================
-TEST 3: seq_set_(filter|map):NNn
+TEST 3: seq_set_split_keep_spaces:Nnn
+============================================================
+The sequence \l_my_seq contains the items (without outer braces):
+>  {}.
+The sequence \l_my_seq contains the items (without outer braces):
+>  {a}
+>  {}.
+The sequence \l_my_seq contains the items (without outer braces):
+>  {a }
+>  { b}.
+The sequence \l_my_seq contains the items (without outer braces):
+>  { a}
+>  {b}
+>  { c }
+>  {|}
+>  { { |{} }}
+>  {d }.
+The sequence \l_my_seq contains the items (without outer braces):
+>  {Hello,}
+>  {world,}
+>  {my}
+>  {name}
+>  {is}
+>  {LaTeX3!}.
+The sequence \l_my_seq contains the items (without outer braces):
+>  {a}
+>  {b}
+>  {c}
+>  {d}
+>  {e}
+>  {f}
+>  {g}
+>  {h}
+>  {i}
+>  {j}
+>  {k}
+>  {l}
+>  {m}.
+============================================================
+============================================================
+TEST 4: seq_set_(filter|map):NNn
 ============================================================
 The sequence \l_my_seq contains the items (without outer braces):
 >  {4}





More information about the latex3-commits mailing list.