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


Java UTF16.isSurrogate方法代码示例

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


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

示例1: decompose

import com.ibm.icu.text.UTF16; //导入方法依赖的package包/类
public int decompose(CharSequence s, int src, int limit,
                     ReorderingBuffer buffer) {
    int minNoCP=minDecompNoCP;

    int prevSrc;
    int c=0;
    int norm16=0;

    // only for quick check
    int prevBoundary=src;
    int prevCC=0;

    for(;;) {
        // count code units below the minimum or with irrelevant data for the quick check
        for(prevSrc=src; src!=limit;) {
            if( (c=s.charAt(src))<minNoCP ||
                isMostDecompYesAndZeroCC(norm16=normTrie.getFromU16SingleLead((char)c))
            ) {
                ++src;
            } else if(!UTF16.isSurrogate((char)c)) {
                break;
            } else {
                char c2;
                if(UTF16Plus.isSurrogateLead(c)) {
                    if((src+1)!=limit && Character.isLowSurrogate(c2=s.charAt(src+1))) {
                        c=Character.toCodePoint((char)c, c2);
                    }
                } else /* trail surrogate */ {
                    if(prevSrc<src && Character.isHighSurrogate(c2=s.charAt(src-1))) {
                        --src;
                        c=Character.toCodePoint(c2, (char)c);
                    }
                }
                if(isMostDecompYesAndZeroCC(norm16=getNorm16(c))) {
                    src+=Character.charCount(c);
                } else {
                    break;
                }
            }
        }
        // copy these code units all at once
        if(src!=prevSrc) {
            if(buffer!=null) {
                buffer.flushAndAppendZeroCC(s, prevSrc, src);
            } else {
                prevCC=0;
                prevBoundary=src;
            }
        }
        if(src==limit) {
            break;
        }

        // Check one above-minimum, relevant code point.
        src+=Character.charCount(c);
        if(buffer!=null) {
            decompose(c, norm16, buffer);
        } else {
            if(isDecompYes(norm16)) {
                int cc=getCCFromYesOrMaybe(norm16);
                if(prevCC<=cc || cc==0) {
                    prevCC=cc;
                    if(cc<=1) {
                        prevBoundary=src;
                    }
                    continue;
                }
            }
            return prevBoundary;  // "no" or cc out of order
        }
    }
    return src;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:74,代码来源:Normalizer2Impl.java

示例2: findWord

import com.ibm.icu.text.UTF16; //导入方法依赖的package包/类
public static IRegion findWord(IDocument document, int offset) {

		int start= -2;
		int end= -1;

		try {
			int pos= offset;
			char c;

			while (pos >= 0) {
				c= document.getChar(pos);
				if (!Character.isJavaIdentifierPart(c)) {
					// Check for surrogates
					if (UTF16.isSurrogate(c)) {
						/*
						 * XXX: Here we should create the code point and test whether
						 * it is a Java identifier part. Currently this is not possible
						 * because java.lang.Character in 1.4 does not support surrogates
						 * and because com.ibm.icu.lang.UCharacter.isJavaIdentifierPart(int)
						 * is not correctly implemented.
						 */
					} else {
						break;
					}
				}
				--pos;
			}
			start= pos;

			pos= offset;
			int length= document.getLength();

			while (pos < length) {
				c= document.getChar(pos);
				if (!Character.isJavaIdentifierPart(c)) {
					if (UTF16.isSurrogate(c)) {
						/*
						 * XXX: Here we should create the code point and test whether
						 * it is a Java identifier part. Currently this is not possible
						 * because java.lang.Character in 1.4 does not support surrogates
						 * and because com.ibm.icu.lang.UCharacter.isJavaIdentifierPart(int)
						 * is not correctly implemented.
						 */
					} else {
						break;
					}

				}
				++pos;
			}
			end= pos;

		} catch (BadLocationException x) {
		}

		if (start >= -1 && end > -1) {
			if (start == offset && end == offset)
				return new Region(offset, 0);
			else if (start == offset)
				return new Region(start, end - start);
			else
				return new Region(start + 1, end - start - 1);
		}

		return null;
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:67,代码来源:JavaWordFinder.java


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