%%%============================================================================== %% Copyright 2025-present by Alceu Frigeri %% %% This work may be distributed and/or modified under the conditions of %% %% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt), %% version 1.3c (or later), and/or %% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html), %% version 3 (or later) %% %% This work has the LPPL maintenance status *maintained*. %% %% The Current Maintainer of this work is Alceu Frigeri %% %% This is version {1.0} {2025/05/11} %% %% The list of files that compose this work can be found in the README.md file at %% https://ctan.org/pkg/switch %% %%%============================================================================== \NeedsTeXFormat{LaTeX2e}[2022/06/01] \ProvidesExplPackage {switch} {2025/05/11} {1.0} {switch a constant time switch/case} %%%%%%% %%% %%% Just an attempt of having my packages info in a regular way %%% Idea being: { / pkg info } for each and all. %%% %%%%%%% \keys_define:nn { switch / pkg info} { name .code:n = {switch} , prefix .code:n = {switch} , date .code:n = {2025/05/11}, version .code:n = {1.0} , description .code:n = {switch a constant time switch/case} } \cs_if_exist:NF \PkgInfo { \NewDocumentCommand \PkgInfo {mm} { \keys_set:nn {#1 / pkg info}{#2} } \NewDocumentCommand \PkgDescription {m} { \noindent Package~ \textbf{\PkgInfo{#1}{name}}~Version:~\PkgInfo{#1}{version}~ -~ \PkgInfo{#1}{date}\par \emph{\PkgInfo{#1}{description}}~\par } } %%%%%%% %%% End of cut-n-paste %%%%%%% \cs_new_protected:Npn \switch_new:Nn #1#2 { \cs_new:Npn #1 ##1 { \cs_if_exist_use:cF { \cs_to_str:N #1 _case_ ##1 : } { #2 } } } \cs_new_eq:NN \newswitch \switch_new:Nn \cs_new_protected:Npn \switch_addcase:Nnn #1#2#3 { \cs_new:cpn { \cs_to_str:N #1 _case_ #2 : } {#3} } \cs_new_eq:NN \addcase \switch_addcase:Nnn %%%% %%%% TeX implementation %%%% %%\makeatletter %%\def\newswitch#1#2{\def#1##1{\ifcsname\string#1@case@##1\endcsname\csname\string#1@case@##1\endcsname\else#2\fi}}% %%\def\addcase#1#2#3{\expandafter\def\csname\string#1@case@#2\endcsname{#3}}% %%\makeatother