\IfStrEqCase having problem with last optional parameter

The internal macro that checks the cases is \@xs@testcase. Using \tracingmacros=1 with your original input, we find:

\@xs@testcase #1#2#3\@xs@nil ->\@xs@reserved@E {\CaseVar }{#1}{#2}{\@xs@ifempty
 {#3}{Oppsss, unknown case '\CaseVar '.}{\@xs@testcase #3\@xs@nil }}
#1<-case A
#2<-Found Case A
#3<- {case B}{Found Case B} 

for the first test; you can see the blank space resulting from the end-of-line after {Found Case A}. This is not a problem, because this space will not be considered at the next test:

\@xs@testcase #1#2#3\@xs@nil ->\@xs@reserved@E {\CaseVar }{#1}{#2}{\@xs@ifempty
 {#3}{Oppsss, unknown case '\CaseVar '.}{\@xs@testcase #3\@xs@nil }}
#1<-case B
#2<-Found Case B
#3<- 

Do you see the problem? The third argument to \@xs@testcase is delimited by \@xs@nil and in this case a blank space is as good as an argument as any list of tokens. TeX disregards spaces only when looking for undelimited arguments.

Add % at the end of lines, if you use that kind of input style.

Probably xstring should use a test for \ifblank rather than \ifempty.

Tags:

Xstring