private int findWordLimit(int index,BreakIterator words,boolean direction,String s){
  int last=(direction == NEXT) ? words.following(index) : words.preceding(index);
  int current=(direction == NEXT) ? words.next() : words.previous();
  while (current != BreakIterator.DONE) {
    for (int p=Math.min(last,current); p < Math.max(last,current); p++) {
      if (Character.isLetter(s.charAt(p))) {
        return last;
      }
    }
    last=current;
    current=(direction == NEXT) ? words.next() : words.previous();
  }
  return BreakIterator.DONE;
}

private int findWordLimit ( int index , BreakIterator words , boolean direction , String s ) { int last = ( direction == NEXT ) ? words . following ( index ) : words . preceding ( index ) ; int current = ( direction == NEXT ) ? words . next ( ) : words . previous ( ) ; while ( current != BreakIterator . DONE ) { for ( int p = Math . min ( last , current ) ; p < Math . max ( last , current ) ; p ++ ) { if ( Character . isLetter ( s . charAt ( p ) ) ) { return last ; } } last = current ; current = ( direction == NEXT ) ? words . next ( ) : words . previous ( ) ; } return BreakIterator . DONE ; }
needed to unify forward and backward searching . the method assumes that s is the text assigned to words .
