Example usage for java.lang Character isHighSurrogate

List of usage examples for java.lang Character isHighSurrogate

Introduction

In this page you can find the example usage for java.lang Character isHighSurrogate.

Prototype

public static boolean isHighSurrogate(char ch) 

Source Link

Document

Determines if the given char value is a <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> Unicode high-surrogate code unit</a> (also known as <i>leading-surrogate code unit</i>).

Usage

From source file:com.clark.func.Functions.java

/**
 * <p>/*from w ww .ja v a  2  s  . c  om*/
 * Searches a CharSequence to find the first index of any character not in
 * the given set of characters.
 * </p>
 * 
 * <p>
 * A <code>null</code> CharSequence will return <code>-1</code>. A
 * <code>null</code> or zero length search array will return <code>-1</code>
 * .
 * </p>
 * 
 * <pre>
 * indexOfAnyBut(null, *)           = -1
 * indexOfAnyBut("", *)             = -1
 * indexOfAnyBut(*, null)           = -1
 * indexOfAnyBut(*, [])             = -1
 * indexOfAnyBut("zzabyycdxx",'za') = 3
 * indexOfAnyBut("zzabyycdxx", '')  = 0
 * indexOfAnyBut("aba", 'ab')       = -1
 * </pre>
 * 
 * @param cs
 *            the CharSequence to check, may be null
 * @param searchChars
 *            the chars to search for, may be null
 * @return the index of any of the chars, -1 if no match or null input
 * @since 2.0
 * @since 3.0 Changed signature from indexOfAnyBut(String, char[]) to
 *        indexOfAnyBut(CharSequence, char[])
 */
public static int indexOfAnyBut(CharSequence cs, char[] searchChars) {
    if (isEmpty(cs) || isEmpty(searchChars)) {
        return INDEX_NOT_FOUND;
    }
    int csLen = cs.length();
    int csLast = csLen - 1;
    int searchLen = searchChars.length;
    int searchLast = searchLen - 1;
    outer: for (int i = 0; i < csLen; i++) {
        char ch = cs.charAt(i);
        for (int j = 0; j < searchLen; j++) {
            if (searchChars[j] == ch) {
                if (i < csLast && j < searchLast && Character.isHighSurrogate(ch)) {
                    if (searchChars[j + 1] == cs.charAt(i + 1)) {
                        continue outer;
                    }
                } else {
                    continue outer;
                }
            }
        }
        return i;
    }
    return INDEX_NOT_FOUND;
}

From source file:com.clark.func.Functions.java

/**
 * <p>/*from  w  w w  .  j a  v a2s  . c  om*/
 * Search a String to find the first index of any character not in the given
 * set of characters.
 * </p>
 * 
 * <p>
 * A <code>null</code> String will return <code>-1</code>. A
 * <code>null</code> search string will return <code>-1</code>.
 * </p>
 * 
 * <pre>
 * indexOfAnyBut(null, *)            = -1
 * indexOfAnyBut("", *)              = -1
 * indexOfAnyBut(*, null)            = -1
 * indexOfAnyBut(*, "")              = -1
 * indexOfAnyBut("zzabyycdxx", "za") = 3
 * indexOfAnyBut("zzabyycdxx", "")   = 0
 * indexOfAnyBut("aba","ab")         = -1
 * </pre>
 * 
 * @param str
 *            the String to check, may be null
 * @param searchChars
 *            the chars to search for, may be null
 * @return the index of any of the chars, -1 if no match or null input
 * @since 2.0
 */
public static int indexOfAnyBut(String str, String searchChars) {
    if (isEmpty(str) || isEmpty(searchChars)) {
        return INDEX_NOT_FOUND;
    }
    int strLen = str.length();
    for (int i = 0; i < strLen; i++) {
        char ch = str.charAt(i);
        boolean chFound = searchChars.indexOf(ch) >= 0;
        if (i + 1 < strLen && Character.isHighSurrogate(ch)) {
            char ch2 = str.charAt(i + 1);
            if (chFound && searchChars.indexOf(ch2) < 0) {
                return i;
            }
        } else {
            if (!chFound) {
                return i;
            }
        }
    }
    return INDEX_NOT_FOUND;
}

From source file:com.clark.func.Functions.java

/**
 * <p>//  w ww. j a va  2s.c  o m
 * Checks that the CharSequence does not contain certain characters.
 * </p>
 * 
 * <p>
 * A <code>null</code> CharSequence will return <code>true</code>. A
 * <code>null</code> invalid character array will return <code>true</code>.
 * An empty CharSequence (length()=0) always returns true.
 * </p>
 * 
 * <pre>
 * containsNone(null, *)       = true
 * containsNone(*, null)       = true
 * containsNone("", *)         = true
 * containsNone("ab", '')      = true
 * containsNone("abab", 'xyz') = true
 * containsNone("ab1", 'xyz')  = true
 * containsNone("abz", 'xyz')  = false
 * </pre>
 * 
 * @param cs
 *            the CharSequence to check, may be null
 * @param searchChars
 *            an array of invalid chars, may be null
 * @return true if it contains none of the invalid chars, or is null
 * @since 2.0
 * @since 3.0 Changed signature from containsNone(String, char[]) to
 *        containsNone(CharSequence, char[])
 */
public static boolean containsNone(CharSequence cs, char[] searchChars) {
    if (cs == null || searchChars == null) {
        return true;
    }
    int csLen = cs.length();
    int csLast = csLen - 1;
    int searchLen = searchChars.length;
    int searchLast = searchLen - 1;
    for (int i = 0; i < csLen; i++) {
        char ch = cs.charAt(i);
        for (int j = 0; j < searchLen; j++) {
            if (searchChars[j] == ch) {
                if (Character.isHighSurrogate(ch)) {
                    if (j == searchLast) {
                        // missing low surrogate, fine, like
                        // String.indexOf(String)
                        return false;
                    }
                    if (i < csLast && searchChars[j + 1] == cs.charAt(i + 1)) {
                        return false;
                    }
                } else {
                    // ch is in the Basic Multilingual Plane
                    return false;
                }
            }
        }
    }
    return true;
}