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


Java UCharacterIterator.getIndex方法代码示例

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


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

示例1: map

import sun.text.normalizer.UCharacterIterator; //导入方法依赖的package包/类
private StringBuffer map( UCharacterIterator iter, int options)
                        throws ParseException {

    Values val = new Values();
    char result = 0;
    int ch  = UCharacterIterator.DONE;
    StringBuffer dest = new StringBuffer();
    boolean allowUnassigned = ((options & ALLOW_UNASSIGNED)>0);

    while((ch=iter.nextCodePoint())!= UCharacterIterator.DONE){

        result = getCodePointValue(ch);
        getValues(result,val);

        // check if the source codepoint is unassigned
        if(val.type == UNASSIGNED && allowUnassigned == false){
             throw new ParseException("An unassigned code point was found in the input " +
                                      iter.getText(), iter.getIndex());
        }else if((val.type == MAP)){
            int index, length;

            if(val.isIndex){
                index = val.value;
                if(index >= indexes[ONE_UCHAR_MAPPING_INDEX_START] &&
                         index < indexes[TWO_UCHARS_MAPPING_INDEX_START]){
                    length = 1;
                }else if(index >= indexes[TWO_UCHARS_MAPPING_INDEX_START] &&
                         index < indexes[THREE_UCHARS_MAPPING_INDEX_START]){
                    length = 2;
                }else if(index >= indexes[THREE_UCHARS_MAPPING_INDEX_START] &&
                         index < indexes[FOUR_UCHARS_MAPPING_INDEX_START]){
                    length = 3;
                }else{
                    length = mappingData[index++];
                }
                /* copy mapping to destination */
                dest.append(mappingData,index,length);
                continue;

            }else{
                ch -= val.value;
            }
        }else if(val.type == DELETE){
            // just consume the codepoint and contine
            continue;
        }
        //copy the source into destination
        UTF16.append(dest,ch);
    }

    return dest;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:StringPrep.java

示例2: prepare

import sun.text.normalizer.UCharacterIterator; //导入方法依赖的package包/类
/**
 * Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC),
 * checks for prohited and BiDi characters in the order defined by RFC 3454
 * depending on the options specified in the profile.
 *
 * @param src           A UCharacterIterator object containing the source string
 * @param options       A bit set of options:
 *
 *  - StringPrep.NONE               Prohibit processing of unassigned code points in the input
 *
 *  - StringPrep.ALLOW_UNASSIGNED   Treat the unassigned code points are in the input
 *                                  as normal Unicode code points.
 *
 * @return StringBuffer A StringBuffer containing the output
 * @throws ParseException
 * @draft ICU 2.8
 */
public StringBuffer prepare(UCharacterIterator src, int options)
                    throws ParseException{

    // map
    StringBuffer mapOut = map(src,options);
    StringBuffer normOut = mapOut;// initialize

    if(doNFKC){
        // normalize
        normOut = normalize(mapOut);
    }

    int ch;
    char result;
    UCharacterIterator iter = UCharacterIterator.getInstance(normOut);
    Values val = new Values();
    int direction=UCharacterDirection.CHAR_DIRECTION_COUNT,
        firstCharDir=UCharacterDirection.CHAR_DIRECTION_COUNT;
    int rtlPos=-1, ltrPos=-1;
    boolean rightToLeft=false, leftToRight=false;

    while((ch=iter.nextCodePoint())!= UCharacterIterator.DONE){
        result = getCodePointValue(ch);
        getValues(result,val);

        if(val.type == PROHIBITED ){
            throw new ParseException("A prohibited code point was found in the input" +
                                     iter.getText(), val.value);
        }

        direction = UCharacter.getDirection(ch);
        if(firstCharDir == UCharacterDirection.CHAR_DIRECTION_COUNT){
            firstCharDir = direction;
        }
        if(direction == UCharacterDirection.LEFT_TO_RIGHT){
            leftToRight = true;
            ltrPos = iter.getIndex()-1;
        }
        if(direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC){
            rightToLeft = true;
            rtlPos = iter.getIndex()-1;
        }
    }
    if(checkBiDi == true){
        // satisfy 2
        if( leftToRight == true && rightToLeft == true){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
         }

        //satisfy 3
        if( rightToLeft == true &&
            !((firstCharDir == UCharacterDirection.RIGHT_TO_LEFT || firstCharDir == UCharacterDirection.RIGHT_TO_LEFT_ARABIC) &&
            (direction == UCharacterDirection.RIGHT_TO_LEFT || direction == UCharacterDirection.RIGHT_TO_LEFT_ARABIC))
          ){
            throw new ParseException("The input does not conform to the rules for BiDi code points." +
                                     iter.getText(),
                                     (rtlPos>ltrPos) ? rtlPos : ltrPos);
        }
    }
    return normOut;

  }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:82,代码来源:StringPrep.java


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