}
public static final int getPreviousWord(final Document doc, final int pos)
throws BadLocationException {
BreakIterator bi = BreakIterator.getWordInstance();
int length = doc.getLength();
if (pos < 0 || pos > length) {
throwException("No more words", pos);
}
String content = null;
content = doc.getText(0, doc.getLength());
bi.setText(content);
int iteratorPrevWord = bi.preceding(pos);
while (iteratorPrevWord > 0
&& ((content.charAt(iteratorPrevWord) == ' '
|| content.charAt(iteratorPrevWord) == '\n')
|| content.charAt(iteratorPrevWord) == '\t')) {
iteratorPrevWord = bi.preceding(iteratorPrevWord);
}
return iteratorPrevWord == -1 ? 0 : iteratorPrevWord;
}