public String format(Passage passages[], String content) {StringBuilder sb = new StringBuilder();int pos = 0;for (Passage passage : passages) {if (passage.getStartOffset() > pos && pos > 0) {sb.append(ellipsis);}pos = passage.getStartOffset();for (int i = 0; i < passage.getNumMatches(); i++) {int start = passage.getMatchStarts()[i];assert start >= pos && start < passage.getEndOffset();append(sb, content, pos, start);int end = passage.getMatchEnds()[i];assert end > start;while (i + 1 < passage.getNumMatches() && passage.getMatchStarts()[i+1] < end) {end = passage.getMatchEnds()[++i];}end = Math.min(end, passage.getEndOffset()); sb.append(preTag);append(sb, content, start, end);sb.append(postTag);pos = end;}append(sb, content, pos, Math.max(pos, passage.getEndOffset()));pos = passage.getEndOffset();}return sb.toString();}

public String format ( Passage passages [ ] , String content ) { StringBuilder sb = new StringBuilder ( ) ; int pos = 0 ; for ( Passage passage : passages ) { if ( passage . getStartOffset ( ) > pos && pos > 0 ) { sb . append ( ellipsis ) ; } pos = passage . getStartOffset ( ) ; for ( int i = 0 ; i < passage . getNumMatches ( ) ; i ++ ) { int start = passage . getMatchStarts ( ) [ i ] ; assert start >= pos && start < passage . getEndOffset ( ) ; append ( sb , content , pos , start ) ; int end = passage . getMatchEnds ( ) [ i ] ; assert end > start ; while ( i + 1 < passage . getNumMatches ( ) && passage . getMatchStarts ( ) [ i + 1 ] < end ) { end = passage . getMatchEnds ( ) [ ++ i ] ; } end = Math . min ( end , passage . getEndOffset ( ) ) ; sb . append ( preTag ) ; append ( sb , content , start , end ) ; sb . append ( postTag ) ; pos = end ; } append ( sb , content , pos , Math . max ( pos , passage . getEndOffset ( ) ) ) ; pos = passage . getEndOffset ( ) ; } return sb . toString ( ) ; }
public override object Format(Passage[] passages, string content){StringBuilder sb = new StringBuilder();int pos = 0;foreach (Passage passage in passages){if (passage.startOffset > pos && pos > 0){sb.Append(m_ellipsis);}pos = passage.startOffset;for (int i = 0; i < passage.numMatches; i++){int start = passage.matchStarts[i];int end = passage.matchEnds[i];if (start > pos){Append(sb, content, pos, start);}if (end > pos){sb.Append(m_preTag);Append(sb, content, Math.Max(pos, start), end);sb.Append(m_postTag);pos = end;}}Append(sb, content, pos, Math.Max(pos, passage.endOffset));pos = passage.endOffset;}return sb.ToString();}
