[latex3-commits] [git/LaTeX3-latex3-latex3] main: Implement \prop_put_from_keyval:Nn (fixes #924) (c880e5f4a)

Bruno Le Floch blflatex at gmail.com
Sun May 16 23:50:39 CEST 2021


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

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

commit c880e5f4a7c55327c94103eae516cef721d082e1
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Sun May 16 23:50:39 2021 +0200

    Implement \prop_put_from_keyval:Nn (fixes #924)


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

c880e5f4a7c55327c94103eae516cef721d082e1
 l3kernel/CHANGELOG.md            |  2 +-
 l3kernel/l3prop.dtx              | 47 ++++++++++++++++++++++++++++++++++++++++
 l3kernel/testfiles/m3prop005.lvt | 17 +++++++++++++++
 l3kernel/testfiles/m3prop005.tlg | 12 ++++++++++
 4 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 44640d90b..5b3140012 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -9,7 +9,7 @@ this project uses date-based 'snapshot' version identifiers.
 
 ### Added
 - `\sys_timer:`
-- `\prop_concat:NNN`
+- `\prop_concat:NNN`, `\prop_put_from_keyval:Nn` (issue #924)
 - Functions to show and log various datatypes (issue #241):
   `\coffin_show:Nnn`, `\coffin_show:N`, `\coffin_log:Nnn`, `\coffin_log:N`,
   `\color_log:n`, `\group_show_list:`, `\group_log_list:`,
diff --git a/l3kernel/l3prop.dtx b/l3kernel/l3prop.dtx
index 0e6cabd15..a5a8f5f96 100644
--- a/l3kernel/l3prop.dtx
+++ b/l3kernel/l3prop.dtx
@@ -206,6 +206,33 @@
 %   other is discarded.
 % \end{function}
 %
+% \begin{function}[added = 2021-05-16]
+%   {
+%     \prop_put_from_keyval:Nn, \prop_put_from_keyval:cn,
+%     \prop_gput_from_keyval:Nn, \prop_gput_from_keyval:cn,
+%   }
+%   \begin{syntax}
+%     \cs{prop_put_from_keyval:Nn} \meta{prop~var}
+%       \{
+%         \meta{key1} |=| \meta{value1} |,|
+%         \meta{key2} |=| \meta{value2} |,| \ldots{}
+%       \}
+%   \end{syntax}
+%   Updates the \meta{prop~var} by adding entries for each key--value
+%   pair given in the second argument.  The addition is done through
+%   \cs{prop_put:Nnn}, hence if the \meta{prop~var} already contains
+%   some of the keys, the corresponding values are discarded and
+%   replaced by those given in the key--value list.  If duplicate keys
+%   appear in the key--value list then only one of the values is kept.
+%
+%   The function is equivalent to storing the key--value pairs in a
+%   temporary property variable using \cs{prop_set_from_keyval:Nn}, then
+%   combining \meta{prop~var} with the temporary variable using
+%   \cs{prop_concat:NNN}.  In particular, the \meta{keys} and
+%   \meta{values} are space-trimmed and unbraced as described in
+%   \cs{prop_set_from_keyval:Nn}.
+% \end{function}
+%
 % \section{Recovering values from property lists}
 %
 % \begin{function}[updated = 2011-08-28]
@@ -776,6 +803,8 @@
 % \begin{macro}{\prop_set_from_keyval:Nn, \prop_set_from_keyval:cn}
 % \begin{macro}{\prop_gset_from_keyval:Nn, \prop_gset_from_keyval:cn}
 % \begin{macro}{\prop_const_from_keyval:Nn, \prop_const_from_keyval:cn}
+% \begin{macro}{\prop_put_from_keyval:Nn, \prop_put_from_keyval:cn}
+% \begin{macro}{\prop_gput_from_keyval:Nn, \prop_gput_from_keyval:cn}
 % \begin{macro}
 %   {
 %     \@@_from_keyval:n,
@@ -828,6 +857,22 @@
     \prop_clear:N \l_@@_internal_prop
   }
 \cs_generate_variant:Nn \prop_const_from_keyval:Nn { c }
+\cs_new_protected:Npn \prop_put_from_keyval:Nn #1#2
+  {
+    \prop_set_eq:NN \l_@@_internal_prop #1
+    \@@_from_keyval:n {#2}
+    \prop_set_eq:NN #1 \l_@@_internal_prop
+    \prop_clear:N \l_@@_internal_prop
+  }
+\cs_generate_variant:Nn \prop_put_from_keyval:Nn { c }
+\cs_new_protected:Npn \prop_gput_from_keyval:Nn #1#2
+  {
+    \prop_set_eq:NN \l_@@_internal_prop #1
+    \@@_from_keyval:n {#2}
+    \prop_gset_eq:NN #1 \l_@@_internal_prop
+    \prop_clear:N \l_@@_internal_prop
+  }
+\cs_generate_variant:Nn \prop_gput_from_keyval:Nn { c }
 \cs_new_protected:Npn \@@_from_keyval:n #1
   {
     \@@_from_keyval_loop:w \prg_do_nothing: #1 ,
@@ -868,6 +913,8 @@
 % \end{macro}
 % \end{macro}
 % \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \subsection{Accessing data in property lists}
 %
diff --git a/l3kernel/testfiles/m3prop005.lvt b/l3kernel/testfiles/m3prop005.lvt
index db76da88e..88c099cb2 100644
--- a/l3kernel/testfiles/m3prop005.lvt
+++ b/l3kernel/testfiles/m3prop005.lvt
@@ -59,5 +59,22 @@
     \prop_log:N \g_tmpa_prop
   }
 
+\TEST { prop_put_from_keyval }
+  {
+    \group_begin:
+      \prop_gset_from_keyval:Nn \g_tmpa_prop
+        { = , \a = b , ~ {\a} ~ = c , ~ \c ~ = ~ { ~ \d = e ~ } }
+      \prop_gput_from_keyval:cn { g_tmpa_prop }
+        { {~\a} = ~ c ~ , \c = ~ { }~ , ~ {\c} = {=} }
+      \prop_set_from_keyval:Nn \l_tmpa_prop
+        { = , \a = b , ~ {\a} ~ = c , ~ \c ~ = ~ { ~ \d = e ~ } }
+      \prop_put_from_keyval:cn { l_tmpa_prop }
+        { {~\a} = ~ c ~ , \c = ~ { }~ , ~ {\c} = {=} }
+      \tl_if_eq:NNTF \l_tmpa_prop \g_tmpa_prop { \TRUE } { \ERROR }
+    \group_end:
+    \prop_log:N \g_tmpa_prop
+    \prop_log:N \l_tmpa_prop
+  }
+
 \END
 
diff --git a/l3kernel/testfiles/m3prop005.tlg b/l3kernel/testfiles/m3prop005.tlg
index 75784f3d4..70157b238 100644
--- a/l3kernel/testfiles/m3prop005.tlg
+++ b/l3kernel/testfiles/m3prop005.tlg
@@ -106,3 +106,15 @@ The property list \g_tmpa_prop contains the pairs (without outer braces):
 >  {=}  =>  {}
 >  {x}  =>  {y}.
 ============================================================
+============================================================
+TEST 4: prop_put_from_keyval
+============================================================
+TRUE
+The property list \g_tmpa_prop contains the pairs (without outer braces):
+>  {}  =>  {}
+>  {\a }  =>  {c}
+>  {\c }  =>  {=}
+>  { \a }  =>  {c}.
+The property list \l_tmpa_prop is empty
+> .
+============================================================





More information about the latex3-commits mailing list.