Examples of BreakIterator


Examples of java.text.BreakIterator

  {
    // Just to be explicit: we're only testing the US locale here.
    Locale loc = Locale.US;
    Locale.setDefault (loc);

    BreakIterator bi = BreakIterator.getWordInstance (loc);

    String[] r1 = { "How", " ", "much", " ", "time", " ", "is", " ",
        "left", "?", "  ", "We", " ", "don't", " ",
        "know", "." };
    check ("How much", "How much time is left?  We don't know.", r1,
View Full Code Here

Examples of java.text.BreakIterator

  {
    // Just to be explicit: we're only testing the US locale here.
    Locale loc = Locale.US;
    Locale.setDefault (loc);

    BreakIterator bi = BreakIterator.getLineInstance (loc);

    String[] r1 = { "How ", "much ", "time ", "is ", "left?  ",
        "We ", "don't ", "know." };
    check ("How much", "How much time is left?  We don't know.", r1,
     bi, harness);
View Full Code Here

Examples of java.text.BreakIterator

        return out.toString();
    }

    protected static String breakLines(String str,int lineWidth,int indent) {
        StringBuffer out=new StringBuffer();
        BreakIterator i=BreakIterator.getLineInstance();
        i.setText(str);
        int curPos=0;
        int curLinePos=indent;
        int next=i.first();
        while (next!=BreakIterator.DONE) {
            String curSpan=str.substring(curPos,next);
            if (curLinePos+curSpan.length()>lineWidth) {
                out.append(System.getProperty("line.separator"));
                for (int j=0;j<indent;++j)
                    out.append(" ");
                curLinePos=indent;
            }
            out.append(curSpan);
            curLinePos+=curSpan.length();
            curPos=next;
            next=i.next();
        }
        return out.toString();
    }
View Full Code Here

Examples of java.text.BreakIterator

    String stripped = m.group(2);

    p = Pattern.compile("^\\p{Blank}*\\**\\p{Blank}*", Pattern.MULTILINE);
    String bareComment = p.matcher(stripped).replaceAll("");

    BreakIterator iterator = BreakIterator.getSentenceInstance();
    iterator.setText(bareComment);
    int firstSentenceEnd = iterator.next();
    if (firstSentenceEnd == BreakIterator.DONE) {
      summary.append(bareComment);
    } else {
      summary.append(bareComment.substring(0, firstSentenceEnd));
    }
View Full Code Here

Examples of java.text.BreakIterator

        return new AccessibleAWTTextComponent();
    }

    private String getLine(int index) {
        String result = null;
        BreakIterator bi = BreakIterator.getSentenceInstance();
        bi.setText(getText());
        int end = bi.following(index);
        int start = bi.preceding(end - 1);
        try {
            result = document.getText(start, end - start);
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
View Full Code Here

Examples of java.text.BreakIterator

        }
        return s;
    }

    private int getWordEnd(final int pos) throws BadLocationException {
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = document.getLength();
        if (pos < 0 || pos > length) {
            throwException("No word at " + pos, pos);
        }
        String content = document.getText(0, length);
        bi.setText(content);
        return (pos < bi.last()) ? bi.following(pos) : pos;
    }
View Full Code Here

Examples of java.text.BreakIterator

        bi.setText(content);
        return (pos < bi.last()) ? bi.following(pos) : pos;
    }

    private int getWordStart(final int pos) throws BadLocationException {
        BreakIterator bi = BreakIterator.getWordInstance();
        int length = document.getLength();
        if (pos < 0 || pos > length) {
            throwException("No word at " + pos, pos);
        }
        String content = null;
        content = document.getText(0, length);
        bi.setText(content);
        int iteratorWordStart = pos;
        if (pos < length - 1) {
            iteratorWordStart = bi.preceding(pos + 1);
        } else {
            bi.last();
            iteratorWordStart = bi.previous();
        }
        return iteratorWordStart;
    }
View Full Code Here

Examples of java.text.BreakIterator

                    } catch (final BadLocationException e) {
                        return null;
                    }
                    return (offset < 0) ? null : getWord(offset);
                case AccessibleText.SENTENCE:
                    BreakIterator bi = BreakIterator.getSentenceInstance();
                    bi.setText(getText());
                    offset = bi.preceding(index);
                    offset = bi.previous() + 1;
                    return (offset < 0) ? null : getLine(offset);
                default:
                    return null;
            }
        }
View Full Code Here

Examples of java.text.BreakIterator

              else
              {
                // Get a BreakIterator.  Note that this code doesn't
                // really work for multi-lingual pages (e.g., an English
                // page that contains some Japanese text).
                BreakIterator breaks = BreakIterator.getLineInstance(
                  context.getViewRoot().getLocale());
                breaks.setText(textString);

                _writeTextWithBreaks(context, breaks, textString, columns);
              }
            } // endif wrapping on
            else
View Full Code Here

Examples of java.text.BreakIterator

              else
              {
                // Get a BreakIterator.  Note that this code doesn't
                // really work for multi-lingual pages (e.g., an English
                // page that contains some Japanese text).
                BreakIterator breaks = BreakIterator.getLineInstance(
                  context.getViewRoot().getLocale());
                breaks.setText(textString);

                _writeTextWithBreaks(context, breaks, textString, columns);
              }
            } // endif wrapping on
            else
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.