public Hyphenation hyphenate ( char [ ] w , int offset , int len , int remainCharCount , int pushCharCount ) { int i ; char [ ] word = new char [ len + 3 ] ; // normalize word char [ ] c = new char [ 2 ] ; int iIgnoreAtBeginning = 0 ; int iLength = len ; boolean bEndOfLetters = false ; for ( i = 1 ; i <= len ; i ++ ) { c [ 0 ] = w [ offset + i - 1 ] ; int nc = classmap . find ( c , 0 ) ; if ( nc < 0 ) { // found a non-letter character ... if ( i == ( 1 + iIgnoreAtBeginning ) ) { // ... before any letter character iIgnoreAtBeginning ++ ; } else { // ... after a letter character bEndOfLetters = true ; } iLength -- ; } else { if ( ! bEndOfLetters ) { word [ i - iIgnoreAtBeginning ] = ( char ) nc ; } else { return null ; } } } len = iLength ; if ( len < ( remainCharCount + pushCharCount ) ) { // word is too short to be hyphenated return null ; } int [ ] result = new int [ len + 1 ] ; int k = 0 ; // check exception list first String sw = new String ( word , 1 , len ) ; if ( stoplist . containsKey ( sw ) ) { // assume only simple hyphens (Hyphen.pre="-", Hyphen.post = Hyphen.no = null) ArrayList hw = ( ArrayList ) stoplist . get ( sw ) ; int j = 0 ; for ( i = 0 ; i < hw . size ( ) ; i ++ ) { Object o = hw . get ( i ) ; // j = index(sw) = letterindex(word)? // result[k] = corresponding index(w) if ( o instanceof String ) { j += ( ( String ) o ) . length ( ) ; if ( j >= remainCharCount && j < ( len - pushCharCount ) ) { result [ k ++ ] = j + iIgnoreAtBeginning ; } } } } else { // use algorithm to get hyphenation points word [ 0 ] = ' ' ; // word start marker word [ len + 1 ] = ' ' ; // word end marker word [ len + 2 ] = 0 ; // null terminated byte [ ] il = new byte [ len + 3 ] ; // initialized to zero for ( i = 0 ; i < len + 1 ; i ++ ) { searchPatterns ( word , i , il ) ; } // hyphenation points are located where interletter value is odd // i is letterindex(word), // i + 1 is index(word), // result[k] = corresponding index(w) for ( i = 0 ; i < len ; i ++ ) { if ( ( ( il [ i + 1 ] & 1 ) == 1 ) && i >= remainCharCount && i <= ( len - pushCharCount ) ) { result [ k ++ ] = i + iIgnoreAtBeginning ; } } } if ( k > 0 ) { // trim result array int [ ] res = new int [ k ] ; System . arraycopy ( result , 0 , res , 0 , k ) ; return new Hyphenation ( new String ( w , offset , len ) , res ) ; } else { return null ; } }
Hyphenate word and return an array of hyphenation points .