diff options
author | Karl Berry <karl@freefriends.org> | 2009-03-14 22:24:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-03-14 22:24:54 +0000 |
commit | 522c6836e3d77dffdd3ed6cebaef5d4bf24153bd (patch) | |
tree | 91124b9800b8147357eaea1aafca55bf30d30a58 /Master/texmf-dist/tex/generic | |
parent | 08d1f478c9d52e98ea8b2c89882f7f6db1d448d0 (diff) |
xstring 1,5b (14mar09)
git-svn-id: svn://tug.org/texlive/trunk@12389 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic')
-rw-r--r-- | Master/texmf-dist/tex/generic/xstring/xstring.tex | 281 |
1 files changed, 184 insertions, 97 deletions
diff --git a/Master/texmf-dist/tex/generic/xstring/xstring.tex b/Master/texmf-dist/tex/generic/xstring/xstring.tex index 48320845680..af1b9ce4322 100644 --- a/Master/texmf-dist/tex/generic/xstring/xstring.tex +++ b/Master/texmf-dist/tex/generic/xstring/xstring.tex @@ -3,7 +3,7 @@ % | | % | xstring v1.5a | % | | -% | February 9 2009 | +% | March 13 2009 | % | | % |__________________________________________________| % @@ -35,19 +35,21 @@ % % The Current Maintainer of this work is Christian Tellechea % ------------------------------------------------------------------- -\def\xstringversion {1.5a} -\def\xstringdate {2009/02/09} -\def\xstringfrenchdate {9 f\'evrier 2009} -\def\xstringenglishdate {February $9^{\mathrm{th}}$ 2009} +\def\xstringversion {1.5b} +\def\xstringdate {2009/03/13} +\def\xstringfrenchdate {13 mars 2009} +\def\xstringenglishdate {March $13^{\mathrm{th}}$ 2009} \edef\CurrentAtCatcode {\the\catcode`\@} \catcode`\@=11 \newwrite\@xs@message% canal pour les messages \newcount\integerpart\newcount\decimalpart% compteurs utilis\'es par xstring +\newif\if@xs@empty \expandafter\ifx\csname @latexerr\endcsname\relax% on n'utilise pas LaTeX ? \immediate\write\m@ne{Package: xstring \xstringdate\space\space v\xstringversion\space\space String manipulations (C Tellechea)}% \long\def\@firstoftwo#1#2{#1} \long\def\@secondoftwo#1#2{#2} + \long\def\@gobble#1{} \long\def\@ifnextchar#1#2#3{% \let\reserved@d=#1% \def\reserved@a{#2}% @@ -71,6 +73,9 @@ \def\@empty{} \fi% fin des d\'efinitions LaTeX +\def\@xs@testempty#1{% + \expandafter\ifx\expandafter\@empty\detokenize{#1}\@empty\@xs@emptytrue\else\@xs@emptyfalse\fi} + % Ouvre un groupe o\`u les catcodes sont \`a 12 et \`a 10 pour les espaces % ensuite, appelle \@xs@ReadVerb qui lit un argument entre d\'elimiteurs verb \def\@xs@MakeVerb{% lit 1 argument et le transforme en verb @@ -82,7 +87,8 @@ % D\'efinit \@xs@ReadVerb qui lit un argument entre d\'elimiteurs verb \def\setverbdelim#1{% d\'efinit quel est le d\'elimiteur de verb - \expandafter\ifx\expandafter\@empty\detokenize\expandafter{\@xs@gobblefirstchar#1}\@empty + \expandafter\@xs@testempty\expandafter{\@gobble#1}% + \if@xs@empty \else \begingroup \newlinechar`\^^J% @@ -117,10 +123,12 @@ % Macro tr\`es simple qui assigne ou affiche le r\'esultat, selon la pr\'esence % ou non de #2 qui est l'argument optionnel venant en derni\`ere position des macros \def\@xs@ReturnResult#1#2{% - \expandafter\ifx\expandafter\@empty\detokenize{#2}\@empty - #1% + \def\@xs@argument@A{#1}% + \@xs@testempty{#2}% + \if@xs@empty + \@xs@argument@A \else - \def#2{#1}% + \let#2\@xs@argument@A \fi} % Pas d'expansion des arguments @@ -142,42 +150,61 @@ \def\saveexpandmode{\let\@xs@saved@def\@xs@defarg\let\@xs@saved@expand\@xs@expand} \def\restoreexpandmode{\let\@xs@defarg\@xs@saved@def\let\@xs@expand\@xs@saved@expand} +% Macro interne renvoyant #2 si son argument commence par une accolade ouvrante "{" +% et #3 sinon (Ulrich Diez sur comp.text.tex) +\def\@xs@ifbeginwithbrace#1{% + \csname @% + \expandafter\@gobble\string{% ne sert à rien si ce n'est \'equilibrer les accolades dans la d\'efinition + \expandafter\@gobble\expandafter{\expandafter{\string#1}% + \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\@firstoftwo + \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\@gobble + \expandafter\expandafter\expandafter\@gobble + \expandafter\expandafter\expandafter{\expandafter\string\expandafter}\string}% + \expandafter\@gobble\string}% + \@secondoftwo{first}{second}oftwo% + \endcsname} + % Cette macro interne prend la 1ere unit\'e syntaxique de #1 et assigne le r\'esultat \`a #2 \def\@xs@returnfirstsyntaxunit#1#2{% - \def\@xs@returnfirstsyntaxunit@i##1##2\@xs@nil{% + \def\@xs@groupfound{\expandafter\def\expandafter#2\expandafter{\expandafter{#2}}\@xs@gobbleall}% on met #2 dans des accolades et on finit + \def\@xs@assignfirsttok##1##2\@xs@nil{\let\@xs@toks0\def#2{##1}}% + \def\@xs@testfirsttok{% + \let\@xs@next\@xs@assignfirsttok \ifx\@xs@toks\bgroup - \begingroup - \escapechar48\relax% 0 est le caract\`ere d'\'echappement - \expandafter\expandafter\expandafter\ifx\expandafter\@xs@returnfirstsyntaxunit@ii\detokenize{#1}\@xs@nil0% - \def\@xs@reserved@A{\def#2{##1}\let\@xs@toks0}% si commence par 0, ##1 est un «\bgroup» - \else - \def\@xs@reserved@A{\def#2{{##1}}}% si ne commence pas par 0, ##1 est un groupe {...} - \fi - \expandafter\endgroup - \@xs@reserved@A - \else - \def#2{##1}% - \fi}% - \let\@xs@toks0\relax - \expandafter\ifx\expandafter\@empty\@xs@beforespace#1 \@xs@nil\@empty - \ifx\@empty#1\@empty\let#2\@empty\else\def#2{ }\fi + \expandafter\@xs@ifbeginwithbrace\expandafter{\@xs@argument}{\def\@xs@next{\afterassignment\@xs@groupfound\def#2}}{}% + \fi + \@xs@next}% + \def\@xs@argument{#1}% + \expandafter\@xs@testempty\expandafter{\@xs@beforespace#1 \@xs@nil}% + \if@xs@empty + \def\@xs@next{\expandafter\ifx\expandafter\@empty\detokenize\expandafter{\@xs@argument}\@empty\let#2\@empty\else\def#2{ }\fi}% \else - \futurelet\@xs@toks\@xs@returnfirstsyntaxunit@i#1\@xs@nil - \fi} + \def\@xs@next{\expandafter\futurelet\expandafter\@xs@toks\expandafter\@xs@testfirsttok\@xs@argument\@xs@nil}% + \fi + \@xs@next} % Cette macro interne enl\`eve la 1ere unit\'e syntaxique de #1 et assigne le r\'esultat \`a #2 \def\@xs@removefirstsyntaxunit#1#2{% - \expandafter\ifx\expandafter\@empty\@xs@beforespace#1 \@xs@nil\@empty - \ifx\@empty#1\@empty\def#2{}\else\expandafter\def\expandafter#2\expandafter{\@xs@behindspace#1\@xs@nil}\fi + \expandafter\@xs@testempty\expandafter{\@xs@beforespace#1 \@xs@nil}% + \def\@xs@argument{#1}% + \if@xs@empty + \expandafter\@xs@testempty\expandafter{\@xs@argument}% + \if@xs@empty + \let#2\@empty + \else + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter#2% + \expandafter\expandafter\expandafter{\expandafter\@xs@behindspace\@xs@argument\@xs@nil}% + \fi \else - \expandafter\def\expandafter#2\expandafter{\@xs@gobblefirstchar#1}% + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter#2% + \expandafter\expandafter\expandafter{\expandafter\@gobble\@xs@argument}% \fi} % Macros \`a arguments d\'elimit\'es pour les macros ci dessus \def\@xs@beforespace#1 #2\@xs@nil{#1} \def\@xs@behindspace#1 #2\@xs@nil{#2} -\def\@xs@gobblefirstchar#1{} \def\@xs@returnfirstsyntaxunit@ii#1#2\@xs@nil{#1} +\def\@xs@gobbleall#1\@xs@nil{} % Cette macro interne est utilis\'ee dans les macros \'etoil\'ees pour : % 1) d\'evelopper l'argument selon qu'on a choisit \fullexpandarg @@ -191,37 +218,40 @@ \def\@xs@expand@and@assign#1#2{\@xs@def#1{#2}}% on d\'eveloppe #2 selon \fullexpandarg ou \normalexpandarg -\def\@xs@expand@and@addtomacro#1#2{\edef#1{\unexpanded\expandafter{#1}#2}} +\def\@xs@edefaddtomacro#1#2{\edef#1{\unexpanded\expandafter{#1}#2}} +\def\@xs@addtomacro#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} + \def\@xs@argstring{0########1########2########3########4########5########6########7########8########9} -% \@xs@DefArg{3} met dans la sc \@xs@myarg le texte "####1####2####3" +% \@xs@DefArg{3} met dans la sc \@xs@myarg les tokens "####1####2####3" \def\@xs@DefArg#1{\def\@xs@defarg0##1#1##2\@xs@nil{\def\@xs@myarg{##1#1}}\expandafter\@xs@defarg\@xs@argstring\@xs@nil} -% \@xs@DefArg@{3} met dans la sc \@xs@myarg le texte "[####1]####2####3####4" +% \@xs@DefArg@{3} met dans la sc \@xs@myarg les tokens "[####1]####2####3####4" \def\@xs@DefArg@#1{\expandafter\@xs@defarg@\expandafter{\number\numexpr#1+1}} \def\@xs@defarg@#1{\def\@xs@defarg0##11##2#1##3\@xs@nil{\def\@xs@myarg{[##11]##2#1}}\expandafter\@xs@defarg\@xs@argstring\@xs@nil} -% \@xs@OneArg{3} met dans la sc \@xs@myarg le texte "####3" +% \@xs@OneArg{3} met dans la sc \@xs@myarg les tokens "####3" \def\@xs@OneArg#1{\expandafter\@xs@onearg\expandafter{\number\numexpr#1-1}{#1}} \def\@xs@onearg#1#2{\def\@xs@defarg##1#1##2#2##3\@xs@nil{\def\@xs@myarg{##2#2}}\expandafter\@xs@defarg\@xs@argstring\@xs@nil} % #1 : num\'ero du 1er argument; #2 : nombre de lignes; #3 argument optionnel; #4 : dernier num\'ero de l'argument devant être d\'etokenis\'e si \'etoile \def\@xs@BuildLines#1#2#3#4{% - \def\@xs@newlines{}% - \def\@xs@newargs{}% + \let\@xs@newlines\@empty + \let\@xs@newargs\@empty \def\@xs@buildlines##1{% \expandafter\@xs@OneArg\expandafter{\number\numexpr##1+#1-1}% - \def\@xs@reserved@B{\noexpand\@xs@expand\csname @xs@arg@\romannumeral\numexpr##1\endcsname}% + \edef\@xs@reserved@B{\noexpand\@xs@expand\csname @xs@arg@\romannumeral\numexpr##1\endcsname}% \ifnum##1=\@ne% si c'est le premier argument - \ifx\@empty#3\@empty - \@xs@expand@and@addtomacro\@xs@newargs{{\@xs@reserved@B}}% + \@xs@testempty{#3}% + \if@xs@empty + \expandafter\@xs@addtomacro\expandafter\@xs@newargs\expandafter{\expandafter{\@xs@reserved@B}}% \edef\@xs@reserved@B{\ifnum##1>#4 @xs@def\else @xs@assign\fi}% \else% et s'il y a un argument optionnel alors, on met des crochets - \@xs@expand@and@addtomacro\@xs@newargs{[\@xs@reserved@B]}% + \expandafter\@xs@addtomacro\expandafter\@xs@newargs\expandafter{\expandafter[\@xs@reserved@B]}% \def\@xs@reserved@B{@xs@def}% ne pas d\'etok\'eniser l'argument optionnel grace au \@xs@def \fi \else - \@xs@expand@and@addtomacro\@xs@newargs{{\@xs@reserved@B}}% + \expandafter\@xs@addtomacro\expandafter\@xs@newargs\expandafter{\expandafter{\@xs@reserved@B}}% \edef\@xs@reserved@B{\ifnum##1>#4 @xs@def\else @xs@assign\fi}% \fi - \@xs@expand@and@addtomacro\@xs@newlines{\csname\@xs@reserved@B\endcsname\csname @xs@arg@\romannumeral\numexpr##1\endcsname{\@xs@myarg}}% + \edef\@xs@newlines{\unexpanded\expandafter{\@xs@newlines}\expandafter\noexpand\csname\@xs@reserved@B\endcsname\expandafter\noexpand\csname @xs@arg@\romannumeral\numexpr##1\endcsname{\@xs@myarg}}% \ifnum##1<#2\relax \def\@xs@next{\expandafter\@xs@buildlines\expandafter{\number\numexpr##1+1}}% \expandafter\@xs@next @@ -229,14 +259,14 @@ \@xs@buildlines\@ne} \def\@xs@newmacro{\@ifstar{\let\@xs@reserved@D\@empty\@xs@newmacro@}{\let\@xs@reserved@D\relax\@xs@newmacro@0}} -% #1 : dernier num\'ero de l'argument devant être d\'etokenis\'e si \'etoile +% #1 : dernier num\'ero de l'argument devant être d\'etokenis\'e % #2 : nom de la macro publique % #3 : argument optionnel (vide si pas d'arg optionnel) % #4 : nombre d'arguments obligatoires % #5 : utilisation de testopt (1 si oui, 0 si non) % #6 : code de la macro \def\@xs@newmacro@#1#2#3#4#5{% - \edef\@xs@reserved@A{@xs@\expandafter\@xs@gobblefirstchar\string#2}% + \edef\@xs@reserved@A{@xs@\expandafter\@gobble\string#2}% \edef\@xs@reserved@C{\expandafter\noexpand\csname\@xs@reserved@A @\ifx\@empty#3\@empty @\fi\endcsname}% \edef\@xs@reserved@B{% \ifx\@empty\@xs@reserved@D @@ -266,9 +296,9 @@ \edef\@xs@reserved@B{\def\expandafter\noexpand\csname\@xs@reserved@A @@\endcsname\@xs@myarg}% \edef\@xs@reserved@C{\unexpanded\expandafter{\@xs@newlines}\edef\noexpand\@xs@call}% \edef\@xs@reserved@D{\noexpand\noexpand\expandafter\noexpand\csname\@xs@reserved@A\endcsname\unexpanded\expandafter{\@xs@newargs}}% - \ifnum#5=\@ne\edef\@xs@reserved@D{\noexpand\noexpand\noexpand\@testopt{\unexpanded\expandafter{\@xs@reserved@D}}\unexpanded{{}}}\fi - \@xs@expand@and@addtomacro\@xs@reserved@C{{\unexpanded\expandafter{\@xs@reserved@D}}\noexpand\@xs@call}% - \@xs@expand@and@addtomacro\@xs@reserved@B{{\unexpanded\expandafter{\@xs@reserved@C}}}% + \ifnum#5=\@ne\edef\@xs@reserved@D{\noexpand\noexpand\noexpand\@testopt{\unexpanded\expandafter{\@xs@reserved@D}}{}}\fi + \@xs@edefaddtomacro\@xs@reserved@C{{\unexpanded\expandafter{\@xs@reserved@D}}\noexpand\@xs@call}% + \@xs@edefaddtomacro\@xs@reserved@B{{\unexpanded\expandafter{\@xs@reserved@C}}}% % Que fait \@xs@reserved@B ? Il d\'efinit par exemple pour 3 arguments obligatoires et 1 facultatif : % \def\@xs@NOM@@[##2]##3##4##5{% % \@xs@def\@xs@arg@i{##2}\@xs@assign\@xs@arg@ii{##3}\@xs@assign\@xs@arg@iii{##4}\@xs@asign\@xs@arg@iv{##5}% @@ -287,7 +317,8 @@ % \@xs@atbegingroup (un groupe vient d'être ouvert) % \@xs@atnextsyntaxunit (la future US n'est pas un groupe) \def\@xs@read@reserved@C{% - \ifx\@xs@reserved@C\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty \ifnum\@xs@nestlevel=\z@ \let\@xs@next\relax \else @@ -318,7 +349,8 @@ % \@xs@atendofgroup (un groupe se finit, appel r\'ecursif) % \@xs@atoccurfound (une occurrence a \'et\'e trouv\'ee) \def\@xs@read@reserved@D{% - \ifx\@xs@reserved@D\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@D}% + \if@xs@empty \ifnum\@xs@nestlevel=\z@ \let\@xs@next\relax \else @@ -353,18 +385,21 @@ \let\@xs@nestlevel\z@ \@xs@StrRemoveBraces@i \expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@B}{#2}} + \def\@xs@StrRemoveBraces@i{% - \let\@xs@next\@xs@StrRemoveBraces@i - \ifx\@xs@reserved@C\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty \ifnum\@xs@nestlevel=\z@ \let\@xs@next\relax \else \expandafter\endgroup \expandafter\@xs@addtomacro\expandafter\@xs@reserved@B\expandafter{\@xs@reserved@B}% + \let\@xs@next\@xs@StrRemoveBraces@i \fi \else \expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@reserved@C}\@xs@reserved@A \expandafter\@xs@removefirstsyntaxunit\expandafter{\@xs@reserved@C}\@xs@reserved@C + \let\@xs@next\@xs@StrRemoveBraces@i \ifx\bgroup\@xs@toks \ifx\@xs@exploregroups\relax% on explore les groupes ? \begingroup @@ -405,40 +440,51 @@ \let\@xs@next\@xs@read@reserved@D \fi}% \@xs@read@reserved@D + \def\@xs@argument@A{#2}% \ifnum\decimalpart=#3% occurrence trouv\'ee ? \let\@xs@reserved@E\@xs@reserved@D - \expandafter\def\expandafter\@xs@reserved@D\expandafter{\@xs@reserved@C#2}% + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\@xs@reserved@D\expandafter\expandafter\expandafter{\expandafter\@xs@reserved@C\@xs@argument@A}% \else \let\@xs@reserved@C\@empty\let\@xs@reserved@E\@empty\let\groupID\@empty \fi} \@xs@newmacro*3\IfSubStr{1}{2}{0}{% - \@xs@cutafteroccur{#2}{#3}{#1}% - \ifx\@xs@reserved@D\@empty + \def\@xs@argument@A{#2}\def\@xs@argument@B{#3}% + \expandafter\expandafter\expandafter\@xs@cutafteroccur + \expandafter\expandafter\expandafter{\expandafter\@xs@argument@A\expandafter}\expandafter{\@xs@argument@B}{#1}% + \expandafter\@xs@testempty\expandafter{\@xs@reserved@D}% + \if@xs@empty \expandafter\@secondoftwo \else \expandafter\@firstoftwo \fi} \@xs@newmacro*2\IfBeginWith{}{2}{0}{% - \ifx\@empty#2\@empty + \def\@xs@argument@A{#1}\def\@xs@argument@B{#2}% + \expandafter\@xs@testempty\expandafter{\@xs@argument@B}% + \if@xs@empty \let\@xs@next\@secondoftwo \else - \def\@xs@next{\@xs@IfBeginWith@i{#1}{#2}}% + \def\@xs@next{\expandafter\expandafter\expandafter\@xs@IfBeginWith@i + \expandafter\expandafter\expandafter{\expandafter\@xs@argument@A\expandafter}\expandafter{\@xs@argument@B}}% \fi \@xs@next} + \def\@xs@IfBeginWith@i#1#2{% - \ifx\@empty#2\@empty% #2 est vide, tous les tests sont pass\'es avec succ\`es : on renvoie #3 + \def\@xs@argument@A{#1}\def\@xs@argument@B{#2}% + \expandafter\@xs@testempty\expandafter{\@xs@argument@B}% + \if@xs@empty% #2 est vide, tous les tests sont pass\'es avec succ\`es : on renvoie #3 \let\@xs@next\@firstoftwo \else - \ifx\@empty#1\@empty + \expandafter\@xs@testempty\expandafter{\@xs@argument@A}%\@xs@testempty{#1}% + \if@xs@empty \let\@xs@next\@secondoftwo% #1 est vide, c'est que #2 est + long que #1 : on renvoie #4 \else - \@xs@returnfirstsyntaxunit{#1}\@xs@reserved@A - \@xs@returnfirstsyntaxunit{#2}\@xs@reserved@B + \expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@argument@A}\@xs@reserved@A + \expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@argument@B}\@xs@reserved@B \ifx\@xs@reserved@A\@xs@reserved@B% il y a \'egalit\'e... - \@xs@removefirstsyntaxunit{#1}\@xs@reserved@A% on enl\`eve les 1ere unit\'es syntaxiques - \@xs@removefirstsyntaxunit{#2}\@xs@reserved@B + \expandafter\@xs@removefirstsyntaxunit\expandafter{\@xs@argument@A}\@xs@reserved@A% on enl\`eve les 1ere unit\'es syntaxiques + \expandafter\@xs@removefirstsyntaxunit\expandafter{\@xs@argument@B}\@xs@reserved@B \def\@xs@next{% et on recommence avec ces arguments racourcis d'1 unit\'e syntaxique \expandafter\expandafter\expandafter\@xs@IfBeginWith@i \expandafter\expandafter\expandafter{\expandafter\@xs@reserved@A\expandafter}\expandafter{\@xs@reserved@B}}% @@ -447,17 +493,22 @@ \fi \fi \fi - \@xs@next} + \@xs@next} \@xs@newmacro*2\IfEndWith{}{2}{0}{% - \ifx\@empty#2\@empty + \def\@xs@argument@A{#1}\def\@xs@argument@B{#2}% + \@xs@testempty{#2}% + \if@xs@empty \let\@xs@reserved@A\@secondoftwo \else - \@xs@StrCount{#1}{#2}[\@xs@reserved@A]% + \expandafter\expandafter\expandafter\@xs@StrCount + \expandafter\expandafter\expandafter{\expandafter\@xs@argument@A\expandafter}\expandafter + {\@xs@argument@B}[\@xs@reserved@A]% \ifnum\@xs@reserved@A=\z@ \let\@xs@reserved@A\@secondoftwo \else - \ifx\@xs@reserved@C\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty \let\@xs@reserved@A\@firstoftwo \else \let\@xs@reserved@A\@secondoftwo @@ -468,11 +519,20 @@ \@xs@newmacro*4\IfSubStrBefore{1,1}{3}{0}{\@xs@IfSubStrBefore@i[#1]{#2}{#3}{#4}} \def\@xs@IfSubStrBefore@i[#1,#2]#3#4#5{% - \ifx\@xs@exploregroups\relax\let\@xs@reserved@C\@empty\def\@xs@reserved@A{#3}\@xs@StrRemoveBraces@i\else\def\@xs@reserved@C{#3}\fi - \expandafter\@xs@cutafteroccur\expandafter{\@xs@reserved@C}{#5}{#2}% - \expandafter\@xs@cutafteroccur\expandafter{\@xs@reserved@C}{#4}{#1}% + \def\@xs@reserved@C{#3}% + \ifx\@xs@exploregroups\relax% si on explore les groupes + \let\@xs@reserved@B\@empty + \let\@xs@nestlevel\z@ + \@xs@StrRemoveBraces@i% on retire les accolades + \let\@xs@reserved@C\@xs@reserved@B + \fi + \def\@xs@reserved@A{#5}% + \expandafter\expandafter\expandafter\@xs@cutafteroccur\expandafter\expandafter\expandafter{\expandafter\@xs@reserved@C\expandafter}\expandafter{\@xs@reserved@A}{#2}% + \def\@xs@reserved@A{#4}% + \expandafter\expandafter\expandafter\@xs@cutafteroccur\expandafter\expandafter\expandafter{\expandafter\@xs@reserved@C\expandafter}\expandafter{\@xs@reserved@A}{#1}% \let\groupID\@empty - \ifx\@xs@reserved@C\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty \expandafter\@secondoftwo \else \expandafter\@firstoftwo @@ -482,14 +542,17 @@ \def\@xs@IfSubStrBehind@i[#1,#2]#3#4#5{\@xs@IfSubStrBefore@i[#2,#1]{#3}{#5}{#4}} \def\@xs@formatnumber#1#2{% - \ifx\@empty#1\@empty + \def\@xs@argument@A{#1}% + \@xs@testempty{#1}% + \if@xs@empty \def#2{0X}% si vide, renvoie 0X \else \@xs@returnfirstsyntaxunit{#1}\@xs@reserved@A \def\@xs@reserved@B{+}% \ifx\@xs@reserved@A\@xs@reserved@B - \@xs@removefirstsyntaxunit{#1}\@xs@reserved@C - \ifx\@empty\@xs@reserved@C + \expandafter\@xs@removefirstsyntaxunit\expandafter{\@xs@argument@A}\@xs@reserved@C + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty \def#2{+0X}% \else \expandafter\def\expandafter#2\expandafter{\expandafter+\expandafter0\@xs@reserved@C}% @@ -497,14 +560,15 @@ \else \def\@xs@reserved@B{-}% \ifx\@xs@reserved@A\@xs@reserved@B - \@xs@removefirstsyntaxunit{#1}\@xs@reserved@A - \ifx\@empty\@xs@reserved@A + \expandafter\@xs@removefirstsyntaxunit\expandafter{\@xs@argument@A}\@xs@reserved@A + \expandafter\@xs@testempty\expandafter{\@xs@reserved@A}% + \if@xs@empty \def#2{-0X}% \else \expandafter\def\expandafter#2\expandafter{\expandafter-\expandafter0\@xs@reserved@A}% \fi \else - \def#2{0#1}% + \expandafter\def\expandafter#2\expandafter{\expandafter0\@xs@argument@A}% \fi \fi \fi} @@ -555,13 +619,14 @@ \ifx\@xs@reserved@A\@xs@reserved@B \let\@xs@reserved@A\@firstoftwo% \'egalit\'e parfaite des 2 chaines \else - \@xs@reserved@D{#1}{#2}% + \expandafter\expandafter\expandafter\@xs@reserved@D\expandafter\expandafter\expandafter{\expandafter\@xs@reserved@A\expandafter}\expandafter{\@xs@reserved@B}% \fi \@xs@reserved@A} \@xs@newmacro*2\IfStrEq{}{2}{0}{% teste si les deux chaines sont \'egales \let\@xs@reserved@D\@xs@IfStrEqFalse@i \@xs@TestEqual{#1}{#2}} + \@xs@newmacro*2\IfEq{}{2}{0}{% teste si les 2 arguments (chaine ou nombre) sont \'egaux \let\@xs@reserved@D\@xs@IfStrEqFalse@ii \@xs@TestEqual{#1}{#2}} @@ -576,7 +641,8 @@ \def\@xs@testcase##1##2##3\@xs@nil{% lit les 2 premieres unit\'es syntaxiques dans ##1 et ##2. Les autres dans ##3 \@xs@reserved@E{#1}{##1}% {##2}% le test est positif, on ex\'ecute le code correspondant - {\ifx\@empty##3\@empty% le test est n\'egatif + {\@xs@testempty{##3}% + \if@xs@empty% le test est n\'egatif \def\@xs@next{#3}% s'il n'y a plus de cas, on ex\'ecute le code <autres cas> \else \def\@xs@next{\@xs@testcase##3\@xs@nil}% sinon, on recommence avec ce qui reste @@ -607,8 +673,6 @@ \expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@E}{#6}% \let\groupID\@empty} -\def\@xs@addtomacro#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} - \def\exploregroups{\let\@xs@exploregroups\relax} \def\noexploregroups{\def\@xs@exploregroups{\let\@xs@toks0\relax}} \def\saveexploremode{\let\@xs@saveexploremode\@xs@exploregroups} @@ -618,6 +682,7 @@ % par la chaine #4 dans la chaine #2 \@xs@newmacro\StrSubstitute{0}{3}{1}{% \def\@xs@reserved@D{#2}\let\@xs@reserved@C\@empty\def\@xs@reserved@E{#3}% + \def\@xs@argument@C{#3}\def\@xs@argument@D{#4}% \decimalpart\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@ \def\@xs@atendofgroup{% \expandafter\endgroup @@ -625,18 +690,19 @@ \@xs@read@reserved@D}% \def\@xs@atoccurfound{% \ifnum#1<\@ne - \def\@xs@reserved@A{#4}% + \let\@xs@reserved@A\@xs@argument@D \else \ifnum\decimalpart>#1 - \def\@xs@reserved@A{#3}% + \let\@xs@reserved@A\@xs@argument@C \else - \def\@xs@reserved@A{#4}% + \let\@xs@reserved@A\@xs@argument@D \fi \fi \expandafter\@xs@addtomacro\expandafter\@xs@reserved@C\expandafter{\@xs@reserved@A}% \@xs@read@reserved@D}% - \ifx\@empty#3\@empty - \@xs@ReturnResult{#2}{#5}% + \@xs@testempty{#3}% + \if@xs@empty + \expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@D}{#5}% \else \@xs@read@reserved@D \expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@C}{#5}% @@ -661,7 +727,8 @@ % Macro interne fermant autant de groupes que n\'ecessaire pour trouver une unit\'e syntaxique derri\`ere \def\@xs@continuetonext{% - \ifx\@xs@reserved@C\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty \ifnum\@xs@nestlevel>\z@ \expandafter\endgroup\expandafter\@xs@addtomacro\expandafter\@xs@reserved@B\expandafter{\expandafter{\@xs@reserved@B}}% on concat\`ene \expandafter\expandafter\expandafter\@xs@continuetonext% on recommence @@ -746,9 +813,9 @@ \@xs@newmacro\StrChar{}{2}{1}{% \let\@xs@reserved@B\@empty + \def\@xs@reserved@C{#1}\def\@xs@reserved@D{#2}% \ifnum#2>\z@ - \def\@xs@reserved@C{#1}\def\@xs@reserved@D{#2}\decimalpart\z@ - \def\groupID{0}\let\@xs@nestlevel\z@\integerpart\z@ + \def\groupID{0}\let\@xs@nestlevel\z@\integerpart\z@\decimalpart\z@ \let\@xs@atbegingroup\relax \def\@xs@atendofgroup{\endgroup\@xs@read@reserved@C}% \def\@xs@atnextsyntaxunit{% @@ -760,15 +827,17 @@ \fi}% \@xs@read@reserved@C \fi - \ifx\@xs@reserved@B\@empty\let\groupID\@empty\fi + \expandafter\@xs@testempty\expandafter{\@xs@reserved@B}% + \if@xs@empty\let\groupID\@empty\fi \expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@B}{#3}} % Combien de fois compte t-on #2 dans #1 ? \@xs@newmacro\StrCount{}{2}{1}{% - \ifx\@empty#2\@empty + \@xs@testempty{#2}% + \def\@xs@reserved@D{#1}\def\@xs@reserved@E{#2}\let\@xs@reserved@C\@empty + \if@xs@empty \@xs@ReturnResult{0}{#3}% \else - \def\@xs@reserved@D{#1}\def\@xs@reserved@E{#2}\let\@xs@reserved@C\@empty \decimalpart\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@ \def\@xs@atendofgroup{% \expandafter\endgroup @@ -811,14 +880,25 @@ \def\@xs@StrCompare@i#1#2#3{% \def\@xs@StrCompare@iii##1{% + \let\@xs@reserved@A\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty + \def\@xs@reserved@A{*\@xs@comparecoeff}% + \else + \expandafter\@xs@testempty\expandafter{\@xs@reserved@D}% + \if@xs@empty + \def\@xs@reserved@A{*\@xs@comparecoeff}% + \fi + \fi \def\@xs@next{% \expandafter\@xs@ReturnResult\expandafter - {\number\numexpr##1\ifx\@empty\@xs@reserved@C*\@xs@comparecoeff\else\ifx\@empty\@xs@reserved@D*\@xs@comparecoeff\fi\fi\relax}{#3}}}% + {\number\numexpr##1\@xs@reserved@A\relax}{#3}}}% \def\@xs@StrCompare@ii##1{% ##1 est la position \expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@reserved@C}\@xs@reserved@A \expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@reserved@D}\@xs@reserved@B \ifx\@xs@reserved@B\@xs@reserved@A - \ifx\@xs@reserved@A\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@A}% + \if@xs@empty \@xs@StrCompare@iii{##1}% les 2 unit\'es syntaxiques sont \'egales, on renvoie la position \else \def\@xs@next{\expandafter\@xs@StrCompare@ii\expandafter{\number\numexpr##1+1}}% les 2 unit\'es syntaxiques sont \'egales et non vides, on recommence @@ -842,7 +922,8 @@ \@xs@next} \def\@xs@StrFindGroup@i#1#2[#3]{% \def\@xs@StrFindGroup@ii{% - \ifx\@xs@reserved@C\@empty + \expandafter\@xs@testempty\expandafter{\@xs@reserved@C}% + \if@xs@empty \def\@xs@next{\@xs@ReturnResult{}{#3}}% s'il ne reste plus rien, on renvoie vide \else \expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@reserved@C}\@xs@reserved@D @@ -985,7 +1066,7 @@ % - Correction d'un bug : \expandafter#1 % dans les macros \IfSubStrBefore et \StrBetween qui buggue si #1 est un % nombre > 9 ! -% - R\'e \'ecriture de \@xs@returnfirstsyntaxunit et \@xs@gobblefirstchar qui +% - R\'e \'ecriture de \@xs@returnfirstsyntaxunit et \@gobble qui % deviennent purement d\'eveloppables. % - R\'e \'ecriture de \StrLen % - Nouvelle macro interne \@xs@cutafteroccur @@ -1044,4 +1125,10 @@ % donc silencieux ;) % - Passage de 3 \'a 2 compteurs % - Le manuel est d\'esormais plus color\'e, en esp\'erant qu'il sera un peu -% plus agr\'eable \`a lire !
\ No newline at end of file +% plus agr\'eable \`a lire ! +%------------------------------------------------------------------------------ +% v1.5a 13/3/2009 +% - Modification d'un grand nombre de macros de telle sorte que vraiment +% n'importe quel code peut d\'esormais \^etre plac\'e dans les arguments des +% macros (comme par exemple des \if, \ifx ou autre, m\^eme sans leur \fi, ce +% qui n'\'etait pas possible jusqu'alors)
\ No newline at end of file |