SequenceReceiver out = context.getReceiver();
// Start and end with an empty string to force space separation from any previous or following outputs
out.append(StringValue.EMPTY_STRING, 0, 0);
SequenceIterator iter = argument[0].iterate(context);
Item it = iter.next();
if (it==null) {
return;
}
CharSequence first = it.getStringValueCS();
out.characters(first, 0, 0);
it = iter.next();
if (it==null) {
out.append(StringValue.EMPTY_STRING, 0, 0);
return;
}
// Type checking ensures that the separator is not an empty sequence
CharSequence sep = argument[1].evaluateItem(context).getStringValueCS();
out.characters(sep, 0, 0);
out.characters(it.getStringValueCS(), 0, 0);
while (true) {
it = iter.next();
if (it == null) {
break;
}
out.characters(sep, 0, 0);
out.characters(it.getStringValueCS(), 0, 0);
}
out.append(StringValue.EMPTY_STRING, 0, 0);
}