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