%% %% This is file `l3str.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% l3str-expl.dtx (with options: `package') %% %% EXPERIMENTAL CODE %% %% Do not distribute this file without also distributing the %% source files specified above. %% %% Do not distribute a modified version of this file. %% %% File: l3str.dtx Copyright (C) 2011-2014 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. %% %% The released version of this bundle is available from CTAN. %% %% ----------------------------------------------------------------------- %% %% The development version of the bundle can be found at %% %% http://www.latex-project.org/svnroot/experimental/trunk/ %% %% for those people who are interested. %% %%%%%%%%%%% %% NOTE: %% %%%%%%%%%%% %% %% Snapshots taken from the repository represent work in progress and may %% not work or may contain conflicting material! We therefore ask %% people _not_ to put them into distributions, archives, etc. without %% prior consultation with the LaTeX3 Project. %% %% ----------------------------------------------------------------------- \RequirePackage{expl3}[2014/08/25] \@ifpackagelater{expl3}{2014/08/25} {} {% \PackageError{l3str}{Support package l3kernel too old} {% Please install an up to date version of l3kernel\MessageBreak using your TeX package manager or from CTAN.\MessageBreak \MessageBreak Loading l3str will abort!% }% \endinput } \GetIdInfo$Id: l3str-expl.dtx 5378 2014-08-25 10:59:48Z joseph $ {L3 Experimental strings} \def\ExplFileName{l3str} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} \cs_new_eq:NN \str_new:N \tl_new:N \cs_generate_variant:Nn \str_new:N { c } \tl_map_inline:nn { { set } { gset } { const } { put_left } { gput_left } { put_right } { gput_right } } { \cs_new_protected:cpx { str_ #1 :Nn } ##1##2 { \exp_not:c { tl_ #1 :Nx } ##1 { \exp_not:N \tl_to_str:n {##2} } } \exp_args:Nc \cs_generate_variant:Nn { str_ #1 :Nn } { Nx , cn , cx } } \str_const:Nx \c_backslash_str { \cs_to_str:N \\ } \str_const:Nx \c_left_brace_str { \cs_to_str:N \{ } \str_const:Nx \c_right_brace_str { \cs_to_str:N \} } \str_const:Nx \c_hash_str { \cs_to_str:N \# } \str_const:Nx \c_tilde_str { \cs_to_str:N \~ } \str_const:Nx \c_percent_str { \cs_to_str:N \% } \str_new:N \l_tmpa_str \str_new:N \l_tmpb_str \str_new:N \g_tmpa_str \str_new:N \g_tmpb_str \cs_new_nopar:Npn \str_count_spaces:N { \exp_args:No \str_count_spaces:n } \cs_new:Npn \str_count_spaces:n #1 { \int_eval:n { \exp_after:wN \__str_count_spaces_loop:wwwwwwwww \tl_to_str:n {#1} ~ X 7 ~ X 6 ~ X 5 ~ X 4 ~ X 3 ~ X 2 ~ X 1 ~ X 0 ~ X -1 ~ \q_stop } } \cs_new:Npn \__str_count_spaces_loop:wwwwwwwww #1~#2~#3~#4~#5~#6~#7~#8~#9~ { \if_meaning:w X #9 \use_i_delimit_by_q_stop:nw \fi: \c_nine + \__str_count_spaces_loop:wwwwwwwww } \cs_new_nopar:Npn \str_count:N { \exp_args:No \str_count:n } \cs_new:Npn \str_count:n #1 { \__str_count:n { \str_count_spaces:n {#1} + \exp_after:wN \__str_count_loop:NNNNNNNNN \tl_to_str:n {#1} } } \cs_new:Npn \__str_count_unsafe:n #1 { \__str_count:n { \__str_count_loop:NNNNNNNNN #1 } } \cs_new:Npn \str_count_ignore_spaces:n #1 { \__str_count:n { \exp_after:wN \__str_count_loop:NNNNNNNNN \tl_to_str:n {#1} } } \cs_new:Npn \__str_count:n #1 { \int_eval:n { #1 { X \c_eight } { X \c_seven } { X \c_six } { X \c_five } { X \c_four } { X \c_three } { X \c_two } { X \c_one } { X \c_zero } \q_stop } } \cs_set:Npn \__str_count_loop:NNNNNNNNN #1#2#3#4#5#6#7#8#9 { \if_meaning:w X #9 \exp_after:wN \use_none_delimit_by_q_stop:w \fi: \c_nine + \__str_count_loop:NNNNNNNNN } \cs_new_nopar:Npn \str_head:N { \exp_args:No \str_head:n } \cs_set:Npn \str_head:n #1 { \exp_after:wN \__str_head:w \tl_to_str:n {#1} { { } } ~ \q_stop } \cs_set:Npn \__str_head:w #1 ~ % { \use_i_delimit_by_q_stop:nw #1 { ~ } } \cs_new:Npn \str_head_ignore_spaces:n #1 { \exp_after:wN \use_i_delimit_by_q_stop:nw \tl_to_str:n {#1} { } \q_stop } \cs_new_nopar:Npn \str_tail:N { \exp_args:No \str_tail:n } \cs_set:Npn \str_tail:n #1 { \exp_after:wN \__str_tail_auxi:w \reverse_if:N \if_charcode:w \scan_stop: \tl_to_str:n {#1} X X \q_stop } \cs_set:Npn \__str_tail_auxi:w #1 X #2 \q_stop { \fi: #1 } \cs_new:Npn \str_tail_ignore_spaces:n #1 { \exp_after:wN \__str_tail_auxii:w \tl_to_str:n {#1} \q_mark \q_mark \q_stop } \cs_new:Npn \__str_tail_auxii:w #1 #2 \q_mark #3 \q_stop { #2 } \group_begin: \char_set_lccode:nn { `\* } { `\ } \char_set_lccode:nn { `\A } { `\A } \tl_to_lowercase:n { \group_end: \cs_new:Npn \__str_to_other:n #1 { \exp_after:wN \__str_to_other_loop:w \tl_to_str:n {#1} ~ % A ~ A ~ A ~ A ~ A ~ A ~ A ~ A ~ \q_mark \q_stop } \cs_new:Npn \__str_to_other_loop:w #1 ~ #2 ~ #3 ~ #4 ~ #5 ~ #6 ~ #7 ~ #8 ~ #9 \q_stop { \if_meaning:w A #8 \__str_to_other_end:w \fi: \__str_to_other_loop:w #9 #1 * #2 * #3 * #4 * #5 * #6 * #7 * #8 * \q_stop } \cs_new:Npn \__str_to_other_end:w \fi: #1 \q_mark #2 * A #3 \q_stop { \fi: #2 } } \cs_new:Npn \__str_skip_c_zero:w #1; { \if_int_compare:w #1 > \c_eight \exp_after:wN \__str_skip_loop:wNNNNNNNN \else: \exp_after:wN \__str_skip_end:w \int_use:N \__int_eval:w \fi: #1 ; } \cs_new:Npn \__str_skip_loop:wNNNNNNNN #1; #2#3#4#5#6#7#8#9 { \exp_after:wN \__str_skip_c_zero:w \int_use:N \__int_eval:w #1 - \c_eight ; } \cs_new:Npn \__str_skip_end:w #1 ; { \exp_after:wN \__str_skip_end:NNNNNNNN \if_case:w #1 \exp_stop_f: \or: \or: \or: \or: \or: \or: \or: \or: } \cs_new:Npn \__str_skip_end:NNNNNNNN #1#2#3#4#5#6#7#8 { \fi: \c_zero } \cs_new:Npn \__str_collect_delimit_by_q_stop:w #1; { \__str_collect_loop:wn #1 ; { } } \cs_new:Npn \__str_collect_loop:wn #1 ; { \if_int_compare:w #1 > \c_seven \exp_after:wN \__str_collect_loop:wnNNNNNNN \else: \exp_after:wN \__str_collect_end:wn \fi: #1 ; } \cs_new:Npn \__str_collect_loop:wnNNNNNNN #1; #2 #3#4#5#6#7#8#9 { \exp_after:wN \__str_collect_loop:wn \int_use:N \__int_eval:w #1 - \c_seven ; { #2 #3#4#5#6#7#8#9 } } \cs_new:Npn \__str_collect_end:wn #1 ; { \exp_after:wN \__str_collect_end:nnnnnnnnw \if_case:w \if_int_compare:w #1 > \c_zero #1 \else: 0 \fi: \exp_stop_f: \or: \or: \or: \or: \or: \or: \fi: } \cs_new:Npn \__str_collect_end:nnnnnnnnw #1#2#3#4#5#6#7#8 #9 \q_stop { #1#2#3#4#5#6#7#8 } \cs_new_nopar:Npn \str_item:Nn { \exp_args:No \str_item:nn } \cs_new:Npn \str_item:nn #1#2 { \exp_args:Nf \tl_to_str:n { \exp_args:Nf \__str_item_unsafe:nn { \__str_to_other:n {#1} } {#2} } } \cs_new:Npn \str_item_ignore_spaces:nn #1 { \exp_args:No \__str_item_unsafe:nn { \tl_to_str:n {#1} } } \cs_new:Npn \__str_item_unsafe:nn #1#2 { \exp_after:wN \__str_item:ww \int_use:N \__int_eval:w #2 \exp_after:wN ; \__int_value:w \__str_count_unsafe:n {#1} ; #1 \q_stop } \cs_new:Npn \__str_item:ww #1; #2; { \int_compare:nNnTF {#1} < \c_zero { \int_compare:nNnTF {#1} < {-#2} { \use_none_delimit_by_q_stop:w } { \exp_after:wN \use_i_delimit_by_q_stop:nw \tex_romannumeral:D \exp_after:wN \__str_skip_c_zero:w \int_use:N \__int_eval:w #1 + #2 ; } } { \int_compare:nNnTF {#1} > {#2} { \use_none_delimit_by_q_stop:w } { \exp_after:wN \use_i_delimit_by_q_stop:nw \tex_romannumeral:D \__str_skip_c_zero:w #1 ; { } } } } \cs_new:Npn \__str_range_normalize:nn #1#2 { \int_eval:n { \if_int_compare:w #1 < \c_zero \if_int_compare:w #1 < -#2 \exp_stop_f: \c_zero \else: #1 + #2 + \c_one \fi: \else: \if_int_compare:w #1 < #2 \exp_stop_f: #1 \else: #2 \fi: \fi: } } \cs_new_nopar:Npn \str_range:Nnn { \exp_args:No \str_range:nnn } \cs_new:Npn \str_range:nnn #1#2#3 { \exp_args:Nf \tl_to_str:n { \exp_args:Nf \__str_range_unsafe:nnn { \__str_to_other:n {#1} } {#2} {#3} } } \cs_new:Npn \str_range_ignore_spaces:nnn #1 { \exp_args:No \__str_range_unsafe:nnn { \tl_to_str:n {#1} } } \cs_new:Npn \__str_range_unsafe:nnn #1#2#3 { \exp_after:wN \__str_range:www \__int_value:w \__str_count_unsafe:n {#1} \exp_after:wN ; \int_use:N \__int_eval:w #2 - \c_one \exp_after:wN ; \int_use:N \__int_eval:w #3 ; #1 \q_stop } \cs_new:Npn \__str_range:www #1; #2; #3; { \exp_args:Nf \__str_range:nnw { \__str_range_normalize:nn {#2} {#1} } { \__str_range_normalize:nn {#3} {#1} } } \cs_new:Npn \__str_range:nnw #1#2 { \exp_after:wN \__str_collect_delimit_by_q_stop:w \int_use:N \__int_eval:w #2 - #1 \exp_after:wN ; \tex_romannumeral:D \__str_skip_c_zero:w #1 ; } \prg_new_conditional:Npnn \str_if_eq:NN #1#2 { p , TF , T , F } { \if_int_compare:w \__str_if_eq_x:nn { \tl_to_str:N #1 } { \tl_to_str:N #2 } = \c_zero \prg_return_true: \else: \prg_return_false: \fi: } \cs_new_eq:NN \str_show:n \tl_show:n \cs_new_eq:NN \str_show:N \tl_show:N \cs_generate_variant:Nn \str_show:N { c } \cs_new:Npn \str_substr:Nnn #1 { \__str_substr:nnn { \str_range:Nnn #1 } } \cs_new:Npn \str_substr:nnn #1 { \__str_substr:nnn { \str_range:nnn {#1} } } \cs_new:Npn \str_substr_ignore_spaces:nnn #1 { \__str_substr:nnn { \str_range_ignore_spaces:nnn {#1} } } \cs_new:Npn \__str_substr:nnn #1#2#3 { \tl_if_empty:nTF {#2} { \tl_if_empty:nTF {#3} { #1 { 1} { -1 } } { #1 { 1} {#3} } } { \tl_if_empty:nTF {#3} { #1 {#2} { -1 } } { #1 {#2} {#3} } } } \cs_new_eq:NN \c_lbrace_str \c_left_brace_str \cs_new_eq:NN \c_rbrace_str \c_right_brace_str %% %% %% End of file `l3str.sty'.