|
What this is
Other links
The source code
package com.swabunga.spell.event;
/**
* A basic word finder, which searches text for sequences of letters.
*
* @author Anthony Roy (ajr@antroy.co.uk)
*/
public class DefaultWordFinder extends AbstractWordFinder {
//~ Instance/static variables ...............................................
//~ Constructors ............................................................
/**
* Creates a new DefaultWordFinder object.
*
* @param inText the String to search
*/
public DefaultWordFinder(String inText) {
super(inText);
}
public DefaultWordFinder() {
super();
}
//~ Methods .................................................................
/**
* This method scans the text from the end of the last word, and returns a
* new Word object corresponding to the next word.
*
* @return the next word.
* @throws WordNotFoundException search string contains no more words.
*/
public Word next() {
if (nextWord == null) {
throw new WordNotFoundException("No more words found.");
}
currentWord.copy(nextWord);
setSentenceIterator(currentWord);
int i = currentWord.getEnd();
boolean finished = false;
while (i < text.length() && !finished) {
if (isWordChar(i)) {
nextWord.setStart(i);
int end = getNextWordEnd(text, i);
nextWord.setText(text.substring(i, end));
finished = true;
}
i++;
}
if (!finished)
nextWord = null;
return currentWord;
}
/**
* Returns the position in the string after the end of the next word.
* Note that this return value should not be used as an index into the string
* without checking first that it is in range, since it is possible for the
* value
|
Copyright 1998-2008 Alvin Alexander
All Rights Reserved.
devdaily.com is based in louisville, kentucky, and this web site is hosted by godaddy.com