/**
* @param args 1 string values then 2 numeric values (start and end).
* @return Sliced string
*/
public Value execute(Value... args) {
Value stringValue = args[0];
Value startValue = args[1];
Value endValue = args[2];
String string = stringValue.asString();
int start = startValue.asNumber();
int end = endValue.asNumber();
int length = string.length();
if (start < 0) {
start += max(-start, length);
if (end == 0) {
end = length;
}
}
if (end < 0) {
end += length;
}
end = min(end, length);
if (end < start) {
return literalConstant("", args[0]);
}
return literalValue(string.substring(start, end), stringValue.getEscapeMode(), stringValue
.isPartiallyEscaped()
|| startValue.isPartiallyEscaped() || endValue.isPartiallyEscaped());
}