當前位置: 首頁>>代碼示例>>Java>>正文


Java CharacterIterator.getEndIndex方法代碼示例

本文整理匯總了Java中java.text.CharacterIterator.getEndIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java CharacterIterator.getEndIndex方法的具體用法?Java CharacterIterator.getEndIndex怎麽用?Java CharacterIterator.getEndIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.CharacterIterator的用法示例。


在下文中一共展示了CharacterIterator.getEndIndex方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setText

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Calculate break positions eagerly parallel to reading text.
 */
public void setText(CharacterIterator ci) {
    int begin = ci.getBeginIndex();
    text = new char[ci.getEndIndex() - begin];
    int[] breaks0 = new int[text.length + 1];
    int brIx = 0;
    breaks0[brIx++] = begin;

    int charIx = 0;
    boolean inWs = false;
    for (char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) {
        text[charIx] = c;
        boolean ws = Character.isWhitespace(c);
        if (inWs && !ws) {
            breaks0[brIx++] = charIx + begin;
        }
        inWs = ws;
        charIx++;
    }
    if (text.length > 0) {
        breaks0[brIx++] = text.length + begin;
    }
    System.arraycopy(breaks0, 0, breaks = new int[brIx], 0, brIx);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:WhitespaceBasedBreakIterator.java

示例2: setTarget

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Set the target text to be searched. Text iteration will then begin at 
 * the start of the text string. This method is useful if you want to 
 * reuse an iterator to search within a different body of text.
 * 
 * @param text new text iterator to look for match, 
 * @exception IllegalArgumentException thrown when text is null or has
 *               0 length
 * @see #getTarget
 * @stable ICU 2.4
 */
public void setTarget(CharacterIterator text)
{
    if (text == null || text.getEndIndex() == text.getIndex()) {
        throw new IllegalArgumentException("Illegal null or empty text");
    }

    text.setIndex(text.getBeginIndex());
    search_.setTarget(text);
    search_.matchedIndex_ = DONE;
    search_.setMatchedLength(0);
    search_.reset_ = true;
    search_.isForwardSearching_ = true;
    if (search_.breakIter() != null) {
        // Create a clone of CharacterItearator, so it won't
        // affect the position currently held by search_.text()
        search_.breakIter().setText((CharacterIterator)text.clone());
    }
    if (search_.internalBreakIter_ != null) {
        search_.internalBreakIter_.setText((CharacterIterator)text.clone());
    }
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:33,代碼來源:SearchIterator.java

示例3: SearchIterator

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Protected constructor for use by subclasses.
 * Initializes the iterator with the argument target text for searching 
 * and sets the BreakIterator.
 * See class documentation for more details on the use of the target text
 * and {@link BreakIterator}.
 * 
 * @param target The target text to be searched.
 * @param breaker A {@link BreakIterator} that is used to determine the 
 *                boundaries of a logical match. This argument can be null.
 * @exception IllegalArgumentException thrown when argument target is null,
 *            or of length 0
 * @see BreakIterator  
 * @stable ICU 2.0
 */
protected SearchIterator(CharacterIterator target, BreakIterator breaker)
{
    if (target == null 
        || (target.getEndIndex() - target.getBeginIndex()) == 0) {
            throw new IllegalArgumentException(
                               "Illegal argument target. " +
                               " Argument can not be null or of length 0");
    }

    search_.setTarget(target);
    search_.setBreakIter(breaker);
    if (search_.breakIter() != null) {
        search_.breakIter().setText((CharacterIterator)target.clone());
    }
    search_.isOverlap_ = false;
    search_.isCanonicalMatch_ = false;
    search_.elementComparisonType_ = ElementComparisonType.STANDARD_ELEMENT_COMPARISON;
    search_.isForwardSearching_ = true;
    search_.reset_ = true;
    search_.matchedIndex_ = DONE;
    search_.setMatchedLength(0);
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:38,代碼來源:SearchIterator.java

示例4: nextTrail32

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static int nextTrail32(CharacterIterator ci, int lead) {
    if (lead == CharacterIterator.DONE && ci.getIndex() >= ci.getEndIndex()) {
        return DONE32;
    }
    int retVal = lead;
    if (lead <= UTF16.LEAD_SURROGATE_MAX_VALUE) {
        char  cTrail = ci.next();
        if (UTF16.isTrailSurrogate(cTrail)) {
            retVal = ((lead  - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
                        (cTrail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
                        UTF16.SUPPLEMENTARY_MIN_VALUE;
        } else {
            ci.previous();
        }
    }
    return retVal;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:18,代碼來源:CharacterIteration.java

示例5: current32

import java.text.CharacterIterator; //導入方法依賴的package包/類
public static int current32(CharacterIterator ci) {
    char  lead   = ci.current();
    int   retVal = lead;
    if (retVal < UTF16.LEAD_SURROGATE_MIN_VALUE) {
        return retVal;   
    }
    if (UTF16.isLeadSurrogate(lead)) {
        int  trail = (int)ci.next();
        ci.previous();
        if (UTF16.isTrailSurrogate((char)trail)) {
            retVal = ((lead  - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
                     (trail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
                     UTF16.SUPPLEMENTARY_MIN_VALUE;
        }
     } else {
        if (lead == CharacterIterator.DONE) {
            if (ci.getIndex() >= ci.getEndIndex())   {
                retVal = DONE32;   
            }
        }
     }
    return retVal;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:24,代碼來源:CharacterIteration.java

示例6: characterIteratorToString

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Returns a string containing the characters from the given iterator.
 * 
 * @param iterator  the iterator (<code>null</code> not permitted).
 * 
 * @return A string.
 */
private String characterIteratorToString(CharacterIterator iterator) {
    int endIndex = iterator.getEndIndex();
    int beginIndex = iterator.getBeginIndex();
    int count = endIndex - beginIndex;
    if (count <= 0) {
        return "";
    }
    char[] chars = new char[count];
    int i = 0;
    char c = iterator.first();
    while (c != CharacterIterator.DONE) {
        chars[i] = c;
        i++;
        c = iterator.next();
    }
    return new String(chars);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:25,代碼來源:LegendItem.java

示例7: StandardGlyphVector

import java.text.CharacterIterator; //導入方法依賴的package包/類
public StandardGlyphVector(Font font, CharacterIterator iter, FontRenderContext frc) {
    int offset = iter.getBeginIndex();
    char[] text = new char [iter.getEndIndex() - offset];
    for(char c = iter.first();
        c != CharacterIterator.DONE;
        c = iter.next()) {
        text[iter.getIndex() - offset] = c;
    }
    init(font, text, 0, text.length, frc, UNINITIALIZED_FLAGS);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:StandardGlyphVector.java

示例8: handleNext

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * This method is the actual implementation of the next() method.  All iteration
 * vectors through here.  This method initializes the state machine to state 1
 * and advances through the text character by character until we reach the end
 * of the text or the state machine transitions to state 0.  We update our return
 * value every time the state machine passes through a possible end state.
 */
protected int handleNext() {
    // if we're already at the end of the text, return DONE.
    CharacterIterator text = getText();
    if (text.getIndex() == text.getEndIndex()) {
        return BreakIterator.DONE;
    }

    // no matter what, we always advance at least one character forward
    int result = getNextIndex();
    int lookaheadResult = 0;

    // begin in state 1
    int state = START_STATE;
    int category;
    int c = getCurrent();

    // loop until we reach the end of the text or transition to state 0
    while (c != CharacterIterator.DONE && state != STOP_STATE) {

        // look up the current character's character category (which tells us
        // which column in the state table to look at)
        category = lookupCategory(c);

        // if the character isn't an ignore character, look up a state
        // transition in the state table
        if (category != IGNORE) {
            state = lookupState(state, category);
        }

        // if the state we've just transitioned to is a lookahead state,
        // (but not also an end state), save its position.  If it's
        // both a lookahead state and an end state, update the break position
        // to the last saved lookup-state position
        if (lookaheadStates[state]) {
            if (endStates[state]) {
                result = lookaheadResult;
            }
            else {
                lookaheadResult = getNextIndex();
            }
        }

        // otherwise, if the state we've just transitioned to is an accepting
        // state, update the break position to be the current iteration position
        else {
            if (endStates[state]) {
                result = getNextIndex();
            }
        }

        c = getNext();
    }

    // if we've run off the end of the text, and the very last character took us into
    // a lookahead state, advance the break position to the lookahead position
    // (the theory here is that if there are no characters at all after the lookahead
    // position, that always matches the lookahead criteria)
    if (c == CharacterIterator.DONE && lookaheadResult == text.getEndIndex()) {
        result = lookaheadResult;
    }

    text.setIndex(result);
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:72,代碼來源:RuleBasedBreakIterator.java

示例9: SafeCharIterator

import java.text.CharacterIterator; //導入方法依賴的package包/類
SafeCharIterator(CharacterIterator base) {
    this.base = base;
    this.rangeStart = base.getBeginIndex();
    this.rangeLimit = base.getEndIndex();
    this.currentIndex = base.getIndex();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:RuleBasedBreakIterator.java

示例10: getStringBounds

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified <code>FontRenderContext</code>.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified <code>CharacterIterator</code>
 * @param beginIndex the initial offset in <code>ci</code>
 * @param limit the end offset in <code>ci</code>
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * characters indexed in the specified <code>CharacterIterator</code>
 * in the specified <code>FontRenderContext</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than the start index of <code>ci</code>, or
 *         <code>limit</code> is greater than the end index of
 *         <code>ci</code>, or <code>beginIndex</code> is greater
 *         than <code>limit</code>
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:57,代碼來源:Font.java

示例11: getStringBounds

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * Returns the logical bounds of the characters indexed in the
 * specified {@link CharacterIterator} in the
 * specified {@code FontRenderContext}.  The logical bounds
 * contains the origin, ascent, advance, and height, which includes
 * the leading.  The logical bounds does not always enclose all the
 * text.  For example, in some languages and in some fonts, accent
 * marks can be positioned above the ascent or below the descent.
 * To obtain a visual bounding box, which encloses all the text,
 * use the {@link TextLayout#getBounds() getBounds} method of
 * {@code TextLayout}.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param ci the specified {@code CharacterIterator}
 * @param beginIndex the initial offset in {@code ci}
 * @param limit the end offset in {@code ci}
 * @param frc the specified {@code FontRenderContext}
 * @return a {@code Rectangle2D} that is the bounding box of the
 * characters indexed in the specified {@code CharacterIterator}
 * in the specified {@code FontRenderContext}.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 * @throws IndexOutOfBoundsException if {@code beginIndex} is
 *         less than the start index of {@code ci}, or
 *         {@code limit} is greater than the end index of
 *         {@code ci}, or {@code beginIndex} is greater
 *         than {@code limit}
 */
public Rectangle2D getStringBounds(CharacterIterator ci,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    int start = ci.getBeginIndex();
    int end = ci.getEndIndex();

    if (beginIndex < start) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > end) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    char[]  arr = new char[limit - beginIndex];

    ci.setIndex(beginIndex);
    for(int idx = 0; idx < arr.length; idx++) {
        arr[idx] = ci.current();
        ci.next();
    }

    return getStringBounds(arr,0,arr.length,frc);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:57,代碼來源:Font.java


注:本文中的java.text.CharacterIterator.getEndIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。