The goal of the program below is to apply certain modification to the values of certain keys within a cs list. It works fine, except for removing the leading comma. Try with/out lines A and B.
\documentclass{report}
\usepackage{xparse}
%https://tex.stackexchange.com/questions/523083/keyval-parse-for-dummies/523085#523085
\ExplSyntaxOn
\cs_new_protected:Npn \my_keyval_parser:nn #1 #2
{
\group_begin:
\str_clear:N \l_tmpa_str
\str_case:nnTF { #1 }
{
{ foo } {,\tl_put_right:Nn \l_tmpa_str {#1=(#2)}}
{ bar } {,\tl_put_right:Nn \l_tmpa_str {#1=[#2]}}
}
{}
{\tl_put_right:Nn \l_tmpa_str{#1=#2}}
% \exp_args:NV \str_tail:n\l_tmpa_str
\l_tmpa_str
\group_end:
}
\cs_new_protected:Npn \my_key_parser:n #1
{
\str_case:nnTF { #1 }
{
{ qux } {,QUX}
}
{}
{}
}
\begin{document}
\exp_args:Nf % A
\str_tail:n % B
{
\keyval_parse:NNn
\my_key_parser:n
\my_keyval_parser:nn
{
foo=World,
bar=Universe,
qux
}
}%WANTED: foo=(World),bar=[Universe],QUX
\ExplSyntaxOff
\end{document}


