There are 2 code examples for java.text.BreakIterator.
The API names are highlighted below.
You can use
button
to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.
Project Name: rssowl.ui Package: org.rssowl.ui.internal.views.explorer
Source Code: BookMarkFilter.java (Click to view .java file)
Method Code:
/**
* Take the given filter text and break it down into words using a
* BreakIterator.
* @param text
* @return an array of words
*/
private String[] getWords(String text){
List<String> words=new ArrayList<String>();
BreakIterator iter=BreakIterator.getWordInstance();
iter.setText(text);
int i=iter.first();
while (i != java.text.BreakIterator.DONE && i < text.length()) {
int j=iter.following(i);
if (j == java.text.BreakIterator.DONE) j=text.length();
if (Character.isLetterOrDigit(text.charAt(i))) {
String word=text.substring(i,j);
words.add(word);
}
i=j;
}
return words.toArray(new String[words.size()]);
}
Project Name: weka Package: weka.core
Source Code: Utils.java (Click to view .java file)
Method Code:
/**
* Breaks up the string, if wider than "columns" characters.
* @param s the string to process
* @param columns the width in columns
* @return the processed string
*/
public static String[] breakUp(String s,int columns){
Vector<String> result;
String line;
BreakIterator boundary;
int boundaryStart;
int boundaryEnd;
String word;
String punctuation;
int i;
String[] lines;
result=new Vector<String>();
punctuation=" .,;:!?'\"";
lines=s.split("\n");
for (i=0; i < lines.length; i++) {
boundary=BreakIterator.getWordInstance();
boundary.setText(lines[i]);
boundaryStart=boundary.first();
boundaryEnd=boundary.next();
line="";
while (boundaryEnd != BreakIterator.DONE) {
word=lines[i].substring(boundaryStart,boundaryEnd);
if (line.length() >= columns) {
if (word.length() == 1) {
if (punctuation.indexOf(word.charAt(0)) > -1) {
line+=word;
word="";
}
}
result.add(line);
line="";
}
line+=word;
boundaryStart=boundaryEnd;
boundaryEnd=boundary.next();
}
if (line.length() > 0) result.add(line);
}
return result.toArray(new String[result.size()]);
}