I don't understand the following behavior.
Intro
First, here is a simplified version of a macro I am using (which is itself a hacked version of a macro found in gloss.tex). If you have a string MY|STRING with a delimiter in it (in this case, a pipe), then \getmorphs MY|STRING|\\ will split it into its parts MY and STRING. Notice we have to put a pipe at the end of MY|STRING when we pass it as an argument to \getmorphs so that there is always at least one "part delimited by a pipe" (argument #1 in \getmorphs):
\makeatletter
\def\getmorphs#1|#2\\{%
\@getparts(#1,#2,\getmorphs)
}
\def\@getparts(#1,#2,#3){Printed: #1%
\def\more{#2}%
\ifx\more\empty\let\more=\donewords
\expandafter\else\expandafter\let\expandafter\more=#3
\fi
\more#2\\%
}
\gdef\donewords#1\\{}%
\makeatother
That is illustrated here, where \getmorphs prints each part separately:
\getmorphs aaa|bbb|\\% Printed: aaa Printed: bbb (correct)
And it even works if we define a macro which expands to some text with pipes in it, and pass that macro as the argument to \getmorphs. To make it work, we have to use \expandafter so that \testmacro expands before \getmorphs:
\def\testmacro{aaa|bbb}
\getmorphs\testmacro|\\% Printed: aaa|bbb (incorrect)
\expandafter\getmorphs\testmacro|\\% Printed: aaa Printed: bbb (correct)
Problem
In the actual code I am working on, I have an hbox whose contents are aaa|bbb:
\newbox\testbox
\setbox\testbox=\hbox{aaa|bbb}
What I can't figure out is how to pass the contents of that box to \getmorphs. I have tried variations of the sort
\getmorphs\unhbox\testbox|\\
\expandafter\getmorphs\unhbox\testbox|\
etc., and have even tried defining a scratch macro to expand to \unhbox\testbox and then passed that as the argument to \getmorphs as before:
\def\moretest{\unhbox\testbox}
\expandafter\getmorphs\moretest|\
Nothing works. Does anyone know how I can access the contents of that hbox and use it as an argument of a macro?