Search in sources :

Example 61 with BreakIterator

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

the class BreakIteratorTest method testConcurrentBreakIteratorAccess.

// http://code.google.com/p/android/issues/detail?id=41143
// This code is inherently unsafe and crazy;
// we're just trying to provoke native crashes!
public void testConcurrentBreakIteratorAccess() throws Exception {
    final BreakIterator it = BreakIterator.getCharacterInstance();
    ArrayList<Thread> threads = new ArrayList<Thread>();
    for (int i = 0; i < 10; ++i) {
        Thread t = new Thread(new Runnable() {

            public void run() {
                for (int i = 0; i < 4096; ++i) {
                    it.setText("some example text");
                    for (int index = it.first(); index != BreakIterator.DONE; index = it.next()) {
                    }
                }
            }
        });
        threads.add(t);
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
}
Also used : ArrayList(java.util.ArrayList) BreakIterator(java.text.BreakIterator)

Example 62 with BreakIterator

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

the class BreakIteratorTest method testFollowing.

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

Example 63 with BreakIterator

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

the class BreakIteratorTest method testStress.

// http://b/7307154 - we used to pin an unbounded number of char[]s, relying on finalization.
public void testStress() throws Exception {
    char[] cs = { 'a' };
    for (int i = 0; i < 4096; ++i) {
        BreakIterator it = BreakIterator.getWordInstance(Locale.US);
        it.setText(new String(cs));
    }
}
Also used : BreakIterator(java.text.BreakIterator)

Example 64 with BreakIterator

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

the class BreakIteratorTest method testGetWordInstanceLocale.

public void testGetWordInstanceLocale() {
    BreakIterator it1 = BreakIterator.getWordInstance(Locale.CANADA_FRENCH);
    assertTrue("Incorrect BreakIterator", it1 != BreakIterator.getWordInstance());
    BreakIterator it2 = BreakIterator.getWordInstance(new Locale("bad locale"));
    assertTrue("Incorrect BreakIterator", it2 != BreakIterator.getWordInstance());
}
Also used : Locale(java.util.Locale) BreakIterator(java.text.BreakIterator)

Example 65 with BreakIterator

use of java.text.BreakIterator in project geode by apache.

the class LogWriterImpl method formatText.

static void formatText(PrintWriter writer, String target, int initialLength) {
    BreakIterator boundary = BreakIterator.getLineInstance();
    boundary.setText(target);
    int start = boundary.first();
    int end = boundary.next();
    int lineLength = initialLength;
    while (end != BreakIterator.DONE) {
        // Look at the end and only accept whitespace breaks
        char endChar = target.charAt(end - 1);
        while (!Character.isWhitespace(endChar)) {
            int lastEnd = end;
            end = boundary.next();
            if (end == BreakIterator.DONE) {
                // give up. We are at the end of the string
                end = lastEnd;
                break;
            }
            endChar = target.charAt(end - 1);
        }
        int wordEnd = end;
        if (endChar == '\n') {
            // trim off the \n since println will do it for us
            wordEnd--;
            if (wordEnd > 0 && target.charAt(wordEnd - 1) == '\r') {
                wordEnd--;
            }
        } else if (endChar == '\t') {
            // figure tabs use 8 characters
            lineLength += 7;
        }
        String word = target.substring(start, wordEnd);
        lineLength += word.length();
        writer.print(word);
        if (endChar == '\n' || endChar == '\r') {
            // force end of line
            writer.println();
            writer.print("  ");
            lineLength = 2;
        }
        start = end;
        end = boundary.next();
    }
    if (lineLength != 0) {
        writer.println();
    }
}
Also used : BreakIterator(java.text.BreakIterator)

Aggregations

BreakIterator (java.text.BreakIterator)120 ArrayList (java.util.ArrayList)17 Locale (java.util.Locale)9 Paint (android.graphics.Paint)4 IntPair (edu.illinois.cs.cogcomp.core.datastructures.IntPair)3 BytesRef (org.apache.lucene.util.BytesRef)3 SuppressLint (android.annotation.SuppressLint)2 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)2 Collection (java.util.Collection)2 BadLocationException (javax.swing.text.BadLocationException)2 Document (javax.swing.text.Document)2 Element (javax.swing.text.Element)2 Segment (javax.swing.text.Segment)2 Snippet (org.apache.lucene.search.highlight.Snippet)2 Intent (android.content.Intent)1 RectF (android.graphics.RectF)1 TextPaint (android.text.TextPaint)1 TagElement (com.google.devtools.j2objc.ast.TagElement)1 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)1 AbstractNLPDecoder (edu.emory.mathcs.nlp.decode.AbstractNLPDecoder)1