// This rather tortuous code is designed to ensure that we don't evaluate the
// separator argument unless there are at least two items in the sequence.
SequenceIterator iter = argument[0].iterate(c);
Item it = iter.next();
if (it==null) {
return StringValue.EMPTY_STRING;
}
CharSequence first = it.getStringValueCS();
it = iter.next();
if (it==null) {
return StringValue.makeStringValue(first);
}
FastStringBuffer sb = new FastStringBuffer(1024);
sb.append(first);
// Type checking ensures that the separator is not an empty sequence
CharSequence sep = argument[1].evaluateItem(c).getStringValueCS();
sb.append(sep);
sb.append(it.getStringValueCS());
while (true) {
it = iter.next();
if (it == null) {
return StringValue.makeStringValue(sb.condense());
}
sb.append(sep);
sb.append(it.getStringValueCS());
}
}