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


Java CharacterIterator.previous方法代碼示例

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


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

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

示例2: previous32

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

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

示例4: utf8Length

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
 * For the given string, returns the number of UTF-8 bytes
 * required to encode the string.
 * @param string text to encode
 * @return number of UTF-8 bytes required to encode
 */
public static int utf8Length(String string) {
  CharacterIterator iter = new StringCharacterIterator(string);
  char ch = iter.first();
  int size = 0;
  while (ch != CharacterIterator.DONE) {
    if ((ch >= 0xD800) && (ch < 0xDC00)) {
      // surrogate pair?
      char trail = iter.next();
      if ((trail > 0xDBFF) && (trail < 0xE000)) {
        // valid pair
        size += 4;
      } else {
        // invalid pair
        size += 3;
        iter.previous(); // rewind one
      }
    } else if (ch < 0x80) {
      size++;
    } else if (ch < 0x800) {
      size += 2;
    } else {
      // ch < 0x10000, that is, the largest char value
      size += 3;
    }
    ch = iter.next();
  }
  return size;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:35,代碼來源:Text.java

示例5: codePointBefore

import java.text.CharacterIterator; //導入方法依賴的package包/類
private static int codePointBefore(CharacterIterator iter, int index) {
    int currentIterIndex = iter.getIndex();
    iter.setIndex(index);
    char codeUnit = iter.previous();
    int cp = codeUnit;
    if (Character.isLowSurrogate(codeUnit)) {
        char prevUnit = iter.previous();
        if (Character.isHighSurrogate(prevUnit)) {
            cp = Character.toCodePoint(prevUnit, codeUnit);
        }
    }
    iter.setIndex(currentIterIndex);  // restore iter position
    return cp;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:15,代碼來源:StringSearch.java

示例6: next32

import java.text.CharacterIterator; //導入方法依賴的package包/類
/**
  * Move the iterator forward to the next code point, and return that code point,
  *   leaving the iterator positioned at char returned.
  *   For Supplementary chars, the iterator is left positioned at the lead surrogate.
  * @param ci  The character iterator
  * @return    The next code point.
  */
 public static int next32(CharacterIterator ci) {
     // If the current position is at a surrogate pair, move to the trail surrogate
     //   which leaves it in position for underlying iterator's next() to work.
     int c = ci.current();
     if (c >= UTF16.LEAD_SURROGATE_MIN_VALUE && c<=UTF16.LEAD_SURROGATE_MAX_VALUE) {
         c = ci.next();   
         if (c<UTF16.TRAIL_SURROGATE_MIN_VALUE || c>UTF16.TRAIL_SURROGATE_MAX_VALUE) {
             ci.previous();   
         }
     }

     // For BMP chars, this next() is the real deal.
     c = ci.next();
     
     // If we might have a lead surrogate, we need to peak ahead to get the trail 
     //  even though we don't want to really be positioned there.
     if (c >= UTF16.LEAD_SURROGATE_MIN_VALUE) {
         c = nextTrail32(ci, c);   
     }
     
     if (c >= UTF16.SUPPLEMENTARY_MIN_VALUE && c != DONE32) {
         // We got a supplementary char.  Back the iterator up to the postion
         // of the lead surrogate.
         ci.previous();   
     }
     return c;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:35,代碼來源:CharacterIteration.java


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