%D \module
%D   [       file=unic-exp,
%D        version=2002.12.05,
%D          title=\CONTEXT\ \UNICODE\ Support,
%D       subtitle=\UNICODE\ vector expansion,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{Context UNICODE Macros (expansion)}

%D \macros
%D   {expandunivector}
%D
%D The \type {\expandunivector} macro can be used to expand
%D vectors, which leads to a faster run in case of documents
%D with lots of \UTF-8 code.

\unprotect

\def\expandunivector[#1]%
  {\processcommalist[#1]\doexpandunivector}

\def\doexpandunivector#1%
  {\ifcsname\@@univector#1\endcsname
     \ifcsname\@@univector\@@univector#1\endcsname\else
       \writestatus{unicode}{expanding vector #1}%
       \setvalue{\@@univector\@@univector#1}{\expandedunivector{#1}}%
       \dorecurse{255}
         {\@EA\ifx\csname\csname\@@univector#1\endcsname\recurselevel\endcsname\unknownchar
            % skip
          \else
            \@EA\let\csname\@@univector\@@univector#1:\recurselevel\@EA\endcsname
              \csname\csname\@@univector#1\endcsname\recurselevel\endcsname
          \fi}%
       \letbeundefined{\@@univector#1}%
     \fi
   \fi}

\def\expandedunivector#1#2%
  {\ifcsname\@@univector\@@univector#1:\number#2\endcsname
     \@@univector\@@univector#1:\number#2%
   \else
     \@@unknownchar
   \fi}

%D For this purpose, we need to redefine the resolver.

\def\doutfunihash#1#2%
  {\ifcsname\@@univector\@@univector\number#1\endcsname
     \csname\@@univector\@@univector\number#1\endcsname{\utfmod{#2}}%
   \else\ifcsname\@@univector\number#1\endcsname
     \csname\@@univector#1\endcsname{\utfmod{#2}}%
   \else
     \@@unknownchar
   \fi\fi}

\let\utfunihash\utfunihashglyph

%D Let's use it:

\expandunivector[0,1,2,3,4,5,30,32,33]

\protect \endinput
