public static NodeEnumeration tokenize(Context context, String str, String pattern) throws XPathException {
try {
Builder builder = context.getController().makeBuilder();
NamePool pool = context.getController().getNamePool();
builder.setNamePool(pool);
builder.startDocument();
int name = pool.allocate("", "", "token");
AttributeCollection emptyAtts = new AttributeCollection(pool);
String[] tokens = str.split(pattern);
for(String token: tokens) {
builder.startElement(name, emptyAtts, new int[0], 0);
builder.characters(token.toCharArray(), 0, token.length());
builder.endElement(name);
}
builder.endDocument();
DocumentInfo doc = builder.getCurrentDocument();
return doc.getEnumeration(Axis.CHILD, AnyNodeTest.getInstance());
} catch (Exception err) {
ExtensionFunctionUtils.setExtensionFunctionError(err);
throw new XPathException(err);
}
}