@Builtin(Name = "index-of")
public static RuleList index_of(final Argument arg) {
if (arg.arguments.size() == 2
&& arg.arguments.get(0) instanceof RuleList
&& arg.arguments.get(1) instanceof Item) {
final RuleList list = (RuleList) arg.arguments.get(0);
final Item item = arg.arguments.get(1);
IExpression lookingFor = null;
if (item instanceof Variable)
lookingFor = new RuleVariable(item.getName());
else if (item instanceof Literal)
lookingFor = new Constant((Literal) item, list);
else if (item instanceof IExpression)
lookingFor = (IExpression) item;
final RuleList results = new RuleList();
for (int i = 0; i < list.getItems().size(); i++) {
if (list.getItems().get(i).equals(lookingFor))
results.addItem(new Constant(BuiltinHelper
.createXSLiteral(i, "integer"), results));
}
return results;
}
return null;