public static String word_slice ( EvaluationContext ctx , Object text , Object start , @ IntegerDefault ( 0 ) Object stop , @ BooleanDefault ( false ) Object bySpaces ) { String _text = Conversions . toString ( text , ctx ) ; int _start = Conversions . toInteger ( start , ctx ) ; Integer _stop = Conversions . toInteger ( stop , ctx ) ; boolean _bySpaces = Conversions . toBoolean ( bySpaces , ctx ) ; if ( _start == 0 ) { throw new RuntimeException ( "Start word cannot be zero" ) ; } else if ( _start > 0 ) { _start -= 1 ; // convert to a zero-based offset } if ( _stop == 0 ) { // zero is treated as no end _stop = null ; } else if ( _stop > 0 ) { _stop -= 1 ; // convert to a zero-based offset } List < String > words = getWords ( _text , _bySpaces ) ; List < String > selection = ExpressionUtils . slice ( words , _start , _stop ) ; // re-combine selected words with a single space return StringUtils . join ( selection , ' ' ) ; }
Extracts a substring spanning from start up to but not - including stop