From bcdf6c829c6761de02484473ebe43fa3760adcaa Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Wed, 12 May 2021 03:01:15 +0000
Subject: CTAN sync 202105120301

---
 macros/latex/contrib/l3kernel/l3cctab.dtx | 41 +++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

(limited to 'macros/latex/contrib/l3kernel/l3cctab.dtx')

diff --git a/macros/latex/contrib/l3kernel/l3cctab.dtx b/macros/latex/contrib/l3kernel/l3cctab.dtx
index a84852f73b..9a0bc54933 100644
--- a/macros/latex/contrib/l3kernel/l3cctab.dtx
+++ b/macros/latex/contrib/l3kernel/l3cctab.dtx
@@ -43,7 +43,7 @@
 %    }^^A
 % }
 %
-% \date{Released 2021-05-07}
+% \date{Released 2021-05-11}
 %
 % \maketitle
 %
@@ -110,7 +110,7 @@
 %   matching \cs{cctab_begin:N}.
 % \end{function}
 %
-% \begin{function}[added = 2020-05-19, updated = 2020-07-02]{\cctab_select:N}
+% \begin{function}[added = 2020-05-19, updated = 2020-07-02]{\cctab_select:N, \cctab_select:c}
 %   \begin{syntax}
 %     \cs{cctab_select:N} \meta{category code table}
 %   \end{syntax}
@@ -120,6 +120,15 @@
 %   and \cs{cctab_gset:Nn}.
 % \end{function}
 %
+% \begin{function}[EXP, added = 2021-05-10]{\cctab_item:Nn, \cctab_item:cn}
+%   \begin{syntax}
+%     \cs{cctab_item:Nn} \meta{category code table} \Arg{integer expression}
+%   \end{syntax}
+%   Determines the \meta{character} with character code given by the
+%   \meta{integer expression} and expands to its category code specified
+%   by the \meta{category code table}.
+% \end{function}
+%
 % \section{Category code table conditionals}
 %
 % \begin{function}[pTF]{\cctab_if_exist:N, \cctab_if_exist:c}
@@ -660,6 +669,34 @@
   }
 %    \end{macrocode}
 %
+%
+% \begin{macro}{\cctab_item:Nn, \cctab_item:cn}
+%   Evaluate the integer argument only once.  In most engines the
+%   |cctab| variable only has $256$ entries so we only look up the
+%   catcode for these entries, otherwise we use the current catcode.  In
+%   particular, for out-of-range values we use whatever fall-back
+%   \cs{char_value_catcode:n}.  In \LuaTeX{}, we use the
+%   |tex.getcatcode| function.
+%    \begin{macrocode}
+\cs_new:Npn \cctab_item:Nn #1#2
+  { \exp_args:Nf \@@_item:nN { \int_eval:n {#2} } #1 }
+\sys_if_engine_luatex:TF
+  {
+    \cs_new:Npn \@@_item:nN #1#2
+      { \lua_now:e { tex.print(-2, tex.getcatcode(\int_use:N #2, #1)) } }
+  }
+  {
+    \cs_new:Npn \@@_item:nN #1#2
+      {
+        \int_compare:nNnTF {#1} < { 256 }
+          { \intarray_item:Nn #2 { #1 + 1 } }
+          { \char_value_catcode:n {#1} }
+      }
+  }
+\cs_generate_variant:Nn \cctab_item:Nn { c }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{Category code table conditionals}
 %
 % \begin{macro}{\cctab_if_exist:N,\cctab_if_exist:c}
-- 
cgit v1.2.3

