case ENDSWITH:
return BooleanValue.get(s0.endsWith(s1));
case AFTER:
int i = s0.indexOf(s1);
if (i<0) return StringValue.EMPTY_STRING;
return new StringValue(s0.substring(i+s1.length()));
case BEFORE:
int j = s0.indexOf(s1);
if (j<0) return StringValue.EMPTY_STRING;
return new StringValue(s0.substring(0, j));
default:
throw new UnsupportedOperationException("Unknown operation " + operation);
}
} else {
if (!(collator instanceof RuleBasedCollator)) {
dynamicError("The collation for " + getDisplayName(context.getController().getNamePool()) +
" must be a RuleBaseCollator", context);
return null;
}
RuleBasedCollator rbc = (RuleBasedCollator)collator;
CollationElementIterator iter0 = rbc.getCollationElementIterator(s0);
CollationElementIterator iter1 = rbc.getCollationElementIterator(s1);
switch (operation) {
case STARTSWITH:
return BooleanValue.get( collationStartsWith(iter0, iter1) );
case CONTAINS:
case ENDSWITH:
return BooleanValue.get( collationContains(iter0, iter1, null) );
case AFTER:
int[] ia = new int[2];
boolean ba = collationContains(iter0, iter1, ia);
if (ba) {
return new StringValue(s0.substring(ia[1]));
} else {
return StringValue.EMPTY_STRING;
}
case BEFORE:
int[] ib = new int[2];
boolean bb = collationContains(iter0, iter1, ib);
if (bb) {
return new StringValue(s0.substring(0, ib[0]));
} else {
return StringValue.EMPTY_STRING;
}
default:
throw new UnsupportedOperationException("Unknown operation " + operation);