[latex3-commits] [git/LaTeX3-latex3-latex3] l3bitset-2: rewrote set_true/set_false to take names (67d63ba2c)
Ulrike Fischer
fischer at troubleshooting-tex.de
Tue Dec 29 15:39:11 CET 2020
Repository : https://github.com/latex3/latex3
On branch : l3bitset-2
Link : https://github.com/latex3/latex3/commit/67d63ba2c73cfb18a2bcb6ffe0e5c97d7bf659e6
>---------------------------------------------------------------
commit 67d63ba2c73cfb18a2bcb6ffe0e5c97d7bf659e6
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date: Tue Dec 29 15:39:11 2020 +0100
rewrote set_true/set_false to take names
>---------------------------------------------------------------
67d63ba2c73cfb18a2bcb6ffe0e5c97d7bf659e6
l3experimental/l3bitset/l3bitset.dtx | 166 ++++++++++++++++++++++++++++++-----
1 file changed, 143 insertions(+), 23 deletions(-)
diff --git a/l3experimental/l3bitset/l3bitset.dtx b/l3experimental/l3bitset/l3bitset.dtx
index 485a5e5b2..c04f3dc05 100644
--- a/l3experimental/l3bitset/l3bitset.dtx
+++ b/l3experimental/l3bitset/l3bitset.dtx
@@ -153,28 +153,33 @@
% \begin{function}[added = 2020-12-13]
% { \bitset_set_true:Nn, \bitset_set_true:cn, \bitset_gset_true:Nn, \bitset_gset_true:cn }
% \begin{syntax}
-% \cs{bitset_set_true:Nn} \meta{bitset var} \Arg{integer expression}\\
-% \cs{bitset_gset_true:Nn} \meta{bitset var} \Arg{integer expression}
+% \cs{bitset_set_true:Nn} \meta{bitset var} \Arg{position}\\
+% \cs{bitset_gset_true:Nn} \meta{bitset var} \Arg{position}
% \end{syntax}
-% Evaluates the \meta{integer expression} and sets the bit of the
-% index position it represents to 1. Index position are 1-based and set from
-% right to left (so one can view the bitset as a binary number).
+% This sets the bit of the index position represented by \Arg{position} to 1.
+% \Arg{position} should be either a declared name or a positive,
+% unsigned explicit integer (not an integer expression).
+% If it is both a name and a number, the name will take precedence.
+% Index position are 1-based.
% If needed the length of the bit vector is enlarged.
-% If the \meta{integer expression} evaluates to a negative number, nothing happens.
% \end{function}
%
% \begin{function}[added = 2020-12-13]
% { \bitset_set_false:Nn, \bitset_set_false:cn, \bitset_gset_false:Nn, \bitset_set_false:cn }
% \begin{syntax}
-% \cs{bitset_set_false:Nn} \meta{bitset var} \Arg{integer expression}\\
-% \cs{bitset_gset_false:Nn} \meta{bitset var} \Arg{integer expression}
+% \cs{bitset_set_false:Nn} \meta{bitset var} \Arg{position}\\
+% \cs{bitset_gset_false:Nn} \meta{bitset var} \Arg{position}
% \end{syntax}
-% Evaluates the \meta{integer expression} and unsets the bit of the
-% index position it represents (sets it to 0).
-% The index is 1-based. If the \meta{integer expression} evaluates to a
-% negative number or is larger than the current length of the bit vector
+% This unsets the bit of the index position represented by \Arg{position} (sets
+% it to 0).
+% \Arg{position} should be either a declared name or a positive,
+% unsigned explicit integer (not an integer expression).
+% If it is both a name and a number, the name will take precedence.
+% The index is 1-based. If the index position is larger
+% than the current length of the bit vector
% nothing happens. If the leading (left most) bit is unset,
-% zeros are not trimmed but stay in the bit vector.
+% zeros are not trimmed but stay in the bit vector and a still shown
+% by \cs{bitset_show:N}.
% \end{function}
%
% \begin{function}[added = 2020-12-22]
@@ -183,7 +188,7 @@
% \cs{bitset_clear:N} \meta{bitset var} \\
% \cs{bitset_gclear:N} \meta{bitset var}
% \end{syntax}
-% This resets the bitset to the initial state.
+% This resets the bitset to the initial state. The declared names are not changed.
% \end{function}
%
% \section{Using bitsets}
@@ -385,17 +390,17 @@
{ p , T , F , TF }
% \end{macrocode}
% \end{macro}
-
% \begin{macro}
% {
-% \bitset_set_true:Nn, \bitset_set_true:cn,
-% \bitset_gset_true:Nn, \bitset_gset_true:cn,
+% \@@_set_true:Nn, \@@_gset_true:Nn
% }
+% The internal command uses only numbers (integer expressions) for the
+% position.
% A bit is set by either extending the string or by splitting it and
% then inserting an 1. It is not checked if the value was already 1.
% \begin{macrocode}
% #1 name, #2 index (integer expression, 1-based)
-\cs_new_protected:Npn \bitset_set_true:Nn #1 #2
+\cs_new_protected:Npn \@@_set_true:Nn #1 #2
{
\int_compare:nNnT {#2 } > { 0 }
{
@@ -419,7 +424,7 @@
}
%#1 name, #2 index (integer expression,1-based)
-\cs_new_protected:Npn \bitset_gset_true:Nn #1 #2
+\cs_new_protected:Npn \@@_gset_true:Nn #1 #2
{
\int_compare:nNnT {#2 } > { 0 }
{
@@ -441,6 +446,64 @@
}
}
}
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}
+% {
+% \bitset_set_true:Nn, \bitset_set_true:cn,
+% \bitset_gset_true:Nn, \bitset_gset_true:cn,
+% }
+% The user commands must first translate the argument to an index number.
+% \begin{macrocode}
+% #1 name, #2 index (name or number)
+\cs_new_protected:Npn \bitset_set_true:Nn #1 #2
+ {
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+ {
+ \@@_set_true:Nn #1
+ {
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+ }
+ }
+ {
+ \regex_match:nnTF { ^[\d]+$ } {#2}
+ {
+ %is number
+ \@@_set_true:Nn #1 { #2}
+ \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+ }
+ {
+ \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+ { \token_to_str:N #1 }
+ { \tl_to_str:n { #2} }
+ }
+ }
+ }
+
+%#1 name, #2 index (name or number)
+\cs_new_protected:Npn \bitset_gset_true:Nn #1 #2
+ {
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+ {
+ \@@_gset_true:Nn #1
+ {
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+ }
+ }
+ {
+ \regex_match:nnTF { ^[\d]+$ } {#2}
+ {
+ %is number
+ \@@_gset_true:Nn #1 { #2}
+ \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+ }
+ {
+ \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+ { \token_to_str:N #1 }
+ { \tl_to_str:n { #2} }
+ }
+ }
+ }
\cs_generate_variant:Nn \bitset_set_true:Nn {cn}
\cs_generate_variant:Nn \bitset_gset_true:Nn {cn}
% \end{macrocode}
@@ -448,12 +511,13 @@
% \begin{macro}
% {
-% \bitset_set_false:Nn, \bitset_set_false:cn,
-% \bitset_gset_false:Nn, \bitset_gset_false:cn
+% \@@_set_false:Nn, \@@_gset_false:Nn
% }
+% The internal command uses only numbers (integer expressions) for the
+% position.
% Unsetting a bit has only to do something if the string is longer than then index.
% \begin{macrocode}
-\cs_new_protected:Npn \bitset_set_false:Nn #1 #2 %#1 name, #2 index (1-based)
+\cs_new_protected:Npn \@@_set_false:Nn #1 #2 %#1 name, #2 index (1-based)
{
\int_compare:nNnT {#2 } > { 0 }
{
@@ -470,7 +534,7 @@
}
}
-\cs_new_protected:Npn \bitset_gset_false:Nn #1 #2 %#1 name, #2 index (1-based)
+\cs_new_protected:Npn \@@_gset_false:Nn #1 #2 %#1 name, #2 index (1-based)
{
\int_compare:nNnT {#2 } > { 0 }
{
@@ -486,6 +550,62 @@
}
}
}
+% \end{macrocode}
+% \end{macro}
+
+% \begin{macro}
+% {
+% \bitset_set_false:Nn, \bitset_set_false:cn,
+% \bitset_gset_false:Nn, \bitset_gset_false:cn
+% }
+% \begin{macrocode}
+\cs_new_protected:Npn \bitset_set_false:Nn #1 #2 %#1 name, #2 index (1-based)
+ {
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+ {
+ \@@_set_false:Nn #1
+ {
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+ }
+ }
+ {
+ \regex_match:nnTF { ^[\d]+$ } {#2}
+ {
+ %is number
+ \@@_set_false:Nn #1 { #2}
+ \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+ }
+ {
+ \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+ { \token_to_str:N #1 }
+ { \tl_to_str:n { #2} }
+ }
+ }
+ }
+
+\cs_new_protected:Npn \bitset_gset_false:Nn #1 #2 %#1 name, #2 index (1-based)
+ {
+ \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+ {
+ \@@_gset_false:Nn #1
+ {
+ \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+ }
+ }
+ {
+ \regex_match:nnTF { ^[\d]+$ } {#2}
+ {
+ %is number
+ \@@_gset_false:Nn #1 { #2}
+ \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+ }
+ {
+ \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+ { \token_to_str:N #1 }
+ { \tl_to_str:n { #2} }
+ }
+ }
+ }
\cs_generate_variant:Nn \bitset_set_false:Nn {cn}
\cs_generate_variant:Nn \bitset_gset_false:Nn {cn}
% \end{macrocode}
More information about the latex3-commits
mailing list.