Convert token to string in LaTeX3
Further thinking along with @egreg's comments have led me to do things in a slightly different way and use an inline map. It's not quite as compact as I might have hoped to achieve with \str_if_in:nnTF
, but at least it doesn't involve nested boolean checks.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\bool_new:N \l__dcp_punct_found_bool
\cs_new_protected:Nn \__dcp_test_punct:
{
\bool_set_false:N \l__dcp_punct_found_bool
\str_map_inline:nn { .,:;!? }
{
\token_if_eq_meaning:NNT \l_peek_token ##1
{
~Punctuation~found:~
\bool_set_true:N \l__dcp_punct_found_bool
\str_map_break:
}
}
\bool_if:NF \l__dcp_punct_found_bool
{ ~Punctuation~not~found~ }
}
\cs_new_protected:Nn \__dcp_test_punct:n
{
\peek_after:Nw \__dcp_test_punct:
}
\DeclareDocumentCommand {\testpunct} { +m }
{
\__dcp_test_punct:n {#1}
}
\ExplSyntaxOff
\begin{document}
\testpunct{A}.
\testpunct{A},
\testpunct{A}:
\testpunct{A};
\testpunct{A}!
\testpunct{A}?
\testpunct{A}
\end{document}