static Matcher combineAdjacentCharSeqs ( Matcher matcher ) { if ( matcher instanceof SeqMatcher ) { List < Matcher > matchers = matcher . < SeqMatcher > as ( ) . matchers ( ) ; List < Matcher > ms = new ArrayList <> ( ) ; CharSeqMatcher cs1 = null ; for ( Matcher m : matchers ) { if ( m instanceof CharSeqMatcher ) { if ( cs1 == null ) { cs1 = m . as ( ) ; } else { CharSeqMatcher cs2 = m . as ( ) ; cs1 = new CharSeqMatcher ( cs1 . pattern ( ) + cs2 . pattern ( ) ) ; } } else { if ( cs1 != null ) { ms . add ( cs1 ) ; cs1 = null ; } ms . add ( m ) ; } } if ( cs1 != null ) { ms . add ( cs1 ) ; } return SeqMatcher . create ( ms ) ; } return matcher ; }
If a char sequence is adjacent to another char sequence then concatenate the sequences .