Skip to content

Instantly share code, notes, and snippets.

@jfbu
Created September 9, 2018 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfbu/ff1fe5ddad072c59e940b321edc25353 to your computer and use it in GitHub Desktop.
Save jfbu/ff1fe5ddad072c59e940b321edc25353 to your computer and use it in GitHub Desktop.
CheckWhetherNull.tex
% Time-stamp: <09-09-2018 15:45:05 CEST>
% cf https://tex.stackexchange.com/questions/449869/trying-to-get-zapspace-and-lowercase-to-work-on-string-comparison/449979
\catcode`@ 11
\long\def\@gobble#1{}
%\long\def\JFB@stop@firstoftwo#1#2{\z@#1}
\long\def\JFB@stop@secondoftwo#1#2{\z@#2}
\long\def\JFB@stop@thirdoffour#1#2#3#4{\z@#3}
% first variant
\long\def\JFB@CheckWhetherNull#1{%
\romannumeral
\expandafter\expandafter\expandafter\@gobble
\expandafter\expandafter\expandafter{%
\expandafter\string\expandafter{%
\expandafter{\string#1}\expandafter\@gobble\string}%
\iffalse}\JFB@stop@thirdoffour\fi
\JFB@stop@secondoftwo
}%
\JFB@CheckWhetherNull{}{OK}{WRONG}
\JFB@CheckWhetherNull{{}}{WRONG}{OK}
\JFB@CheckWhetherNull{ }{WRONG}{OK}
\JFB@CheckWhetherNull{ {}}{WRONG}{OK}
\JFB@CheckWhetherNull{a}{WRONG}{OK}
\JFB@CheckWhetherNull{\error}{WRONG}{OK}
% second variant with less \expandafter's
\long\def\@gobbletwo#1#2{}
\long\def\JFB@CheckWhetherNull#1{%
\romannumeral
\expandafter\expandafter\expandafter\@gobbletwo
\expandafter\string\expandafter{\expandafter{%
\expandafter{\string#1}\expandafter\@gobble\string}%
\iffalse}\JFB@stop@thirdoffour\fi
\JFB@stop@secondoftwo
}%
\JFB@CheckWhetherNull{}{OK}{WRONG}
\JFB@CheckWhetherNull{{}}{WRONG}{OK}
\JFB@CheckWhetherNull{ }{WRONG}{OK}
\JFB@CheckWhetherNull{ {}}{WRONG}{OK}
\JFB@CheckWhetherNull{a}{WRONG}{OK}
\JFB@CheckWhetherNull{\error}{WRONG}{OK}
\bye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment