public Object exec(List args) throws TemplateModelException { int argCnt = args.size(); checkMethodArgCount(argCnt, 1, 2); String separatorString = getStringMethodArg(args, 0); long flags = argCnt > 1 ? RegexpHelper.parseFlagString(getStringMethodArg(args, 1)) : 0; int stopIndex; if ((flags & RegexpHelper.RE_FLAG_REGEXP) == 0) { RegexpHelper.checkOnlyHasNonRegexpFlags(key, flags, true); if ((flags & RegexpHelper.RE_FLAG_CASE_INSENSITIVE) == 0) { stopIndex = s.indexOf(separatorString); } else { stopIndex = s.toLowerCase().indexOf(separatorString.toLowerCase()); } } else { Pattern pattern = RegexpHelper.getPattern(separatorString, (int) flags); final Matcher matcher = pattern.matcher(s); if (matcher.find()) { stopIndex = matcher.start(); } else { stopIndex = -1; } } return stopIndex == -1 ? new SimpleScalar(s) : new SimpleScalar(s.substring(0, stopIndex)); } }
public Object exec(List args) throws TemplateModelException { int argCnt = args.size(); checkMethodArgCount(argCnt, 1, 2); String separatorString = getStringMethodArg(args, 0); long flags = argCnt > 1 ? RegexpHelper.parseFlagString(getStringMethodArg(args, 1)) : 0; int stopIndex; if ((flags & RegexpHelper.RE_FLAG_REGEXP) == 0) { RegexpHelper.checkOnlyHasNonRegexpFlags(key, flags, true); if ((flags & RegexpHelper.RE_FLAG_CASE_INSENSITIVE) == 0) { stopIndex = s.indexOf(separatorString); } else { stopIndex = s.toLowerCase().indexOf(separatorString.toLowerCase()); } } else { Pattern pattern = RegexpHelper.getPattern(separatorString, (int) flags); final Matcher matcher = pattern.matcher(s); if (matcher.find()) { stopIndex = matcher.start(); } else { stopIndex = -1; } } return stopIndex == -1 ? new SimpleScalar(s) : new SimpleScalar(s.substring(0, stopIndex)); } }
public Object exec(List args) throws TemplateModelException { int argCnt = args.size(); checkMethodArgCount(argCnt, 1, 2); String separatorString = getStringMethodArg(args, 0); long flags = argCnt > 1 ? RegexpHelper.parseFlagString(getStringMethodArg(args, 1)) : 0; int stopIndex; if ((flags & RegexpHelper.RE_FLAG_REGEXP) == 0) { RegexpHelper.checkOnlyHasNonRegexpFlags(key, flags, true); if ((flags & RegexpHelper.RE_FLAG_CASE_INSENSITIVE) == 0) { stopIndex = s.indexOf(separatorString); } else { stopIndex = s.toLowerCase().indexOf(separatorString.toLowerCase()); } } else { Pattern pattern = RegexpHelper.getPattern(separatorString, (int) flags); final Matcher matcher = pattern.matcher(s); if (matcher.find()) { stopIndex = matcher.start(); } else { stopIndex = -1; } } return stopIndex == -1 ? new SimpleScalar(s) : new SimpleScalar(s.substring(0, stopIndex)); } }