public static int moveByWord(String text,int column,boolean forward,boolean returnCursorAtEnd){
  int curColumn=column;
  int length=text.length();
  int direction=forward ? 1 : -1;
  boolean farWordEnd=((direction == 1 && returnCursorAtEnd) || (direction == -1 && !returnCursorAtEnd));
  boolean foundEarlyMatch=false;
  if (!UnicodeUtils.isWhitespace(text.charAt(curColumn))) {
    curColumn=skipNonwhitespaceSimilar(text,curColumn,forward);
    if (farWordEnd && curColumn - direction != column) {
      curColumn-=direction;
      foundEarlyMatch=true;
    }
  }
  if (!foundEarlyMatch && curColumn >= 0 && curColumn < length) {
    curColumn=skipWhitespace(text,curColumn,forward);
    if (farWordEnd && curColumn >= 0 && curColumn < length) {
      curColumn=skipNonwhitespaceSimilar(text,curColumn,forward) - direction;
    }
  }
  if (curColumn < 0 || curColumn >= length) {
    return -1;
  }
  return curColumn;
}

public static int moveByWord ( String text , int column , boolean forward , boolean returnCursorAtEnd ) { int curColumn = column ; int length = text . length ( ) ; int direction = forward ? 1 : - 1 ; boolean farWordEnd = ( ( direction == 1 && returnCursorAtEnd ) || ( direction == - 1 && ! returnCursorAtEnd ) ) ; boolean foundEarlyMatch = false ; if ( ! UnicodeUtils . isWhitespace ( text . charAt ( curColumn ) ) ) { curColumn = skipNonwhitespaceSimilar ( text , curColumn , forward ) ; if ( farWordEnd && curColumn - direction != column ) { curColumn -= direction ; foundEarlyMatch = true ; } } if ( ! foundEarlyMatch && curColumn >= 0 && curColumn < length ) { curColumn = skipWhitespace ( text , curColumn , forward ) ; if ( farWordEnd && curColumn >= 0 && curColumn < length ) { curColumn = skipNonwhitespaceSimilar ( text , curColumn , forward ) - direction ; } } if ( curColumn < 0 || curColumn >= length ) { return - 1 ; } return curColumn ; }
jumps to the previous or next best match given the parameters below . this may be inside the current word . for example , if the cursor is at index 1 in " hey bob " , and movebyword is called with returncursoratend = true , then the returned value will be 2 ( y ) . if returncursoratend is false , it would return 4 ( b ) .
