diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3experimental/l3bitset/l3bitset.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3experimental/l3bitset/l3bitset.sty | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3bitset/l3bitset.sty b/Master/texmf-dist/tex/latex/l3experimental/l3bitset/l3bitset.sty new file mode 100644 index 00000000000..df0bdb61709 --- /dev/null +++ b/Master/texmf-dist/tex/latex/l3experimental/l3bitset/l3bitset.sty @@ -0,0 +1,234 @@ +%% +%% This is file `l3bitset.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% l3bitset.dtx (with options: `package') +%% +%% Copyright (C) 2020 The LaTeX3 Project +%% +%% It may be distributed and/or modified under the conditions of +%% the LaTeX Project Public License (LPPL), either version 1.3c of +%% this license or (at your option) any later version. The latest +%% version of this license is in the file: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This file is part of the "l3experimental bundle" (The Work in LPPL) +%% and all files in that bundle must be distributed together. +%% +%% File: l3bitset.dtx +\ProvidesExplPackage{l3bitset}{2020-01-29}{} + {L3 Experimental bitset support} +\cs_new_protected:Npn \bitset_new:N #1 + { + \__kernel_chk_if_free_cs:N #1 + \cs_gset_eq:NN #1 \c_zero_str + \prop_new:c { g__bitset_ \cs_to_str:N #1 _name_prop } + } + +\cs_new_protected:Npn \bitset_new:Nn #1 #2 + { + \__kernel_chk_if_free_cs:N #1 + \cs_gset_eq:NN #1 \c_zero_str + \prop_new:c { g__bitset_ \cs_to_str:N #1 _name_prop } + \prop_gset_from_keyval:cn + { g__bitset_ \cs_to_str:N #1 _name_prop } + {#2} + } +\cs_generate_variant:Nn \bitset_new:N { c } +\prop_new:N \l__bitset_tmpa_prop +\cs_new_protected:Npn \bitset_addto_named_index:Nn #1#2 + { + \prop_set_from_keyval:Nn \l__bitset_tmpa_prop {#2} + \prop_map_inline:Nn \l__bitset_tmpa_prop + { + \prop_gput:cnn + { g__bitset_ \cs_to_str:N #1 _name_prop } + {##1} + {##2} + } + } +\prg_new_eq_conditional:NNn + \bitset_if_exist:N \str_if_exist:N { p , T , F , TF } +\prg_new_eq_conditional:NNn + \bitset_if_exist:c \str_if_exist:c + { p , T , F , TF } +\cs_new_protected:Npn \__bitset_set_true:Nn #1#2 + { \__bitset_set:NNnN \str_set:Nx #1 {#2} 1 } +\cs_new_protected:Npn \__bitset_gset_true:Nn #1#2 + { \__bitset_set:NNnN \str_gset:Nx #1 {#2} 1 } +\cs_new_protected:Npn \__bitset_set_false:Nn #1#2 + { \__bitset_set:NNnN \str_set:Nx #1 {#2} 0 } +\cs_new_protected:Npn \__bitset_gset_false:Nn #1#2 + { \__bitset_set:NNnN \str_gset:Nx #1 {#2} 0 } +\cs_new_protected:Npn \__bitset_set:NNnN #1#2#3#4 + { + \int_compare:nNnT {#3} > { 0 } + { + \int_compare:nNnTF { \str_count:N #2 } < {#3} + { + #1 #2 + { + #4 + \prg_replicate:nn { #3 - \str_count:N #2 - 1 } { 0 } + #2 + } + } + { + #1 #2 + { + \str_range:Nnn #2 { 1 } { -1 - (#3) } + #4 + \str_range:Nnn #2 { 1 - (#3) } { -1 } + } + } + } + } +\int_new:N \l__bitset_internal_int +\prg_new_protected_conditional:Npnn \__bitset_test_digits:n #1 { TF } + { + \tex_afterassignment:D \__bitset_test_digits:w + \l__bitset_internal_int = 0 \tl_trim_spaces_apply:nN {#1} \tl_to_str:n + \__bitset_test_digits_end: + \use_i:nnn \if_false: + \__bitset_test_digits_end: + \if_int_compare:w \c_zero_int < \l__bitset_internal_int + \prg_return_true: + \else: + \prg_return_false: + \fi: + } +\cs_new_eq:NN \__bitset_test_digits_end: \exp_stop_f: +\cs_new_protected:Npn \__bitset_test_digits:w #1 \__bitset_test_digits_end: { } +\cs_new_protected:Npn \bitset_set_true:Nn #1#2 + { \__bitset_set:NNn \__bitset_set_true:Nn #1 {#2} } +\cs_new_protected:Npn \bitset_gset_true:Nn #1#2 + { \__bitset_set:NNn \__bitset_gset_true:Nn #1 {#2} } +\cs_new_protected:Npn \bitset_set_false:Nn #1#2 + { \__bitset_set:NNn \__bitset_set_false:Nn #1 {#2} } +\cs_new_protected:Npn \bitset_gset_false:Nn #1#2 + { \__bitset_set:NNn \__bitset_gset_false:Nn #1 {#2} } +\cs_new_protected:Npn \__bitset_set:NNn #1#2#3 + { + \prop_if_in:cnTF { g__bitset_ \cs_to_str:N #2 _name_prop } {#3} + { + #1 #2 + { + \prop_item:cn { g__bitset_ \cs_to_str:N #2 _name_prop } {#3} + } + } + { + \__bitset_test_digits:nTF {#3} + { + #1 #2 {#3} + \prop_gput:cnn { g__bitset_ \cs_to_str:N #2 _name_prop } {#3} {#3} + } + { + \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name } + { \token_to_str:N #2 } + { \tl_to_str:n {#3} } + } + } + } +\cs_generate_variant:Nn \bitset_set_true:Nn { c } +\cs_generate_variant:Nn \bitset_gset_true:Nn { c } +\cs_generate_variant:Nn \bitset_set_false:Nn { c } +\cs_generate_variant:Nn \bitset_gset_false:Nn { c } +\cs_new_protected:Npn \bitset_clear:N #1 + { + \str_set_eq:NN #1 \c_zero_str + } +\cs_new_protected:Npn \bitset_gclear:N #1 + { + \str_gset_eq:NN #1 \c_zero_str + } +\cs_generate_variant:Nn \bitset_clear:N { c } +\cs_generate_variant:Nn \bitset_gclear:N { c } +\cs_new:Npn \bitset_to_arabic:N #1 + { + \int_compare:nNnTF { \str_count:N #1 } < { 32 } + { \exp_args:No \int_from_bin:n {#1} } + { + \exp_after:wN \__bitset_to_int:nN \exp_after:wN 0 + #1 \q_recursion_tail \q_recursion_stop + } + } + +\cs_new:Npn \__bitset_to_int:nN #1#2 + { + \quark_if_recursion_tail_stop_do:Nn #2 {#1} + \exp_args:Nf \__bitset_to_int:nN { \fp_eval:n { #1 * 2 + #2 } } + } + +\cs_new:Npn \bitset_to_bin:N #1 + { + #1 + } +\cs_generate_variant:Nn \bitset_to_arabic:N { c } +\cs_generate_variant:Nn \bitset_to_bin:N { c } +\cs_new:Npn \bitset_item:Nn #1#2 + { + \prop_if_in:cnTF { g__bitset_ \cs_to_str:N #1 _name_prop } {#2} + { + \int_eval:n + { + \str_item:Nn #1 + { 0 - ( \prop_item:cn { g__bitset_ \cs_to_str:N #1 _name_prop } {#2} ) } + +0 + } + } + { + 0 + } + } +\cs_generate_variant:Nn \bitset_item:Nn { c } + +\cs_new_protected:Npn \bitset_show:N { \__bitset_show:NN \msg_show:nnxxxx } +\cs_generate_variant:Nn \bitset_show:N { c } +\cs_new_protected:Npn \bitset_log:N { \__bitset_show:NN \msg_log:nnxxxx } +\cs_generate_variant:Nn \bitset_log:N { c } +\cs_new_protected:Npn \bitset_show_named_index:N { \__bitset_show_named_index:NN \msg_show:nnxxxx } +\cs_generate_variant:Nn \bitset_show_named_index:N { c } +\cs_new_protected:Npn \__bitset_show:NN #1#2 + { + \__kernel_chk_defined:NT #2 + { + #1 { LaTeX/bitset } { show-bitset } + { \token_to_str:N #2 } + { \bitset_to_bin:N #2 } + { \bitset_to_arabic:N #2 } + { } + } + } +\cs_new_protected:Npn \__bitset_show_named_index:NN #1#2 + { + \__kernel_chk_defined:NT #2 + { + #1 { LaTeX/bitset } { show-names } + { \token_to_str:N #2 } + { \prop_map_function:cN { g__bitset_ \cs_to_str:N #2 _name_prop } \msg_show_item:nn } + { } + { } + } + } + \__kernel_msg_new:nnn { bitset } { show-bitset } + { + The~bitset~#1~has~the~representation: \\ + >~binary:~#2 \\ + >~arabic:~#3 . + } +\__kernel_msg_new:nnn { bitset } { show-names } + { + The~bitset~#1~ + \tl_if_empty:nTF {#2} + { knows~no~names~yet \\>~ . } + { knows~the~name/index~pairs~(without~outer~braces): #2 . } + } +\__kernel_msg_new:nnn { bitset } { bitset-unknown-name } + { The~name~'#2'~is~unknown~for~bitset~\tl_to_str:n {#1} } + +%% +%% +%% End of file `l3bitset.sty'. |