当前位置: 首页>>代码示例>>Java>>正文


Java BreakIterator.first方法代码示例

本文整理汇总了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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:BreakIteratorTest.java

示例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;
}
 
开发者ID:remkop,项目名称:picocli,代码行数:19,代码来源:CommandLine.java

示例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();
}
 
开发者ID:kasirgalabs,项目名称:ETUmulator,代码行数:23,代码来源:SyntaxHighlighter.java

示例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());
    }
}
 
开发者ID:annoflex,项目名称:annoflex,代码行数:25,代码来源:TextFormatter.java

示例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;
}
 
开发者ID:AudiophileDev,项目名称:T2M,代码行数:32,代码来源:TextAnalyser.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Columns.java

示例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()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:LocalizedBundleInfo.java

示例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;
}
 
开发者ID:alisianoi,项目名称:lyra2-java,代码行数:15,代码来源:CommandLine.java

示例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.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:BreakIteratorTest.java

示例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));
       }
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:12,代码来源:WordDetection.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:MirroredBreakIterator.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:BreakIteratorTest.java

示例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();
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:53,代码来源:MultiLineLabel.java

示例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());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:CustomSeparatorBreakIteratorTests.java

示例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
                }
            }
        });
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:66,代码来源:InfoWindow.java


注:本文中的java.text.BreakIterator.first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。