Java Code Examples for java.text.BreakIterator#getCharacterInstance()

The following examples show how to use java.text.BreakIterator#getCharacterInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BreakIteratorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testCache() {
    BreakIterator newOne = BreakIterator.getCharacterInstance(Locale.US);
    assertNotSame(newOne, iterator);
    assertEquals(newOne, iterator);

    newOne = BreakIterator.getCharacterInstance();
    assertEquals(newOne, iterator);

    newOne = BreakIterator.getCharacterInstance(Locale.CHINA);
    assertEquals(newOne, iterator);

    BreakIterator wordIterator = BreakIterator.getWordInstance();
    assertFalse(wordIterator.equals(iterator));

    BreakIterator lineIterator = BreakIterator.getLineInstance();
    assertFalse(lineIterator.equals(iterator));

    BreakIterator senteIterator = BreakIterator.getSentenceInstance();
    assertFalse(senteIterator.equals(iterator));
}
 
Example 2
Source File: SimpleTextLineWrapper.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void startParagraph(String text, int start, boolean truncateAtChar)
{
	paragraphText = text;
	paragraphTruncateAtChar = truncateAtChar;
	
	char[] textChars = text.toCharArray();
	// direction is per paragraph
	paragraphLeftToRight = isLeftToRight(textChars);
	paragraphMeasureExact = isParagraphMeasureExact(textChars);
	
	if (logTrace)
	{
		log.trace("paragraph start at " + start
				+ ", truncate at char " + truncateAtChar
				+ ", LTR " + paragraphLeftToRight
				+ ", exact measure " + paragraphMeasureExact);
	}
	
	paragraphOffset = start;
	paragraphPosition = 0;
	
	paragraphBreakIterator = truncateAtChar ? BreakIterator.getCharacterInstance()
			: BreakIterator.getLineInstance();
	paragraphBreakIterator.setText(paragraphText);
}
 
Example 3
Source File: TextServiceImpl.java    From olat with Apache License 2.0 6 votes vote down vote up
private int countCharacters(String text, Locale locale) {
    if (locale == null) {
        locale = I18nModule.getDefaultLocale();
    }

    int count = 0;
    BreakIterator characterIterator = BreakIterator.getCharacterInstance(locale);

    characterIterator.setText(text);
    int start = characterIterator.first();
    int end = characterIterator.next();
    while (end != BreakIterator.DONE) {
        char ch = text.charAt(start);
        if (Character.isLetterOrDigit(ch)) {
            count++;
        }
        start = end;
        end = characterIterator.next();
    }

    return count;
}
 
Example 4
Source File: BreakIteratorTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public BreakIteratorTest()
{
    characterBreak = BreakIterator.getCharacterInstance();
    wordBreak = BreakIterator.getWordInstance();
    lineBreak = BreakIterator.getLineInstance();
    sentenceBreak = BreakIterator.getSentenceInstance();
}
 
Example 5
Source File: BreakIteratorTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void TestCharacterInvariants()
{
    BreakIterator e = BreakIterator.getCharacterInstance();
    doBreakInvariantTest(e, cannedTestChars + "\u1100\u1101\u1102\u1160\u1161\u1162\u11a8"
        + "\u11a9\u11aa");
    doOtherInvariantTest(e, cannedTestChars + "\u1100\u1101\u1102\u1160\u1161\u1162\u11a8"
        + "\u11a9\u11aa");
}
 
Example 6
Source File: BreakIteratorTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public BreakIteratorTest()
{
    characterBreak = BreakIterator.getCharacterInstance();
    wordBreak = BreakIterator.getWordInstance();
    lineBreak = BreakIterator.getLineInstance();
    sentenceBreak = BreakIterator.getSentenceInstance();
}
 
Example 7
Source File: DatePicker.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * set / update the text of the displayLabels. these are the Week column
 * headers above the days on the Calendar part of the <code>CDateTime</code>
 * .
 */
private void updateDaysOfWeek() {
    if (dayPanel != null) {
        Calendar tmpcal = cdt.getCalendarInstance();
        tmpcal.set(Calendar.DAY_OF_WEEK, tmpcal.getFirstDayOfWeek());
        Locale locale = cdt.getLocale();
        boolean ltr = ComponentOrientation.getOrientation(locale)
                .isLeftToRight() && !locale.getLanguage().equals("zh"); //$NON-NLS-1$
        BreakIterator iterator = BreakIterator.getCharacterInstance(locale);
        for (VLabel dayLabel : dayLabels) {
            String str = getFormattedDate("E", tmpcal.getTime()); //$NON-NLS-1$
            if (dayLabel.getData(CDT.Key.Compact, Boolean.class)) {
                iterator.setText(str);
                int start, end;
                if (ltr) {
                    start = iterator.first();
                    end = iterator.next();
                } else {
                    end = iterator.last();
                    start = iterator.previous();
                }
                dayLabel.setText(str.substring(start, end));
            } else {
                dayLabel.setText(str);
            }
            tmpcal.add(Calendar.DAY_OF_WEEK, 1);
        }
    }
}
 
