public List < Segment > buildSegments ( String str ) { List < Segment > segments = new ArrayList <> ( ) ; String value = str ; int i = value . indexOf ( PREFIX ) ; while ( i > - 1 ) { //the text before the prefix if ( i > 0 ) { String rawSegment = value . substring ( 0 , i ) ; segments . add ( new RawSegment ( rawSegment ) ) ; } //everything after the prefix value = value . substring ( i + PREFIX . length ( ) ) ; int suffixIdx = value . indexOf ( SUFFIX ) ; if ( suffixIdx > - 1 ) { String expr = value . substring ( 0 , suffixIdx ) . trim ( ) ; segments . add ( new PlaceholderSegment ( expr ) ) ; if ( value . length ( ) > suffixIdx ) { value = value . substring ( suffixIdx + SUFFIX . length ( ) ) ; } } else { throw new ConfigurationException ( "Incomplete placeholder definitions detected: " + str ) ; } i = value . indexOf ( PREFIX ) ; } if ( value . length ( ) > 0 ) { segments . add ( new RawSegment ( value ) ) ; } return segments ; }
Split a placeholder value into logic segments .