本文整理汇总了Java中java.text.BreakIterator.first方法的典型用法代码示例。如果您正苦于以下问题:Java BreakIterator.first方法的具体用法?Java BreakIterator.first怎么用?Java BreakIterator.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.BreakIterator
的用法示例。
在下文中一共展示了BreakIterator.first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFirstAndNext
import java.text.BreakIterator; //导入方法依赖的package包/类
private Vector testFirstAndNext(BreakIterator bi, String text) {
int p = bi.first();
int lastP = p;
Vector<String> result = new Vector<String>();
if (p != 0)
errln("first() returned " + p + " instead of 0");
while (p != BreakIterator.DONE) {
p = bi.next();
if (p != BreakIterator.DONE) {
if (p <= lastP)
errln("next() failed to move forward: next() on position "
+ lastP + " yielded " + p);
result.addElement(text.substring(lastP, p));
}
else {
if (lastP != text.length())
errln("next() returned DONE prematurely: offset was "
+ lastP + " instead of " + text.length());
}
lastP = p;
}
return result;
}
示例2: copy
import java.text.BreakIterator; //导入方法依赖的package包/类
private int copy(BreakIterator line, Text text, Text columnValue, int offset) {
// Deceive the BreakIterator to ensure no line breaks after '-' character
line.setText(text.plainString().replace("-", "\u00ff"));
int done = 0;
for (int start = line.first(), end = line.next(); end != BreakIterator.DONE; start = end, end = line.next()) {
Text word = text.substring(start, end); //.replace("\u00ff", "-"); // not needed
if (columnValue.maxLength >= offset + done + length(word)) {
done += copy(word, columnValue, offset + done); // TODO localized length
} else {
break;
}
}
if (done == 0 && length(text) > columnValue.maxLength) {
// The value is a single word that is too big to be written to the column. Write as much as we can.
done = copy(text, columnValue, offset);
}
return done;
}
示例3: highlightMisspelled
import java.text.BreakIterator; //导入方法依赖的package包/类
private StyleSpans<Collection<String>> highlightMisspelled(String text) {
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
BreakIterator wb = BreakIterator.getWordInstance();
wb.setText(text);
int lastIndex = wb.first();
int lastKeywordEnd = 0;
while(lastIndex != BreakIterator.DONE) {
int firstIndex = lastIndex;
lastIndex = wb.next();
if(lastIndex != BreakIterator.DONE
&& Character.isLetterOrDigit(text.charAt(firstIndex))) {
String word = text.substring(firstIndex, lastIndex).toLowerCase();
if(!dictionary.contains(word)) {
spansBuilder.add(Collections.emptyList(), firstIndex - lastKeywordEnd);
spansBuilder.add(Collections.singleton("underlined"), lastIndex - firstIndex);
lastKeywordEnd = lastIndex;
}
}
}
spansBuilder.add(Collections.emptyList(), text.length() - lastKeywordEnd);
return spansBuilder.create();
}
示例4: layoutFragments
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
*
*/
private void layoutFragments() {
BreakIterator breakIterator = createBreakIterator();
breakIterator.setText(text);
int fragmentStart = 0;
int fragmentEnd = breakIterator.first();
if (fragmentEnd == 0) {
fragmentEnd = breakIterator.next();
}
while (fragmentEnd != BreakIterator.DONE) {
layoutFragment(fragmentStart,fragmentEnd);
fragmentStart = fragmentEnd;
fragmentEnd = breakIterator.next();
}
if (fragmentStart < text.length()) {
layoutFragment(fragmentStart,text.length());
}
}
示例5: splitSentences
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Splits string into sentences by line breaks and punctuation marks.
*
* @param text the text to be split
* @return Sentences as string array
* @see java.text.BreakIterator#getSentenceInstance(Locale)
*/
private static String[] splitSentences(String text) {
BreakIterator iterator = BreakIterator.getSentenceInstance(Locale.GERMAN);
iterator.setText(text);
ArrayList<String> sentenceList = new ArrayList<>(text.length() / 6); // Avg word length in german is 5.7
int start = iterator.first();
for (int end = iterator.next();
end != BreakIterator.DONE;
start = end, end = iterator.next()) {
String sentence = text.substring(start, end).trim();
// Exclude empty sentences
if (sentence.length() > 0) {
Stream.of(sentence.split("\n"))
.filter(s -> s.length() > 0 && !s.equals("\r"))
.forEach(sentenceList::add);
}
}
sentenceList.trimToSize(); // Remove unused indices
// Convert ArrayList to array
String[] sentences = new String[sentenceList.size()];
sentenceList.toArray(sentences);
return sentences;
}
示例6: piecesOfEmbeddedLine
import java.text.BreakIterator; //导入方法依赖的package包/类
private List<String> piecesOfEmbeddedLine( String line, int width ) {
List<String> pieces = new ArrayList<String>();
BreakIterator words = BreakIterator.getLineInstance( Locale.US );
words.setText( line );
StringBuilder nextPiece = new StringBuilder();
int start = words.first();
for ( int end = words.next(); end != DONE; start = end, end = words.next() )
nextPiece = processNextWord( line, nextPiece, start, end, width, pieces );
if ( nextPiece.length() > 0 )
pieces.add( nextPiece.toString() );
return pieces;
}
示例7: splitBySentence
import java.text.BreakIterator; //导入方法依赖的package包/类
private static String[] splitBySentence(String text) {
List<String> sentences = new ArrayList<String>();
// Use Locale.US since the customizer is setting the default (US) locale text only:
BreakIterator it = BreakIterator.getSentenceInstance(Locale.US);
it.setText(text);
int start = it.first();
int end;
while ((end = it.next()) != BreakIterator.DONE) {
sentences.add(text.substring(start, end));
start = end;
}
return sentences.toArray(new String[sentences.size()]);
}
示例8: copy
import java.text.BreakIterator; //导入方法依赖的package包/类
private int copy(BreakIterator line, Text text, Text columnValue, int offset) {
// Deceive the BreakIterator to ensure no line breaks after '-' character
line.setText(text.plainString().replace("-", "\u00ff"));
int done = 0;
for (int start = line.first(), end = line.next(); end != BreakIterator.DONE; start = end, end = line.next()) {
Text word = text.substring(start, end); //.replace("\u00ff", "-"); // not needed
if (columnValue.maxLength >= offset + done + length(word)) {
done += copy(word, columnValue, offset + done); // TODO localized length
} else {
break;
}
}
return done;
}
示例9: TestEndBehavior
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Bug 4068137
*/
public void TestEndBehavior()
{
String testString = "boo.";
BreakIterator wb = BreakIterator.getWordInstance();
wb.setText(testString);
if (wb.first() != 0)
errln("Didn't get break at beginning of string.");
if (wb.next() != 3)
errln("Didn't get break before period in \"boo.\"");
if (wb.current() != 4 && wb.next() != 4)
errln("Didn't get break at end of string.");
}
示例10: useBreakIterator
import java.text.BreakIterator; //导入方法依赖的package包/类
public void useBreakIterator(String input){
System.out.println("Break Iterator");
BreakIterator tokenizer = BreakIterator.getWordInstance();
tokenizer.setText(input);
int start = tokenizer.first();
for (int end = tokenizer.next();
end != BreakIterator.DONE;
start = end, end = tokenizer.next()) {
System.out.println(input.substring(start,end));
}
}
示例11: MirroredBreakIterator
import java.text.BreakIterator; //导入方法依赖的package包/类
MirroredBreakIterator(BreakIterator bi) {
List<Integer> b = new ArrayList<Integer>();
int i = bi.first();
charIndex = i;
for (; i != DONE; i = bi.next()) {
b.add(i);
}
boundaries = Collections.unmodifiableList(b);
}
示例12: doMultipleSelectionTest
import java.text.BreakIterator; //导入方法依赖的package包/类
private void doMultipleSelectionTest(BreakIterator iterator, String testText)
{
logln("Multiple selection test...");
BreakIterator testIterator = (BreakIterator)iterator.clone();
int offset = iterator.first();
int testOffset;
int count = 0;
do {
testOffset = testIterator.first();
testOffset = testIterator.next(count);
logln("next(" + count + ") -> " + testOffset);
if (offset != testOffset)
errln("next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset);
if (offset != BreakIterator.DONE) {
count++;
offset = iterator.next();
}
} while (offset != BreakIterator.DONE);
// now do it backwards...
offset = iterator.last();
count = 0;
do {
testOffset = testIterator.last();
testOffset = testIterator.next(count);
logln("next(" + count + ") -> " + testOffset);
if (offset != testOffset)
errln("next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset);
if (offset != BreakIterator.DONE) {
count--;
offset = iterator.previous();
}
} while (offset != BreakIterator.DONE);
}
示例13: wrapText
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
*
* @param toWrap
* The string on which the line wrapping process should be done
* @param maxLength
* The maximum length per line
* @return The StringBuffer with the wrapped lines
*/
public static String wrapText(final String toWrap, final int maxLength)
{
if (maxLength == 0) throw new IllegalArgumentException("maxLength must not be 0");
StringBuffer ret = new StringBuffer();
BreakIterator boundary = BreakIterator.getLineInstance();
boundary.setText(toWrap);
int realEnd = BreakIterator.DONE;
int start = boundary.first();
int end = boundary.next();
int lineLength = 0;
while (end != BreakIterator.DONE)
{
int charCount = end - start - 1;
if (charCount > maxLength)
{
realEnd = end;
end = start + maxLength;
}
String word = toWrap.substring(start, end);
lineLength = lineLength + word.length();
if (lineLength >= maxLength)
{
ret.append("\n");
lineLength = word.length();
}
ret.append(word);
if (realEnd == BreakIterator.DONE)
{
start = end;
end = boundary.next();
}
else
{
start = end;
end = realEnd;
realEnd = BreakIterator.DONE;
}
}
return ret.toString();
}
示例14: assertSameBreaks
import java.text.BreakIterator; //导入方法依赖的package包/类
/** Asserts that two breakiterators break the text the same way */
private static void assertSameBreaks(CharacterIterator one, CharacterIterator two, BreakIterator expected, BreakIterator actual) {
expected.setText(one);
actual.setText(two);
assertEquals(expected.current(), actual.current());
// next()
int v = expected.current();
while (v != BreakIterator.DONE) {
assertEquals(v = expected.next(), actual.next());
assertEquals(expected.current(), actual.current());
}
// first()
assertEquals(expected.first(), actual.first());
assertEquals(expected.current(), actual.current());
// last()
assertEquals(expected.last(), actual.last());
assertEquals(expected.current(), actual.current());
// previous()
v = expected.current();
while (v != BreakIterator.DONE) {
assertEquals(v = expected.previous(), actual.previous());
assertEquals(expected.current(), actual.current());
}
// following()
for (int i = one.getBeginIndex(); i <= one.getEndIndex(); i++) {
expected.first();
actual.first();
assertEquals(expected.following(i), actual.following(i));
assertEquals(expected.current(), actual.current());
}
// preceding()
for (int i = one.getBeginIndex(); i <= one.getEndIndex(); i++) {
expected.last();
actual.last();
assertEquals(expected.preceding(i), actual.preceding(i));
assertEquals(expected.current(), actual.current());
}
}
示例15: _display
import java.text.BreakIterator; //导入方法依赖的package包/类
private void _display(String caption, String text, String messageType) {
captionLabel.setText(caption);
BreakIterator iter = BreakIterator.getWordInstance();
if (text != null) {
iter.setText(text);
int start = iter.first(), end;
int nLines = 0;
do {
end = iter.next();
if (end == BreakIterator.DONE ||
text.substring(start, end).length() >= 50)
{
lineLabels[nLines].setText(text.substring(start, end == BreakIterator.DONE ?
iter.last() : end));
textPanel.add(lineLabels[nLines++]);
start = end;
}
if (nLines == BALLOON_WORD_LINE_MAX_COUNT) {
if (end != BreakIterator.DONE) {
lineLabels[nLines - 1].setText(
new String(lineLabels[nLines - 1].getText() + " ..."));
}
break;
}
} while (end != BreakIterator.DONE);
textPanel.setLayout(new GridLayout(nLines, 1));
}
if ("ERROR".equals(messageType)) {
iconImage = errorImage;
} else if ("WARNING".equals(messageType)) {
iconImage = warnImage;
} else if ("INFO".equals(messageType)) {
iconImage = infoImage;
} else {
iconImage = null;
}
if (iconImage != null) {
Dimension tpSize = textPanel.getSize();
iconCanvas.setSize(BALLOON_ICON_WIDTH, (BALLOON_ICON_HEIGHT > tpSize.height ?
BALLOON_ICON_HEIGHT : tpSize.height));
iconCanvas.validate();
}
SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
public void run() {
if (liveArguments.isDisposed()) {
return;
}
Point parLoc = getParent().getLocationOnScreen();
Dimension parSize = getParent().getSize();
show(new Point(parLoc.x + parSize.width/2, parLoc.y + parSize.height/2),
BALLOON_TRAY_ICON_INDENT);
if (iconImage != null) {
iconCanvas.updateImage(iconImage); // call it after the show(..) above
}
}
});
}