示例#1
0
 /**
  * Clone method. Creates another LaoBreakIterator with the same behavior and current state as this
  * one.
  *
  * @return The clone.
  */
 @Override
 public LaoBreakIterator clone() {
   LaoBreakIterator other = (LaoBreakIterator) super.clone();
   other.rules = (RuleBasedBreakIterator) rules.clone();
   other.verify = (RuleBasedBreakIterator) verify.clone();
   if (text != null) other.text = text.clone();
   if (working != null) other.working = working.clone();
   if (verifyText != null) other.verifyText = verifyText.clone();
   return other;
 }
示例#2
0
 @Override
 public int first() {
   working.setText(this.text.getText(), this.text.getStart(), this.text.getLength());
   rules.setText(working);
   workingOffset = 0;
   int first = rules.first();
   return first == BreakIterator.DONE ? BreakIterator.DONE : workingOffset + first;
 }
示例#3
0
 @Override
 public void setText(CharacterIterator text) {
   if (!(text instanceof CharArrayIterator))
     throw new UnsupportedOperationException("unsupported CharacterIterator");
   this.text = (CharArrayIterator) text;
   ccReorder(this.text.getText(), this.text.getStart(), this.text.getLength());
   working.setText(this.text.getText(), this.text.getStart(), this.text.getLength());
   rules.setText(working);
   workingOffset = 0;
 }
示例#4
0
  @Override
  public int next() {
    int current = current();
    int next = rules.next();
    if (next == BreakIterator.DONE) return next;
    else next += workingOffset;

    char c = working.current();
    int following = rules.next(); // lookahead
    if (following != BreakIterator.DONE) {
      following += workingOffset;
      if (rules.getRuleStatus() == 0 && laoSet.contains(c) && verifyPushBack(current, next)) {
        workingOffset = next - 1;
        working.setText(
            text.getText(), text.getStart() + workingOffset, text.getLength() - workingOffset);
        return next - 1;
      }
      rules.previous(); // undo the lookahead
    }

    return next;
  }
示例#5
0
  private boolean verifyPushBack(int current, int next) {
    int shortenedSyllable = next - current - 1;

    verifyText.setText(text.getText(), text.getStart() + current, shortenedSyllable);
    verify.setText(verifyText);
    if (verify.next() != shortenedSyllable || verify.getRuleStatus() == 0) return false;

    verifyText.setText(text.getText(), text.getStart() + next - 1, text.getLength() - next + 1);
    verify.setText(verifyText);

    return (verify.next() != BreakIterator.DONE && verify.getRuleStatus() != 0);
  }
示例#6
0
  private void makeLayoutWindow(int localStart) {

    int compStart = localStart;
    int compLimit = fChars.length;

    // If we've already gone past the layout window, format to end of paragraph
    if (layoutCount > 0 && !haveLayoutWindow) {
      float avgLineLength = Math.max(layoutCharCount / layoutCount, 1);
      compLimit = Math.min(localStart + (int) (avgLineLength * EST_LINES), fChars.length);
    }

    if (localStart > 0 || compLimit < fChars.length) {
      if (charIter == null) {
        charIter = new CharArrayIterator(fChars);
      } else {
        charIter.reset(fChars);
      }
      if (fLineBreak == null) {
        fLineBreak = BreakIterator.getLineInstance();
      }
      fLineBreak.setText(charIter);
      if (localStart > 0) {
        if (!fLineBreak.isBoundary(localStart)) {
          compStart = fLineBreak.preceding(localStart);
        }
      }
      if (compLimit < fChars.length) {
        if (!fLineBreak.isBoundary(compLimit)) {
          compLimit = fLineBreak.following(compLimit);
        }
      }
    }

    ensureComponents(compStart, compLimit);
    haveLayoutWindow = true;
  }
示例#7
0
 @Override
 public void setText(String newText) {
   CharArrayIterator ci = new CharArrayIterator();
   ci.setText(newText.toCharArray(), 0, newText.length());
   setText(ci);
 }