%%%==============================================================================
%% 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.1b} {2025/10/28}
%%
%% 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/10/28}
    {1.1b}
    {a constant time switch/case}

%%%%%%%
%%%
%%% Just an attempt of having my packages info in a regular way
%%% \Pkginfograb_set:nn {<pkg-name>} { props} for each and all.
%%%
%%%%%%%
\RequirePackage{pkginfograb}
\pkginfograb_set:nn { switch }
  {
     name        = {switch} ,
     prefix      = {switch} ,
     date        = {2025/10/28},
     version     = {1.1b} ,
     description = {a~ constant~ time~ switch/case}
  }
%%%%%%%
%%% 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
  {
    \cs_new:cn { \cs_to_str:N #1 _case_ #2 : }
  }
\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


%%
%% Just to be complete... questionable, at best.
%%
\prg_new_eq_conditional:NNn \switch_if_exist:N \cs_if_exist:N {p, T, F, TF}

\cs_set:Npn \switch_if_case_exist:NnTF #1#2
  { \cs_if_exist:cTF { \cs_to_str:N #1 _case_ #2 : } }
\cs_set:Npn \switch_if_case_exist:NnT #1#2
  { \cs_if_exist:cT { \cs_to_str:N #1 _case_ #2 : } }
\cs_set:Npn \switch_if_case_exist:NnF #1#2
  { \cs_if_exist:cF { \cs_to_str:N #1 _case_ #2 : } }
\cs_set:Npn \switch_if_case_exist_p:Nn #1#2
  { \cs_if_exist_p:c { \cs_to_str:N #1 _case_ #2 : } }
  
\cs_new_eq:NN \switch_undefine:N \cs_undefine:N

\cs_new_protected:Npn \switch_case_undefine:Nn #1#2
  {
    \cs_undefine:c { \cs_to_str:N #1 _case_ #2 : }
  }


