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


Java CharacterIterator.setIndex方法代码示例

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


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

示例1: candidates

import java.text.CharacterIterator; //导入方法依赖的package包/类
public int candidates(CharacterIterator fIter, DictionaryMatcher dict, int rangeEnd) {
    int start = fIter.getIndex();
    if (start != offset) {
        offset = start;
        prefix = dict.matches(fIter, rangeEnd - start, lengths, count, lengths.length);
        // Dictionary leaves text after longest prefix, not longest word. Back up.
        if (count[0] <= 0) {
            fIter.setIndex(start);
        }
    }
    if (count[0] > 0) {
        fIter.setIndex(start + lengths[count[0]-1]);
    }
    current = count[0] - 1;
    mark = current;
    return count[0];
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:18,代码来源:DictionaryBreakEngine.java

示例2: matches

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 *
 * @return -1 if <var>iterator</var> does not contain this pattern.
 */
public int matches(CharacterIterator iterator, int start, int limit) {
    if (this.ignoreCase)  return this.matchesIgnoreCase(iterator, start, limit);
    int plength = this.pattern.length;
    if (plength == 0)  return start;
    int index = start+plength;
    while (index <= limit) {
        int pindex = plength;
        int nindex = index+1;
        char ch;
        do {
            if ((ch = iterator.setIndex(--index)) != this.pattern[--pindex])
                break;
            if (pindex == 0)
                return index;
        } while (pindex > 0);
        index += this.shiftTable[ch % this.shiftTable.length]+1;
        if (index < nindex)  index = nindex;
    }
    return -1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:BMPattern.java

示例3: 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

示例4: previous

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * Advances the iterator one step backwards.
 * @return The position of the last boundary position before the
 * current iteration position
 */
@Override
public int previous() {
    CharacterIterator text = getText();

    // if we have cached break positions and we're still in the range
    // covered by them, just move one step backward in the cache
    if (cachedBreakPositions != null && positionInCache > 0) {
        --positionInCache;
        text.setIndex(cachedBreakPositions[positionInCache]);
        return cachedBreakPositions[positionInCache];
    }

    // otherwise, dump the cache and use the inherited previous() method to move
    // backward.  This may fill up the cache with new break positions, in which
    // case we have to mark our position in the cache
    else {
        cachedBreakPositions = null;
        int result = super.previous();
        if (cachedBreakPositions != null) {
            positionInCache = cachedBreakPositions.length - 2;
        }
        return result;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:DictionaryBasedBreakIterator.java

示例5: peekAndEat

import java.text.CharacterIterator; //导入方法依赖的package包/类
public static boolean peekAndEat(CharacterIterator i, String s) {
    final int ind = i.getIndex();
    for (int cntr = 0; cntr < s.length(); cntr++) {
        if (i.current() == s.charAt(cntr)) {
            i.next();
        } else {
            i.setIndex(ind);
            return false;
        }
    }
    return true;
}
 
开发者ID:beehive-lab,项目名称:Maxine-VM,代码行数:13,代码来源:StringUtil.java

示例6: getString

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * Gets a substring out of a CharacterIterator
 * 
 * Java porting note: Not available in ICU4C
 * 
 * @param text CharacterIterator
 * @param start start offset
 * @param length of substring
 * @return substring from text starting at start and length length
 */
private static final String getString(CharacterIterator text, int start, int length) {
    StringBuilder result = new StringBuilder(length);
    int offset = text.getIndex();
    text.setIndex(start);
    for (int i = 0; i < length; i++) {
        result.append(text.current());
        text.next();
    }
    text.setIndex(offset);
    return result.toString();
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:22,代码来源:StringSearch.java

示例7: following

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * Sets the iterator to refer to the first boundary position following
 * the specified position.
 * @param offset The position from which to begin searching for a break position.
 * @return The position of the first break after the current position.
 * @stable ICU 2.0
 */
@Override
public int following(int offset) {
    CharacterIterator text = getText();

    // if we have no cached break positions, or if "offset" is outside the
    // range covered by the cache, then dump the cache and call our
    // inherited following() method.  This will call other methods in this
    // class that may refresh the cache.
    if (fCachedBreakPositions == null || offset < fCachedBreakPositions[0] ||
            offset >= fCachedBreakPositions[fCachedBreakPositions.length - 1]) {
        fCachedBreakPositions = null;
        return rulesFollowing(offset);
    }

    // on the other hand, if "offset" is within the range covered by the
    // cache, then just search the cache for the first break position
    // after "offset"
    else {
        fPositionInCache = 0;
        while (fPositionInCache < fCachedBreakPositions.length
               && offset >= fCachedBreakPositions[fPositionInCache])
            ++fPositionInCache;
        text.setIndex(fCachedBreakPositions[fPositionInCache]);
        return text.getIndex();
    }
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:34,代码来源:RuleBasedBreakIterator.java

示例8: setText

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * Set the iterator to analyze a new piece of text.  This function resets
 * the current iteration position to the beginning of the text.
 * @param newText An iterator over the text to analyze.
 */
@Override
public void setText(CharacterIterator newText) {
    // Test iterator to see if we need to wrap it in a SafeCharIterator.
    // The correct behavior for CharacterIterators is to allow the
    // position to be set to the endpoint of the iterator.  Many
    // CharacterIterators do not uphold this, so this is a workaround
    // to permit them to use this class.
    int end = newText.getEndIndex();
    boolean goodIterator;
    try {
        newText.setIndex(end);  // some buggy iterators throw an exception here
        goodIterator = newText.getIndex() == end;
    }
    catch(IllegalArgumentException e) {
        goodIterator = false;
    }

    if (goodIterator) {
        text = newText;
    }
    else {
        text = new SafeCharIterator(newText);
    }
    text.first();

    cachedLastKnownBreak = BreakIterator.DONE;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:RuleBasedBreakIterator.java

示例9: preceding

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * Sets the current iteration position to the last boundary position
 * before the specified position.
 * @param offset The position to begin searching from
 * @return The position of the last boundary before "offset"
 */
@Override
public int preceding(int offset) {
    CharacterIterator text = getText();
    checkOffset(offset, text);

    // if we have no cached break positions, or "offset" is outside the
    // range covered by the cache, we can just call the inherited routine
    // (which will eventually call other routines in this class that may
    // refresh the cache)
    if (cachedBreakPositions == null || offset <= cachedBreakPositions[0] ||
            offset > cachedBreakPositions[cachedBreakPositions.length - 1]) {
        cachedBreakPositions = null;
        return super.preceding(offset);
    }

    // on the other hand, if "offset" is within the range covered by the cache,
    // then all we have to do is search the cache for the last break position
    // before "offset"
    else {
        positionInCache = 0;
        while (positionInCache < cachedBreakPositions.length
               && offset > cachedBreakPositions[positionInCache]) {
            ++positionInCache;
        }
        --positionInCache;
        text.setIndex(cachedBreakPositions[positionInCache]);
        return text.getIndex();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:DictionaryBasedBreakIterator.java

示例10: following

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * Sets the current iteration position to the first boundary position after
 * the specified position.
 * @param offset The position to begin searching forward from
 * @return The position of the first boundary after "offset"
 */
@Override
public int following(int offset) {
    CharacterIterator text = getText();
    checkOffset(offset, text);

    // if we have no cached break positions, or if "offset" is outside the
    // range covered by the cache, then dump the cache and call our
    // inherited following() method.  This will call other methods in this
    // class that may refresh the cache.
    if (cachedBreakPositions == null || offset < cachedBreakPositions[0] ||
            offset >= cachedBreakPositions[cachedBreakPositions.length - 1]) {
        cachedBreakPositions = null;
        return super.following(offset);
    }

    // on the other hand, if "offset" is within the range covered by the
    // cache, then just search the cache for the first break position
    // after "offset"
    else {
        positionInCache = 0;
        while (positionInCache < cachedBreakPositions.length
               && offset >= cachedBreakPositions[positionInCache]) {
            ++positionInCache;
        }
        text.setIndex(cachedBreakPositions[positionInCache]);
        return text.getIndex();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:DictionaryBasedBreakIterator.java

示例11: following

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * Sets the iterator to refer to the first boundary position following
 * the specified position.
 * @offset The position from which to begin searching for a break position.
 * @return The position of the first break after the current position.
 */
@Override
public int following(int offset) {

    CharacterIterator text = getText();
    checkOffset(offset, text);

    // Set our internal iteration position (temporarily)
    // to the position passed in.  If this is the _beginning_ position,
    // then we can just use next() to get our return value
    text.setIndex(offset);
    if (offset == text.getBeginIndex()) {
        cachedLastKnownBreak = handleNext();
        return cachedLastKnownBreak;
    }

    // otherwise, we have to sync up first.  Use handlePrevious() to back
    // us up to a known break position before the specified position (if
    // we can determine that the specified position is a break position,
    // we don't back up at all).  This may or may not be the last break
    // position at or before our starting position.  Advance forward
    // from here until we've passed the starting position.  The position
    // we stop on will be the first break position after the specified one.
    int result = cachedLastKnownBreak;
    if (result >= offset || result <= BreakIterator.DONE) {
        result = handlePrevious();
    } else {
        //it might be better to check if handlePrevious() give us closer
        //safe value but handlePrevious() is slow too
        //So, this has to be done carefully
        text.setIndex(result);
    }
    while (result != BreakIterator.DONE && result <= offset) {
        result = handleNext();
    }
    cachedLastKnownBreak = result;
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:RuleBasedBreakIterator.java

示例12: acceptMarked

import java.text.CharacterIterator; //导入方法依赖的package包/类
public int acceptMarked(CharacterIterator fIter) {
    fIter.setIndex(offset + lengths[mark]);
    return lengths[mark];
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:5,代码来源:DictionaryBreakEngine.java

示例13: substring

import java.text.CharacterIterator; //导入方法依赖的package包/类
static final String substring(CharacterIterator iterator, int begin, int end) {
    char[] src = new char[end-begin];
    for (int i = 0;  i < src.length;  i ++)
        src[i] = iterator.setIndex(i+begin);
    return new String(src);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:REUtil.java

示例14: 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

示例15: handleNext

import java.text.CharacterIterator; //导入方法依赖的package包/类
/**
 * This is the implementation function for next().
 */
@Override
protected int handleNext() {
    CharacterIterator text = getText();

    // if there are no cached break positions, or if we've just moved
    // off the end of the range covered by the cache, we have to dump
    // and possibly regenerate the cache
    if (cachedBreakPositions == null ||
        positionInCache == cachedBreakPositions.length - 1) {

        // start by using the inherited handleNext() to find a tentative return
        // value.   dictionaryCharCount tells us how many dictionary characters
        // we passed over on our way to the tentative return value
        int startPos = text.getIndex();
        dictionaryCharCount = 0;
        int result = super.handleNext();

        // if we passed over more than one dictionary character, then we use
        // divideUpDictionaryRange() to regenerate the cached break positions
        // for the new range
        if (dictionaryCharCount > 1 && result - startPos > 1) {
            divideUpDictionaryRange(startPos, result);
        }

        // otherwise, the value we got back from the inherited fuction
        // is our return value, and we can dump the cache
        else {
            cachedBreakPositions = null;
            return result;
        }
    }

    // if the cache of break positions has been regenerated (or existed all
    // along), then just advance to the next break position in the cache
    // and return it
    if (cachedBreakPositions != null) {
        ++positionInCache;
        text.setIndex(cachedBreakPositions[positionInCache]);
        return cachedBreakPositions[positionInCache];
    }
    return -9999;   // SHOULD NEVER GET HERE!
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:46,代码来源:DictionaryBasedBreakIterator.java


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