public Object exec(List args) throws TemplateModelException {
int numArgs = args.size();
if (numArgs < 1 || numArgs >2 ) {
throw new TemplateModelException(
"?replace(...) needs 1 or 2 arguments.");
}
String splitString = (String) args.get(0);
String flags = numArgs >1 ? (String) args.get(1) : "";
boolean caseInsensitive = flags.indexOf('i") >=0;
boolean useRegexp = flags.indexOf('r") >=0;
String[] result = null;
if (!useRegexp) {
result = StringUtil.split(s, splitString, caseInsensitive);
} else {
Pattern pattern = getPattern(splitString, flags);
result = pattern.split(s);
}
return ObjectWrapper.DEFAULT_WRAPPER.wrap(result);
}
|