Prevent the end range of a substring from going over the end of the string.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@487401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Marc Prud'hommeaux 2006-12-15 00:04:14 +00:00
parent 4e85c5eb84
commit 53614b371f
1 changed files with 4 additions and 2 deletions

View File

@ -50,8 +50,10 @@ class Substring
Object arg = _args.eval(candidate, orig, ctx, params);
if (arg instanceof Object[]) {
Object[] args = (Object[]) arg;
return str.toString().substring(((Number) args[0]).intValue(),
((Number) args[1]).intValue());
int start = ((Number) args[0]).intValue();
int end = Math.min(((Number) args[1]).intValue(),
str.toString().length() - start + 1);
return str.toString().substring(start, end);
}
return str.toString().substring(((Number) arg).intValue());
}