Search in sources :

Example 11 with BreakIterator

use of java.text.BreakIterator in project robovm by robovm.

the class BreakIteratorTest method testPreceding.

public void testPreceding() {
    BreakIterator it = BreakIterator.getCharacterInstance(Locale.US);
    it.setText("hello");
    try {
        it.preceding(-1);
        fail();
    } catch (IllegalArgumentException expected) {
    // Expected exception
    }
    assertEquals(BreakIterator.DONE, it.preceding(0));
    assertEquals(0, it.preceding(1));
    assertEquals(4, it.preceding(5));
    try {
        it.preceding(6);
        fail();
    } catch (IllegalArgumentException expected) {
    // Expected exception
    }
}
Also used : BreakIterator(java.text.BreakIterator)

Example 12 with BreakIterator

use of java.text.BreakIterator in project robovm by robovm.

the class BreakIteratorTest method testWordBoundaries.

public void testWordBoundaries() {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 1024; ++i) {
        if (i > 0) {
            sb.append(' ');
        }
        sb.append("12345");
    }
    String s = sb.toString();
    BreakIterator it = BreakIterator.getWordInstance(Locale.US);
    it.setText(s);
    // Check we're not leaking global references. 2048 would bust the VM's hard-coded limit.
    for (int i = 0; i < 2048; ++i) {
        it.setText(s);
    }
    BreakIterator clone = (BreakIterator) it.clone();
    assertExpectedWordBoundaries(it, s);
    assertExpectedWordBoundaries(clone, s);
}
Also used : BreakIterator(java.text.BreakIterator)

Example 13 with BreakIterator

use of java.text.BreakIterator in project robovm by robovm.

the class BreakIteratorTest method testIsBoundary.

public void testIsBoundary() {
    BreakIterator it = BreakIterator.getCharacterInstance(Locale.US);
    it.setText("hello");
    try {
        it.isBoundary(-1);
        fail();
    } catch (IllegalArgumentException expected) {
    // Note that this exception is not listed in the Java API documentation
    }
    assertTrue(it.isBoundary(0));
    assertTrue(it.isBoundary(1));
    assertTrue(it.isBoundary(4));
    assertTrue(it.isBoundary(5));
    try {
        it.isBoundary(6);
        fail();
    } catch (IllegalArgumentException expected) {
    // Note that this exception is not listed in the Java API documentation
    }
}
Also used : BreakIterator(java.text.BreakIterator)

Example 14 with BreakIterator

use of java.text.BreakIterator in project spring-boot by spring-projects.

the class DescriptionExtractor method getShortDescription.

public String getShortDescription(String description) {
    if (description == null) {
        return null;
    }
    int dot = description.indexOf(".");
    if (dot != -1) {
        BreakIterator breakIterator = BreakIterator.getSentenceInstance(Locale.US);
        breakIterator.setText(description);
        String text = description.substring(breakIterator.first(), breakIterator.next()).trim();
        return removeSpaceBetweenLine(text);
    } else {
        String[] lines = description.split(NEW_LINE);
        return lines[0].trim();
    }
}
Also used : BreakIterator(java.text.BreakIterator)

Example 15 with BreakIterator

use of java.text.BreakIterator in project bazel by bazelbuild.

the class OptionsUsage method paragraphFill.

/**
   * Paragraph-fill the specified input text, indenting lines to 'indent' and
   * wrapping lines at 'width'.  Returns the formatted result.
   */
static String paragraphFill(String in, int indent, int width) {
    String indentString = Strings.repeat(" ", indent);
    StringBuilder out = new StringBuilder();
    String sep = "";
    for (String paragraph : NEWLINE_SPLITTER.split(in)) {
        // (factory)
        BreakIterator boundary = BreakIterator.getLineInstance();
        boundary.setText(paragraph);
        out.append(sep).append(indentString);
        int cursor = indent;
        for (int start = boundary.first(), end = boundary.next(); end != BreakIterator.DONE; start = end, end = boundary.next()) {
            String word = // (may include trailing space)
            paragraph.substring(start, end);
            if (word.length() + cursor > width) {
                out.append('\n').append(indentString);
                cursor = indent;
            }
            out.append(word);
            cursor += word.length();
        }
        sep = "\n";
    }
    return out.toString();
}
Also used : BreakIterator(java.text.BreakIterator)

Aggregations

BreakIterator (java.text.BreakIterator)59 ArrayList (java.util.ArrayList)10 Locale (java.util.Locale)6 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)3 BytesRef (org.apache.lucene.util.BytesRef)3 Snippet (org.apache.lucene.search.highlight.Snippet)2 Intent (android.content.Intent)1 TagElement (com.google.devtools.j2objc.ast.TagElement)1 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)1 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 PriorityQueue (java.util.PriorityQueue)1 JComponent (javax.swing.JComponent)1 Text (org.apache.hadoop.io.Text)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Encoder (org.apache.lucene.search.highlight.Encoder)1 CustomSeparatorBreakIterator (org.apache.lucene.search.postingshighlight.CustomSeparatorBreakIterator)1 CustomPassageFormatter (org.apache.lucene.search.uhighlight.CustomPassageFormatter)1