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();
}
}
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
}
}
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));
}
}
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());
}
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();
}
}
Aggregations