Java Code Examples for com.ibm.icu.text.UTF16#isSurrogate()

The following examples show how to use com.ibm.icu.text.UTF16#isSurrogate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Normalizer2Impl.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
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;
}