Example 8
Source File: BreakIteratorTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public BreakIteratorTest()
{
    characterBreak = BreakIterator.getCharacterInstance();
    wordBreak = BreakIterator.getWordInstance();
    lineBreak = BreakIterator.getLineInstance();
    sentenceBreak = BreakIterator.getSentenceInstance();
}
 
Example 9
Source File: BreakIteratorTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void TestCharacterInvariants()
{
    BreakIterator e = BreakIterator.getCharacterInstance();
    doBreakInvariantTest(e, cannedTestChars + "\u1100\u1101\u1102\u1160\u1161\u1162\u11a8"
        + "\u11a9\u11aa");
    doOtherInvariantTest(e, cannedTestChars + "\u1100\u1101\u1102\u1160\u1161\u1162\u11a8"
        + "\u11a9\u11aa");
}
 
Example 10
Source File: BreakIteratorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public BreakIteratorTest()
{
    characterBreak = BreakIterator.getCharacterInstance();
    wordBreak = BreakIterator.getWordInstance();
    lineBreak = BreakIterator.getLineInstance();
    sentenceBreak = BreakIterator.getSentenceInstance();
}
 
Example 11
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * parse a break iterator type for the specified locale
 */
protected BreakIterator parseBreakIterator(String type, Locale locale) {
  if (type == null || "SENTENCE".equals(type)) {
    return BreakIterator.getSentenceInstance(locale);
  } else if ("LINE".equals(type)) {
    return BreakIterator.getLineInstance(locale);
  } else if ("WORD".equals(type)) {
    return BreakIterator.getWordInstance(locale);
  } else if ("CHARACTER".equals(type)) {
    return BreakIterator.getCharacterInstance(locale);
  } else {
    throw new IllegalArgumentException("Unknown " + HighlightParams.BS_TYPE + ": " + type);
  }
}
 
Example 12
Source File: BreakIteratorTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    iterator = BreakIterator.getCharacterInstance(Locale.US);
}
 
Example 13
Source File: AccessibilityIterators.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
protected void onLocaleChanged(Locale locale) {
    mImpl = BreakIterator.getCharacterInstance(locale);
}
 
Example 14
Source File: GranularityIterator.java    From talkback with Apache License 2.0 4 votes vote down vote up
private CharacterTextSegmentIterator(Locale locale) {
  this(locale, BreakIterator.getCharacterInstance(locale));
}
 
Example 15
Source File: BreakIteratorTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    iterator = BreakIterator.getCharacterInstance(Locale.US);
}
 
Example 16
Source File: BreakIteratorTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void testGetCharacterInstance() {
    BreakIterator.getCharacterInstance();
}
 
Example 17
Source File: MongolEditText.java    From mongol-library with MIT License 4 votes vote down vote up
private int getFollowingCharIndex(int currentOffset) {
    BreakIterator boundary = BreakIterator.getCharacterInstance();
    boundary.setText(mTextStorage.toString());
    int following = boundary.following(currentOffset);
    return (following == BreakIterator.DONE) ? currentOffset : following;
}
 
Example 18
Source File: MongolEditText.java    From mongol-library with MIT License 4 votes vote down vote up
private int getPrecedingCharIndex(int currentOffset) {
    BreakIterator boundary = BreakIterator.getCharacterInstance();
    boundary.setText(mTextStorage.toString());
    int preceding = boundary.preceding(currentOffset);
    return (preceding == BreakIterator.DONE) ? currentOffset : preceding;
}
 
Example 19
Source File: BreakIteratorTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void testGetCharacterInstanceLocale() {
    BreakIterator it = BreakIterator.getCharacterInstance(Locale.US);
    BreakIterator it2 = BreakIterator.getCharacterInstance(Locale.CHINA);
    assertEquals(it, it2);
}
 
Example 20
Source File: Utilities.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/** Wrap multi-line strings (and get the individual lines).
* @param original  the original string to wrap
* @param width     the maximum width of lines
* @param wrapWords if <code>true</code>, the lines are wrapped on word boundaries (if possible);
*                  if <code>false</code>, character boundaries are used
* @param removeNewLines if <code>true</code>, any newlines in the original string are ignored
* @return the lines after wrapping
* @deprecated use {@link #wrapStringToArray(String, int, BreakIterator, boolean)} since it is better for I18N
*/
@Deprecated
public static String[] wrapStringToArray(String original, int width, boolean wrapWords, boolean removeNewLines) {
    BreakIterator bi = (wrapWords ? BreakIterator.getWordInstance() : BreakIterator.getCharacterInstance());

    return wrapStringToArray(original, width, bi, removeNewLines);
}