[latex3-commits] [git/LaTeX3-latex3-latex3] l3bitset: changed named key implementation to use an global internal property (db06ffc40)
Ulrike Fischer
fischer at troubleshooting-tex.de
Sun Dec 20 00:42:55 CET 2020
Repository : https://github.com/latex3/latex3
On branch : l3bitset
Link : https://github.com/latex3/latex3/commit/db06ffc405d34860d21e4eddde1da8cb5da9949e
>---------------------------------------------------------------
commit db06ffc405d34860d21e4eddde1da8cb5da9949e
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date: Sun Dec 20 00:42:55 2020 +0100
changed named key implementation to use an global internal property
>---------------------------------------------------------------
db06ffc405d34860d21e4eddde1da8cb5da9949e
l3kernel/l3bitset.dtx | 82 +++++++++++++++++++++++++-------------
l3kernel/testfiles/m3bitset002.lvt | 32 +++++++--------
2 files changed, 71 insertions(+), 43 deletions(-)
diff --git a/l3kernel/l3bitset.dtx b/l3kernel/l3bitset.dtx
index 8e951fb66..46f43f0d4 100644
--- a/l3kernel/l3bitset.dtx
+++ b/l3kernel/l3bitset.dtx
@@ -169,15 +169,28 @@
% \section{Syntactic sugar: Setting bits by keys}
%
-% If a property with the same name as the bitset exists which maps names to
-% (explizit) numbers, it is possible to set and unset bits by the keys of this property.
+% \begin{function}[added = 2020-12-19]
+% {\bitset_gset_named_index:Nn}
+% \begin{syntax}
+% \cs{bitset_gset_named_index:Nn} \meta{bitset var}
+% \{
+% \meta{name1} |=| \meta{index1} |,|
+% \meta{name2} |=| \meta{index2} |,| \ldots{}
+% \}
+% \end{syntax}
+% This adds the name--index pairs given in the second
+% argument to an internal, global property list. If the
+% property list didn't exist yet, it is created.
+% It is then possible to use the names (the keys of the property
+% to set and unset bits. It is not necessary to give every index
+% a name, and an index can have more than one name.
+% \end{function}
%
% For example after this settings
%
% \begin{verbatim}
% \bitset_new:N \l_pdfannot_F_bitset
-% \prop_new:N \l_pdfannot_F_bitset_prop
-% \prop_set_from_keyval:Nn \l_pdfannot_F_bitset_prop
+% \bitset_gset_named_index:Nn \l_pdfannot_F_bitset
% {
% Invisible = 1,
% Hidden = 2,
@@ -192,19 +205,18 @@
% }
% \end{verbatim}
% it is possible to set bit 3 by using
-% |\bitset_set_key:Nn \l_pdfannot_F_bitset {Print}|
+% |\bitset_set_true_key:Nn \l_pdfannot_F_bitset {Print}|
% If a key is unknown a warning is issued.
-% It is not needed to give all index positions a name.
% \begin{function}[added = 2020-12-13]
-% {\bitset_set_key:Nn, \bitset_set_key:cn,
-% \bitset_gset_key:Nn,\bitset_gset_key:cn }
+% {\bitset_set_true_key:Nn, \bitset_set_true_key:cn,
+% \bitset_gset_true_key:Nn,\bitset_gset_true_key:cn }
% \begin{syntax}
-% \cs{bitset_set_key:Nn} \meta{bitset var} \Arg{key}\\
-% \cs{bitset_gset_key:Nn} \meta{bitset var} \Arg{key}
+% \cs{bitset_set_true_key:Nn} \meta{bitset var} \Arg{key}\\
+% \cs{bitset_gset_true_key:Nn} \meta{bitset var} \Arg{key}
% \end{syntax}
% This sets the bit of the position described by key to \texttt{1}.
%
-% If needed the length of the bit vector is enlarged.
+% If needed the length of the bitset is enlarged.
% \end{function}
% \begin{function}[added = 2020-12-13]
% {\bitset_set_false_key:Nn, \bitset_set_false_key:cn,
@@ -444,18 +456,34 @@
% \end{macrocode}
% \end{macro}
% \begin{macro}
+% {
+% \bitset_gset_named_index:Nn
+% }
+% \begin{macrocode}
+\cs_new_protected:Npn \bitset_gset_named_index:Nn #1 #2
+ {
+ \prop_if_exist:cF { g_@@_\cs_to_str:N #1 _key_prop }
+ {
+ \prop_new:c { g_@@_\cs_to_str:N #1 _key_prop }
+ }
+ \prop_gset_from_keyval:cn
+ { g_@@_\cs_to_str:N #1 _key_prop }
+ { #2 }
+ }
+% \end{macrocode}
+% \begin{macro}
% {
-% \bitset_set_key:Nn, \bitset_set_key:cn,
-% \bitset_gset_key:Nn, \bitset_gset_key:cn
+% \bitset_set_true_key:Nn, \bitset_set_true_key:cn,
+% \bitset_gset_true_key:Nn, \bitset_gset_true_key:cn
% }
% \begin{macrocode}
-\cs_new_protected:Npn \bitset_set_key:Nn #1 #2
+\cs_new_protected:Npn \bitset_set_true_key:Nn #1 #2
{
- \prop_if_in:cnTF { \cs_to_str:N #1_prop } {#2}
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
{
\bitset_set_true:Nn #1
{
- \prop_item:cn{ \cs_to_str:N #1_prop }{#2}
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
}
}
{
@@ -465,13 +493,13 @@
}
}
-\cs_new_protected:Npn \bitset_gset_key:Nn #1 #2
+\cs_new_protected:Npn \bitset_gset_true_key:Nn #1 #2
{
- \prop_if_in:cnTF { \cs_to_str:N #1_prop } {#2}
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
{
\bitset_gset_true:Nn #1
{
- \prop_item:cn{ \cs_to_str:N #1_prop }{#2}
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
}
}
{
@@ -481,8 +509,8 @@
}
}
-\cs_generate_variant:Nn \bitset_set_key:Nn {cn}
-\cs_generate_variant:Nn \bitset_gset_key:Nn {cn}
+\cs_generate_variant:Nn \bitset_set_true_key:Nn {cn}
+\cs_generate_variant:Nn \bitset_gset_true_key:Nn {cn}
% \end{macrocode}
% \end{macro}%
@@ -494,11 +522,11 @@
% \begin{macrocode}
\cs_new_protected:Npn \bitset_set_false_key:Nn #1 #2
{
- \prop_if_in:cnTF { \cs_to_str:N #1_prop } {#2}
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
{
\bitset_set_false:Nn #1
{
- \prop_item:cn{ \cs_to_str:N #1_prop }{#2}
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
}
}
{
@@ -510,11 +538,11 @@
\cs_new_protected:Npn \bitset_gset_false_key:Nn #1 #2
{
- \prop_if_in:cnTF { \cs_to_str:N #1_prop } {#2}
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
{
\bitset_gset_false:Nn #1
{
- \prop_item:cn{ \cs_to_str:N #1_prop }{#2}
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
}
}
{
@@ -534,12 +562,12 @@
% \begin{macrocode}
\cs_new:Npn \bitset_key:Nn #1 #2
{
- \prop_if_in:cnTF { \cs_to_str:N #1_prop } {#2}
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
{
\int_eval:n
{
\str_item:Nn #1
- { 0 -(\prop_item:cn{\cs_to_str:N #1_prop}{#2}) }
+ { 0 - ( \prop_item:cn { g_@@_\cs_to_str:N #1 _key_prop }{#2} ) }
+0
}
}
diff --git a/l3kernel/testfiles/m3bitset002.lvt b/l3kernel/testfiles/m3bitset002.lvt
index 5cccb3036..d2557d461 100644
--- a/l3kernel/testfiles/m3bitset002.lvt
+++ b/l3kernel/testfiles/m3bitset002.lvt
@@ -11,8 +11,8 @@
\START
\OMIT
\bitset_new:N \l_my_test_bitset
-\prop_new:N \l_my_test_bitset_prop
-\prop_set_from_keyval:Nn \l_my_test_bitset_prop
+
+\bitset_gset_named_index:Nn \l_my_test_bitset
{
Invisible = 1,
Hidden = 2,
@@ -26,8 +26,8 @@
LockedContents = 10
}
\bitset_new:N \g_my_test_bitset
-\prop_new:N \g_my_test_bitset_prop
-\prop_gset_from_keyval:Nn \g_my_test_bitset_prop
+
+\bitset_gset_named_index:Nn \g_my_test_bitset
{
gInvisible = 1,
gHidden = 2,
@@ -50,8 +50,8 @@
}
\OMIT
-\bitset_set_key:Nn \l_my_test_bitset{Invisible}
-\bitset_gset_key:Nn \g_my_test_bitset{gInvisible}
+\bitset_set_true_key:Nn \l_my_test_bitset{Invisible}
+\bitset_gset_true_key:Nn \g_my_test_bitset{gInvisible}
\TIMO
\TESTEXP { set~Invisible~(index~1) }
@@ -68,9 +68,9 @@
\TEST { set~unknown~key}
{
- \bitset_set_key:Nn \l_my_test_bitset{unknown}
+ \bitset_set_true_key:Nn \l_my_test_bitset{unknown}
\NEWLINE
- \bitset_gset_key:Nn \g_my_test_bitset{unknown}
+ \bitset_gset_true_key:Nn \g_my_test_bitset{unknown}
\NEWLINE
\bitset_show:N \l_my_test_bitset
\NEWLINE
@@ -78,14 +78,14 @@
}
\OMIT
-\bitset_set_key:Nn \l_my_test_bitset {Print}
-\bitset_set_key:Nn \l_my_test_bitset {NoRotate}
-\bitset_set_key:Nn \l_my_test_bitset {ReadOnly}
-\bitset_set_key:Nn \l_my_test_bitset {ToggleNoView}
-\bitset_gset_key:Nn \g_my_test_bitset {gPrint}
-\bitset_gset_key:Nn \g_my_test_bitset {gNoRotate}
-\bitset_gset_key:Nn \g_my_test_bitset {gReadOnly}
-\bitset_gset_key:Nn \g_my_test_bitset {gToggleNoView}
+\bitset_set_true_key:Nn \l_my_test_bitset {Print}
+\bitset_set_true_key:Nn \l_my_test_bitset {NoRotate}
+\bitset_set_true_key:Nn \l_my_test_bitset {ReadOnly}
+\bitset_set_true_key:Nn \l_my_test_bitset {ToggleNoView}
+\bitset_gset_true_key:Nn \g_my_test_bitset {gPrint}
+\bitset_gset_true_key:Nn \g_my_test_bitset {gNoRotate}
+\bitset_gset_true_key:Nn \g_my_test_bitset {gReadOnly}
+\bitset_gset_true_key:Nn \g_my_test_bitset {gToggleNoView}
\TIMO
\TESTEXP {set~3,~4,~5,~6}
More information about the latex3-commits
mailing list.