当前位置: 首页>>代码示例>>Java>>正文


Java BreakIterator.setText方法代码示例

本文整理汇总了Java中java.text.BreakIterator.setText方法的典型用法代码示例。如果您正苦于以下问题:Java BreakIterator.setText方法的具体用法?Java BreakIterator.setText怎么用?Java BreakIterator.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.BreakIterator的用法示例。


在下文中一共展示了BreakIterator.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: layoutFragments

import java.text.BreakIterator; //导入方法依赖的package包/类
/**
 * 
 */
private void layoutFragments() {
    BreakIterator breakIterator = createBreakIterator();
    breakIterator.setText(text);
    
    int fragmentStart = 0;
    int fragmentEnd = breakIterator.first();
    
    if (fragmentEnd == 0) {
        fragmentEnd = breakIterator.next();
    }
    
    while (fragmentEnd != BreakIterator.DONE) {
        layoutFragment(fragmentStart,fragmentEnd);
        fragmentStart = fragmentEnd;
        fragmentEnd = breakIterator.next();
    }
    
    if (fragmentStart < text.length()) {
        layoutFragment(fragmentStart,text.length());
    }
}
 
开发者ID:annoflex,项目名称:annoflex,代码行数:25,代码来源:TextFormatter.java

示例2: piecesOfEmbeddedLine

