private String getFirstSegment ( String expression ) { int indexDot = expression . indexOf ( ' ' ) ; int indexBracket = expression . indexOf ( ' ' ) ; if ( indexBracket < 0 ) { return indexDot < 0 ? expression : expression . substring ( 0 , indexDot ) ; } if ( indexDot < 0 ) { return expression . substring ( 0 , indexBracket ) ; } return expression . substring ( 0 , Math . min ( indexDot , indexBracket ) ) ; }
Extract the first expression segment that is the substring up to the first . or [