public StringBuffer format ( Object pat , StringBuffer result , FieldPosition fpos ) { String pattern = processPattern ( ( String ) pat ) ; int lastOffset = 0 ; for ( int i = 0 ; i <= maxOffset ; ++ i ) { int offidx = offsets [ i ] ; result . append ( pattern . substring ( lastOffset , offsets [ i ] ) ) ; lastOffset = offidx ; String key = arguments [ i ] ; String obj ; if ( key . length ( ) > 0 ) { obj = formatObject ( processKey ( key ) ) ; } else { // else just copy the left and right braces result . append ( this . ldel ) ; result . append ( this . rdel ) ; continue ; } if ( obj == null ) { // try less-greedy match; useful for e.g. PROP___PROPNAME__ where // 'PROPNAME' is a key and delims are both '__' // this does not solve all possible cases, surely, but it should catch // the most common ones String lessgreedy = ldel + key ; int fromright = lessgreedy . lastIndexOf ( ldel ) ; if ( fromright > 0 ) { String newkey = lessgreedy . substring ( fromright + ldel . length ( ) ) ; String newsubst = formatObject ( processKey ( newkey ) ) ; if ( newsubst != null ) { obj = lessgreedy . substring ( 0 , fromright ) + newsubst ; } } } if ( obj == null ) { if ( throwex ) { throw new IllegalArgumentException ( "ObjectForKey" ) ; } else { obj = ldel + key + rdel ; } } result . append ( obj ) ; } result . append ( pattern . substring ( lastOffset , pattern . length ( ) ) ) ; return result ; }
Formats the parsed string by inserting table s values .