Please note that expl3
offers you different data types and also provides tests for those data types. One of these is a token list, which is the correct variable type to store contents which you might want to print out.
The following changes your code to follow expl3
naming conventions and uses token list variables to store the email addresses. As a result you can use \tl_if_empty:cTF
to check whether the email is indeed empty.
\documentclass{article}
\ExplSyntaxOn
\int_new:N \l_sergiokapone_creator_int
\cs_new_protected:Npn \sergiokapone_new_creator:nn #1#2
{
\int_incr:N \l_sergiokapone_creator_int
\tl_new:c
{ l__sergiokapone_creator \int_use:N \l_sergiokapone_creator_int _tl }
\tl_new:c
{ l__sergiokapone_email \int_use:N \l_sergiokapone_creator_int _tl }
\tl_set:cn
{ l__sergiokapone_creator \int_use:N \l_sergiokapone_creator_int _tl }
{#2}
\tl_set:cn
{ l__sergiokapone_email \int_use:N \l_sergiokapone_creator_int _tl }
{#1}
}
\NewDocumentCommand \creator { O{} m }
{ \sergiokapone_new_creator:nn {#1} {#2} }
\NewDocumentCommand\usemail { m }
{
\tl_if_empty:cTF { l__sergiokapone_email #1 _tl }
{ \emph{empty} }
{ \tl_use:c { l__sergiokapone_email #1 _tl } }
}
\ExplSyntaxOff
\begin{document}
\creator[]{Me}
\creator{You}
\creator[[email protected]]{Him}
\usemail{1}
\usemail{2}
\usemail{3}
\end{document}
\tl_set:cn { l__<module>_creator \int_use:N \l_creator_int _tl } {#2}
, then you can check whether it's empty with\tl_if_empty:cTF { l__<module>_creator <num> _tl} { <true> } { <false> }
.