diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3str.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3str.dtx | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3str.dtx b/Master/texmf-dist/source/latex/l3kernel/l3str.dtx index aecd6d3c0d1..6b6acc03364 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3str.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3str.dtx @@ -43,7 +43,7 @@ % }^^A % } % -% \date{Released 2021-05-11} +% \date{Released 2021-05-25} % % \maketitle % @@ -401,6 +401,34 @@ % not be used within this string. % \end{function} % +% \begin{function}[EXP, pTF, added = 2021-05-17]{\str_compare:nNn, \str_compare:eNe} +% \begin{syntax} +% \cs{str_compare_p:nNn} \Arg{tl_1} \meta{relation} \Arg{tl_2} +% \cs{str_compare:nNnTF} \Arg{tl_1} \meta{relation} \Arg{tl_2} \Arg{true code} \Arg{false code} +% \end{syntax} +% Compares the two \meta{token lists} on a character by character +% basis (namely after converting them to strings) in a lexicographic +% order according to the character codes of the characters. The +% \meta{relation} can be |<|, |=|, or~|>| and the test is +% \texttt{true} under the following conditions: +% \begin{itemize} +% \item for |<|, if the first string is earlier than the second in lexicographic order; +% \item for |=|, if the two strings have exactly the same characters; +% \item for |>|, if the first string is later than the second in lexicographic order. +% \end{itemize} +% Thus for example the following is logically \texttt{true}: +% \begin{verbatim} +% \str_compare_p:nNn { ab } < { abc } +% \end{verbatim} +% \begin{texnote} +% This is a wrapper around the \TeX{} primitive +% \cs[index=pdfstrcmp]{(pdf)strcmp}. It is meant for programming +% and not for sorting textual contents, as it simply considers +% character codes and not more elaborate considerations of grapheme +% clusters, locale, etc. +% \end{texnote} +% \end{function} +% % \section{Mapping over strings} % % All mappings are done at the current group level, \emph{i.e.}~any @@ -1109,6 +1137,25 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}[pTF, EXP]{\str_compare:nNn, \str_compare:eNe} +% Simply rely on \cs{@@_if_eq:nn}, which expands to |-1|, |0| +% or~|1|. The |ee| version is created directly because it is more efficient. +% \begin{macrocode} +\prg_new_conditional:Npnn \str_compare:nNn #1#2#3 { p , T , F , TF } + { + \if_int_compare:w + \@@_if_eq:nn { \exp_not:n {#1} } { \exp_not:n {#3} } + #2 \c_zero_int + \prg_return_true: \else: \prg_return_false: \fi: + } +\prg_new_conditional:Npnn \str_compare:eNe #1#2#3 { p , T , F , TF } + { + \if_int_compare:w \@@_if_eq:nn {#1} {#3} #2 \c_zero_int + \prg_return_true: \else: \prg_return_false: \fi: + } +% \end{macrocode} +% \end{macro} +% % \begin{macro}[pTF, EXP] % { % \str_if_eq:nn, \str_if_eq:Vn, \str_if_eq:on, \str_if_eq:nV, @@ -1124,14 +1171,14 @@ { \if_int_compare:w \@@_if_eq:nn { \exp_not:n {#1} } { \exp_not:n {#2} } - = 0 \exp_stop_f: + = \c_zero_int \prg_return_true: \else: \prg_return_false: \fi: } \prg_generate_conditional_variant:Nnn \str_if_eq:nn { V , v , o , nV , no , VV , nv } { p , T , F , TF } \prg_new_conditional:Npnn \str_if_eq:ee #1#2 { p , T , F , TF } { - \if_int_compare:w \@@_if_eq:nn {#1} {#2} = 0 \exp_stop_f: + \if_int_compare:w \@@_if_eq:nn {#1} {#2} = \c_zero_int \prg_return_true: \else: \prg_return_false: \fi: } % \end{macrocode} @@ -1146,7 +1193,7 @@ { \if_int_compare:w \@@_if_eq:nn { \tl_to_str:N #1 } { \tl_to_str:N #2 } - = 0 \exp_stop_f: \prg_return_true: \else: \prg_return_false: \fi: + = \c_zero_int \prg_return_true: \else: \prg_return_false: \fi: } \prg_generate_conditional_variant:Nnn \str_if_eq:NN { c , Nc , cc } { T , F , TF , p } @@ -1620,7 +1667,7 @@ { \int_eval:n { - \if_int_compare:w #1 < 0 \exp_stop_f: + \if_int_compare:w #1 < \c_zero_int \if_int_compare:w #1 < -#2 \exp_stop_f: 0 \else: @@ -1673,7 +1720,7 @@ \cs_new:Npn \@@_collect_end:wn #1 ; { \exp_after:wN \@@_collect_end:nnnnnnnnw - \if_case:w \if_int_compare:w #1 > 0 \exp_stop_f: + \if_case:w \if_int_compare:w #1 > \c_zero_int #1 \else: 0 \fi: \exp_stop_f: \or: \or: \or: \or: \or: \or: \fi: } |