import java.text.BreakIterator; //导入方法依赖的package包/类
private List<String> piecesOfEmbeddedLine( String line, int width ) {
    List<String> pieces = new ArrayList<String>();

    BreakIterator words = BreakIterator.getLineInstance( Locale.US );
    words.setText( line );

    StringBuilder nextPiece = new StringBuilder();

    int start = words.first();
    for ( int end = words.next(); end != DONE; start = end, end = words.next() )
        nextPiece = processNextWord( line, nextPiece, start, end, width, pieces );

    if ( nextPiece.length() > 0 )
        pieces.add( nextPiece.toString() );

    return pieces;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Columns.java

示例3: getSegmentAt

import java.text.BreakIterator; //导入方法依赖的package包/类
/**
 * Returns the Segment at <code>index</code> representing either
 * the paragraph or sentence as identified by <code>part</code>, or
 * null if a valid paragraph/sentence can't be found. The offset
 * will point to the start of the word/sentence in the array, and
 * the modelOffset will point to the location of the word/sentence
 * in the model.
 */
private IndexedSegment getSegmentAt(int part, int index)
    throws BadLocationException {

    IndexedSegment seg = getParagraphElementText(index);
    if (seg == null) {
        return null;
    }
    BreakIterator iterator;
    switch (part) {
    case AccessibleText.WORD:
        iterator = BreakIterator.getWordInstance(getLocale());
        break;
    case AccessibleText.SENTENCE:
        iterator = BreakIterator.getSentenceInstance(getLocale());
        break;
    default:
        return null;
    }
    seg.first();
    iterator.setText(seg);
    int end = iterator.following(index - seg.modelOffset + seg.offset);
    if (end == BreakIterator.DONE) {
        return null;
    }
    if (end > seg.offset + seg.count) {
        return null;
    }
    int begin = iterator.previous();
    if (begin == BreakIterator.DONE ||
        begin >= seg.offset + seg.count) {
        return null;
    }
    seg.modelOffset = seg.modelOffset + begin - seg.offset;
    seg.offset = begin;
    seg.count = end - begin;
    return seg;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:46,代码来源:AccessibleHTML.java

示例4: splitBySentence

import java.text.BreakIterator; //导入方法依赖的package包/类
private static String[] splitBySentence(String text) {
    List<String> sentences = new ArrayList<String>();
    // Use Locale.US since the customizer is setting the default (US) locale text only:
    BreakIterator it = BreakIterator.getSentenceInstance(Locale.US);
    it.setText(text);
    int start = it.first();
    int end;
    while ((end = it.next()) != BreakIterator.DONE) {
        sentences.add(text.substring(start, end));
        start = end;
    }
    return sentences.toArray(new String[sentences.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:LocalizedBundleInfo.java

示例5: copy

import java.text.BreakIterator; //导入方法依赖的package包/类
private int copy(BreakIterator line, Text text, Text columnValue, int offset) {
    // Deceive the BreakIterator to ensure no line breaks after '-' character
    line.setText(text.plainString().replace("-", "\u00ff"));
    int done = 0;
    for (int start = line.first(), end = line.next(); end != BreakIterator.DONE; start = end, end = line.next()) {
        Text word = text.substring(start, end); //.replace("\u00ff", "-"); // not needed
        if (columnValue.maxLength >= offset + done + length(word)) {
            done += copy(word, columnValue, offset + done); // TODO localized length
        } else {
            break;
        }
    }
    return done;
}
 
开发者ID:alisianoi,项目名称:lyra2-java,代码行数:15,代码来源:CommandLine.java

示例6: onDoubleTap

import java.text.BreakIterator; //导入方法依赖的package包/类
@Override
public boolean onDoubleTap(MotionEvent e) {

    int x = (int) e.getX();
    int y = (int) e.getY();

    // find the position
    int offset = getOffsetForPosition(x, y);

    // select word
    BreakIterator iterator = BreakIterator.getWordInstance();
    iterator.setText(getText().toString());

    // start and end are the word boundaries;
    int start;
    if (iterator.isBoundary(offset)) {
        start = offset;
    } else {
        start = iterator.preceding(offset);
    }
    int end = iterator.following(offset);

    // handle tapping at the very beginning or end.
    if (end == BreakIterator.DONE) {
        end = start;
        start = iterator.preceding(offset);
        if (start == BreakIterator.DONE) start = end;
    }

    setSelection(start, end);

    return super.onDoubleTap(e);
}
 
开发者ID:suragch,项目名称:mongol-library,代码行数:34,代码来源:MongolEditText.java

示例7: isFinalCased

import java.text.BreakIterator; //导入方法依赖的package包/类
/**
 * Implements the "Final_Cased" condition
 *
 * Specification: Within the closest word boundaries containing C, there is a cased
 * letter before C, and there is no cased letter after C.
 *
 * Regular Expression:
 *   Before C: [{cased==true}][{wordBoundary!=true}]*
 *   After C: !([{wordBoundary!=true}]*[{cased}])
 */
private static boolean isFinalCased(String src, int index, Locale locale) {
    BreakIterator wordBoundary = BreakIterator.getWordInstance(locale);
    wordBoundary.setText(src);
    int ch;

    // Look for a preceding 'cased' letter
    for (int i = index; (i >= 0) && !wordBoundary.isBoundary(i);
            i -= Character.charCount(ch)) {

        ch = src.codePointBefore(i);
        if (isCased(ch)) {

            int len = src.length();
            // Check that there is no 'cased' letter after the index
            for (i = index + Character.charCount(src.codePointAt(index));
                    (i < len) && !wordBoundary.isBoundary(i);
                    i += Character.charCount(ch)) {

                ch = src.codePointAt(i);
                if (isCased(ch)) {
                    return false;
                }
            }

            return true;
        }
    }

    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:ConditionalSpecialCasing.java

示例8: useBreakIterator

import java.text.BreakIterator; //导入方法依赖的package包/类
public void useBreakIterator(String input){
	System.out.println("Break Iterator");
	BreakIterator tokenizer = BreakIterator.getWordInstance();
       tokenizer.setText(input);
       int start = tokenizer.first();
       for (int end = tokenizer.next();
            end != BreakIterator.DONE;
            start = end, end = tokenizer.next()) {
            System.out.println(input.substring(start,end));
       }
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:12,代码来源:WordDetection.java

示例9: generalIteratorTest

import java.text.BreakIterator; //导入方法依赖的package包/类
private void generalIteratorTest(BreakIterator bi, Vector expectedResult) {
    StringBuffer buffer = new StringBuffer();
    String text;
    for (int i = 0; i < expectedResult.size(); i++) {
        text = (String)expectedResult.elementAt(i);
        buffer.append(text);
    }
    text = buffer.toString();

    bi.setText(text);

    Vector nextResults = testFirstAndNext(bi, text);
    Vector previousResults = testLastAndPrevious(bi, text);

    logln("comparing forward and backward...");
    int errs = getErrorCount();
    compareFragmentLists("forward iteration", "backward iteration", nextResults,
                    previousResults);
    if (getErrorCount() == errs) {
        logln("comparing expected and actual...");
        compareFragmentLists("expected result", "actual result", expectedResult,
                        nextResults);
    }

    int[] boundaries = new int[expectedResult.size() + 3];
    boundaries[0] = BreakIterator.DONE;
    boundaries[1] = 0;
    for (int i = 0; i < expectedResult.size(); i++)
        boundaries[i + 2] = boundaries[i + 1] + ((String)expectedResult.elementAt(i)).
                        length();
    boundaries[boundaries.length - 1] = BreakIterator.DONE;

    testFollowing(bi, text, boundaries);
    testPreceding(bi, text, boundaries);
    testIsBoundary(bi, text, boundaries);

    doMultipleSelectionTest(bi, text);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:BreakIteratorTest.java

示例10: TestEndBehavior

import java.text.BreakIterator; //导入方法依赖的package包/类
/**
 * Bug 4068137
 */
public void TestEndBehavior()
{
    String testString = "boo.";
    BreakIterator wb = BreakIterator.getWordInstance();
    wb.setText(testString);

    if (wb.first() != 0)
        errln("Didn't get break at beginning of string.");
    if (wb.next() != 3)
        errln("Didn't get break before period in \"boo.\"");
    if (wb.current() != 4 && wb.next() != 4)
        errln("Didn't get break at end of string.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:BreakIteratorTest.java

示例11: doBreakInvariantTest

import java.text.BreakIterator; //导入方法依赖的package包/类
private void doBreakInvariantTest(BreakIterator tb, String testChars)
{
    StringBuffer work = new StringBuffer("aaa");
    int errorCount = 0;

    // a break should always occur after CR (unless followed by LF), LF, PS, and LS
    String breaks = /*"\r\n\u2029\u2028"*/"\n\u2029\u2028";
                        // change this back when new BI code is added

    for (int i = 0; i < breaks.length(); i++) {
        work.setCharAt(1, breaks.charAt(i));
        for (int j = 0; j < testChars.length(); j++) {
            work.setCharAt(0, testChars.charAt(j));
            for (int k = 0; k < testChars.length(); k++) {
                char c = testChars.charAt(k);

                // if a cr is followed by lf, don't do the check (they stay together)
                if (work.charAt(1) == '\r' && (c == '\n'))
                    continue;

                // CONTROL (Cc) and FORMAT (Cf) Characters are to be ignored
                // for breaking purposes as per UTR14
                int type1 = Character.getType(work.charAt(1));
                int type2 = Character.getType(c);
                if (type1 == Character.CONTROL || type1 == Character.FORMAT ||
                    type2 == Character.CONTROL || type2 == Character.FORMAT) {
                    continue;
                }

                work.setCharAt(2, c);
                tb.setText(work.toString());
                boolean seen2 = false;
                for (int l = tb.first(); l != BreakIterator.DONE; l = tb.next()) {
                    if (l == 2)
                        seen2 = true;
                }
                if (!seen2) {
                    errln("No break between U+" + Integer.toHexString((int)(work.charAt(1)))
                                + " and U+" + Integer.toHexString((int)(work.charAt(2))));
                    errorCount++;
                    if (errorCount >= 75)
                        return;
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:BreakIteratorTest.java

示例12: wrapText

import java.text.BreakIterator; //导入方法依赖的package包/类
/**
 * 
 * @param toWrap
 *            The string on which the line wrapping process should be done
 * @param maxLength
 *            The maximum length per line
 * @return The StringBuffer with the wrapped lines
 */
public static String wrapText(final String toWrap, final int maxLength)
{
	if (maxLength == 0) throw new IllegalArgumentException("maxLength must not be 0");

	StringBuffer ret = new StringBuffer();
	BreakIterator boundary = BreakIterator.getLineInstance();
	boundary.setText(toWrap);
	int realEnd = BreakIterator.DONE;
	int start = boundary.first();
	int end = boundary.next();

	int lineLength = 0;

	while (end != BreakIterator.DONE)
	{
		int charCount = end - start - 1;

		if (charCount > maxLength)
		{
			realEnd = end;
			end = start + maxLength;
		}
		String word = toWrap.substring(start, end);
		lineLength = lineLength + word.length();
		if (lineLength >= maxLength)
		{
			ret.append("\n");
			lineLength = word.length();
		}
		ret.append(word);
		if (realEnd == BreakIterator.DONE)
		{
			start = end;
			end = boundary.next();
		}
		else
		{
			start = end;
			end = realEnd;
			realEnd = BreakIterator.DONE;
		}
	}
	return ret.toString();
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:53,代码来源:MultiLineLabel.java

示例13: doOtherInvariantTest

import java.text.BreakIterator; //导入方法依赖的package包/类
private void doOtherInvariantTest(BreakIterator tb, String testChars)
{
    StringBuffer work = new StringBuffer("a\r\na");
    int errorCount = 0;

    // a break should never occur between CR and LF
    for (int i = 0; i < testChars.length(); i++) {
        work.setCharAt(0, testChars.charAt(i));
        for (int j = 0; j < testChars.length(); j++) {
            work.setCharAt(3, testChars.charAt(j));
            tb.setText(work.toString());
            for (int k = tb.first(); k != BreakIterator.DONE; k = tb.next())
                if (k == 2) {
                    errln("Break between CR and LF in string U+" + Integer.toHexString(
                            (int)(work.charAt(0))) + ", U+d U+a U+" + Integer.toHexString(
                            (int)(work.charAt(3))));
                    errorCount++;
                    if (errorCount >= 75)
                        return;
                }
        }
    }

    // a break should never occur before a non-spacing mark, unless it's preceded
    // by a line terminator
    work.setLength(0);
    work.append("aaaa");
    for (int i = 0; i < testChars.length(); i++) {
        char c = testChars.charAt(i);
        if (c == '\n' || c == '\r' || c == '\u2029' || c == '\u2028' || c == '\u0003')
            continue;
        work.setCharAt(1, c);
        for (int j = 0; j < testChars.length(); j++) {
            c = testChars.charAt(j);
            if (Character.getType(c) != Character.NON_SPACING_MARK && Character.getType(c)
                    != Character.ENCLOSING_MARK)
                continue;
            work.setCharAt(2, c);

            // CONTROL (Cc) and FORMAT (Cf) Characters are to be ignored
            // for breaking purposes as per UTR14
            int type1 = Character.getType(work.charAt(1));
            int type2 = Character.getType(work.charAt(2));
            if (type1 == Character.CONTROL || type1 == Character.FORMAT ||
                type2 == Character.CONTROL || type2 == Character.FORMAT) {
                continue;
            }

            tb.setText(work.toString());
            for (int k = tb.first(); k != BreakIterator.DONE; k = tb.next())
                if (k == 2) {
                    errln("Break between U+" + Integer.toHexString((int)(work.charAt(1)))
                            + " and U+" + Integer.toHexString((int)(work.charAt(2))));
                    errorCount++;
                    if (errorCount >= 75)
                        return;
                }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:BreakIteratorTest.java

示例14: _writeTextLineWithBreaks

import java.text.BreakIterator; //导入方法依赖的package包/类
private void _writeTextLineWithBreaks(
  FacesContext  context,
  BreakIterator breaks,
  String        textString,
  int           columns
  ) throws IOException
{
  if (textString.length() < columns)
  {
    context.getResponseWriter().writeText(textString, "value");
    return;
  }

  breaks.setText(textString);

  int lastStart = 0;
  int previous = 0;
  while (true)
  {
    int next = breaks.next();
    if (next == BreakIterator.DONE)
    {
      context.getResponseWriter().writeText(textString.substring(lastStart),
                                            null);
      break;
    }

    if (next - lastStart > columns)
    {
      // Even if the first string in this line was too long,
      // always output a complete line.
      if (previous == lastStart)
        previous = next;

      String sub = textString.substring(lastStart, previous);
                  char[] chars = new char['\n'];
      context.getResponseWriter().writeText(sub, null);
      context.getResponseWriter().write(chars, 0, 1);

      lastStart = previous;
    }

    previous = next;
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:46,代码来源:SimpleInputTextRenderer.java

示例15: getBreakSpot

import java.text.BreakIterator; //导入方法依赖的package包/类
/**
 * Returns a location to break at in the passed in region, or
 * BreakIterator.DONE if there isn't a good location to break at
 * in the specified region.
 */
private int getBreakSpot(int p0, int p1) {
    if (breakSpots == null) {
        // Re-calculate breakpoints for the whole view
        int start = getStartOffset();
        int end = getEndOffset();
        int[] bs = new int[end + 1 - start];
        int ix = 0;

        // Breaker should work on the parent element because there may be
        // a valid breakpoint at the end edge of the view (space, etc.)
        Element parent = getElement().getParentElement();
        int pstart = (parent == null ? start : parent.getStartOffset());
        int pend = (parent == null ? end : parent.getEndOffset());

        Segment s = getText(pstart, pend);
        s.first();
        BreakIterator breaker = getBreaker();
        breaker.setText(s);

        // Backward search should start from end+1 unless there's NO end+1
        int startFrom = end + (pend > end ? 1 : 0);
        for (;;) {
            startFrom = breaker.preceding(s.offset + (startFrom - pstart))
                      + (pstart - s.offset);
            if (startFrom > start) {
                // The break spot is within the view
                bs[ix++] = startFrom;
            } else {
                break;
            }
        }

        SegmentCache.releaseSharedSegment(s);
        breakSpots = new int[ix];
        System.arraycopy(bs, 0, breakSpots, 0, ix);
    }

    int breakSpot = BreakIterator.DONE;
    for (int i = 0; i < breakSpots.length; i++) {
        int bsp = breakSpots[i];
        if (bsp <= p1) {
            if (bsp > p0) {
                breakSpot = bsp;
            }
            break;
        }
    }
    return breakSpot;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:GlyphView.java


注:本文中的java.text.BreakIterator.setText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。