svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / string / SubstringFunction.java @ 44198
History | View | Annotate | Download (912 Bytes)
1 | 43512 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.string; |
---|---|---|---|
2 | |||
3 | import org.apache.commons.lang3.Range; |
||
4 | import org.apache.commons.lang3.StringUtils; |
||
5 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Interpreter; |
6 | 43512 | jjdelcerro | import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | |||
8 | public class SubstringFunction extends AbstractFunction { |
||
9 | |||
10 | public SubstringFunction() {
|
||
11 | super("String", "SUBSTRING", Range.between(2, 3)); |
||
12 | this.addAlias("SUBSTR"); |
||
13 | } |
||
14 | |||
15 | |||
16 | @Override
|
||
17 | 44009 | jjdelcerro | public boolean allowConstantFolding() { |
18 | return true; |
||
19 | } |
||
20 | |||
21 | @Override
|
||
22 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object[] args) throws Exception { |
23 | 43512 | jjdelcerro | String str = getStr(args,0); |
24 | int start = getInt(args, 1); |
||
25 | String r = StringUtils.substring(str, start);
|
||
26 | if( args.length == 3 ) { |
||
27 | int len = getInt(args, 2); |
||
28 | r = StringUtils.left(r, len); |
||
29 | } |
||
30 | return r;
|
||
31 | } |
||
32 | |||
33 | } |