本文整理汇总了Java中java.text.BreakIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java BreakIterator.next方法的具体用法?Java BreakIterator.next怎么用?Java BreakIterator.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.BreakIterator
的用法示例。
在下文中一共展示了BreakIterator.next方法的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: findWordLimit
import java.text.BreakIterator; //导入方法依赖的package包/类
/**
* Needed to unify forward and backward searching.
* The method assumes that s is the text assigned to words.
*/
private int findWordLimit(int index, BreakIterator words, boolean direction,
String s) {
// Fix for 4256660 and 4256661.
// Words iterator is different from character and sentence iterators
// in that end of one word is not necessarily start of another word.
// Please see java.text.BreakIterator JavaDoc. The code below is
// based on nextWordStartAfter example from BreakIterator.java.
int last = (direction == NEXT) ? words.following(index)
: words.preceding(index);
int current = (direction == NEXT) ? words.next()
: words.previous();
while (current != BreakIterator.DONE) {
for (int p = Math.min(last, current); p < Math.max(last, current); p++) {
if (Character.isLetter(s.charAt(p))) {
return last;
}
}
last = current;
current = (direction == NEXT) ? words.next()
: words.previous();
}
return BreakIterator.DONE;
}
示例5: 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());
}
}
示例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: 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);
}
示例10: 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);
}
示例11: 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.");
}
示例12: 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();
}
示例13: doOtherInvariantTest
import java.text.BreakIterator; //导入方法依赖的package包/类
private void doOtherInvariantTest(BreakIterator tb, String testChars)
{
StringBuffer work = new StringBuffer("a\r\na");
int errorCount = 0;
// a break should never occur between CR and LF
for (int i = 0; i < testChars.length(); i++) {
work.setCharAt(0, testChars.charAt(i));
for (int j = 0; j < testChars.length(); j++) {
work.setCharAt(3, testChars.charAt(j));
tb.setText(work.toString());
for (int k = tb.first(); k != BreakIterator.DONE; k = tb.next())
if (k == 2) {
errln("Break between CR and LF in string U+" + Integer.toHexString(
(int)(work.charAt(0))) + ", U+d U+a U+" + Integer.toHexString(
(int)(work.charAt(3))));
errorCount++;
if (errorCount >= 75)
return;
}
}
}
// a break should never occur before a non-spacing mark, unless it's preceded
// by a line terminator
work.setLength(0);
work.append("aaaa");
for (int i = 0; i < testChars.length(); i++) {
char c = testChars.charAt(i);
if (c == '\n' || c == '\r' || c == '\u2029' || c == '\u2028' || c == '\u0003')
continue;
work.setCharAt(1, c);
for (int j = 0; j < testChars.length(); j++) {
c = testChars.charAt(j);
if (Character.getType(c) != Character.NON_SPACING_MARK && Character.getType(c)
!= Character.ENCLOSING_MARK)
continue;
work.setCharAt(2, c);
// CONTROL (Cc) and FORMAT (Cf) Characters are to be ignored
// for breaking purposes as per UTR14
int type1 = Character.getType(work.charAt(1));
int type2 = Character.getType(work.charAt(2));
if (type1 == Character.CONTROL || type1 == Character.FORMAT ||
type2 == Character.CONTROL || type2 == Character.FORMAT) {
continue;
}
tb.setText(work.toString());
for (int k = tb.first(); k != BreakIterator.DONE; k = tb.next())
if (k == 2) {
errln("Break between U+" + Integer.toHexString((int)(work.charAt(1)))
+ " and U+" + Integer.toHexString((int)(work.charAt(2))));
errorCount++;
if (errorCount >= 75)
return;
}
}
}
}
示例14: _writeTextLineWithBreaks
import java.text.BreakIterator; //导入方法依赖的package包/类
private void _writeTextLineWithBreaks(
FacesContext context,
BreakIterator breaks,
String textString,
int columns
) throws IOException
{
if (textString.length() < columns)
{
context.getResponseWriter().writeText(textString, "value");
return;
}
breaks.setText(textString);
int lastStart = 0;
int previous = 0;
while (true)
{
int next = breaks.next();
if (next == BreakIterator.DONE)
{
context.getResponseWriter().writeText(textString.substring(lastStart),
null);
break;
}
if (next - lastStart > columns)
{
// Even if the first string in this line was too long,
// always output a complete line.
if (previous == lastStart)
previous = next;
String sub = textString.substring(lastStart, previous);
char[] chars = new char['\n'];
context.getResponseWriter().writeText(sub, null);
context.getResponseWriter().write(chars, 0, 1);
lastStart = previous;
}
previous = next;
}
}
示例15: getG2POutput
import java.text.BreakIterator; //导入方法依赖的package包/类
public void getG2POutput(String inputText) {
StringBuffer buffer = new StringBuffer();
BreakIterator sentenceIterator = BreakIterator.getSentenceInstance();
sentenceIterator.setText(inputText);
int start = sentenceIterator.first();
for (int end = sentenceIterator.next(); end != BreakIterator.DONE; start = end, end = sentenceIterator.next()) {
String sentenceText = inputText.substring(start, end).trim();
sentenceText = expandNumbers(sentenceText);
BreakIterator wordIterator = BreakIterator.getWordInstance();
wordIterator.setText(sentenceText);
int start2 = wordIterator.first();
for (int end2 = wordIterator.next(); end2 != BreakIterator.DONE; start2 = end2, end2 = wordIterator
.next()) {
String wordText = sentenceText.substring(start2, end2).trim();
if (wordText.length() > 0) {
boolean isPunctuation = true;
for (int i = 0; i < wordText.length(); i++) {
int codePoint = wordText.codePointAt(i);
if (Character.isAlphabetic(codePoint)) {
isPunctuation = false;
break;
}
}
if (!isPunctuation) {
Phoneme[] phonemes = performG2P(wordText);
for (int p = 0; p < phonemes.length; p++) {
buffer.append(phonemes[p].phoneme);
}
} else {
if (buffer.length() > 0) {
buffer.deleteCharAt(buffer.length() - 1);
}
buffer.append(wordText + " ");
continue;
}
if (wordText.equals(".")) {
} else {
}
buffer.append(" ");
}
}
buffer.append("\n");
}
}