Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

In this page you can find the example usage for java.lang CharSequence charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>//from w w  w .  j av a2 s .com
 * Checks if the CharSequence contains only whitespace.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty CharSequence
 * (length()=0) will return {@code true}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isWhitespace(null)   = false
 * StringUtils.isWhitespace("")     = true
 * StringUtils.isWhitespace("  ")   = true
 * StringUtils.isWhitespace("abc")  = false
 * StringUtils.isWhitespace("ab2c") = false
 * StringUtils.isWhitespace("ab-c") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains whitespace, and is non-null
 * @since 3.0 Changed signature from isWhitespace(String) to
 * isWhitespace(CharSequence)
 */
public static boolean isWhitespace(CharSequence cs) {
    if (cs == null) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isWhitespace(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>/*from  w  ww  .  j a va 2  s .c  o m*/
 * Checks if the CharSequence contains only Unicode letters, digits or space
 * ({@code ' '}).
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty CharSequence
 * (length()=0) will return {@code true}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isAlphanumericSpace(null)   = false
 * StringUtils.isAlphanumericSpace("")     = true
 * StringUtils.isAlphanumericSpace("  ")   = true
 * StringUtils.isAlphanumericSpace("abc")  = true
 * StringUtils.isAlphanumericSpace("ab c") = true
 * StringUtils.isAlphanumericSpace("ab2c") = true
 * StringUtils.isAlphanumericSpace("ab-c") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains letters, digits or space, and is
 * non-null
 * @since 3.0 Changed signature from isAlphanumericSpace(String) to
 * isAlphanumericSpace(CharSequence)
 */
public static boolean isAlphanumericSpace(CharSequence cs) {
    if (cs == null) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isLetterOrDigit(cs.charAt(i)) && cs.charAt(i) != ' ') {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>//from   www .  j av  a  2s. c  om
 * Checks if the CharSequence contains only ASCII printable characters.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty CharSequence
 * (length()=0) will return {@code true}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isAsciiPrintable(null)     = false
 * StringUtils.isAsciiPrintable("")       = true
 * StringUtils.isAsciiPrintable(" ")      = true
 * StringUtils.isAsciiPrintable("Ceki")   = true
 * StringUtils.isAsciiPrintable("ab2c")   = true
 * StringUtils.isAsciiPrintable("!ab-c~") = true
 * StringUtils.isAsciiPrintable("\u0020") = true
 * StringUtils.isAsciiPrintable("\u0021") = true
 * StringUtils.isAsciiPrintable("\u007e") = true
 * StringUtils.isAsciiPrintable("\u007f") = false
 * StringUtils.isAsciiPrintable("Ceki G\u00fclc\u00fc") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if every character is in the range 32 thru 126
 * @since 3.0 Changed signature from isAsciiPrintable(String) to
 * isAsciiPrintable(CharSequence)
 */
public static boolean isAsciiPrintable(CharSequence cs) {
    if (cs == null) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!CharUtils.isAsciiPrintable(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>/*from www .  ja v  a2s  .c om*/
 * Checks if the CharSequence contains only lowercase characters.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty CharSequence
 * (length()=0) will return {@code false}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isAllLowerCase(null)   = false
 * StringUtils.isAllLowerCase("")     = false
 * StringUtils.isAllLowerCase("  ")   = false
 * StringUtils.isAllLowerCase("abc")  = true
 * StringUtils.isAllLowerCase("abC") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains lowercase characters, and is
 * non-null
 * @since 3.0 Changed signature from isAllLowerCase(String) to
 * isAllLowerCase(CharSequence)
 */
public static boolean isAllLowerCase(CharSequence cs) {
    if (cs == null || isEmpty(cs)) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isLowerCase(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>//from   w  ww. ja v  a2s .  c om
 * Checks if the CharSequence contains only uppercase characters.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty String (length()=0) will
 * return {@code false}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isAllUpperCase(null)   = false
 * StringUtils.isAllUpperCase("")     = false
 * StringUtils.isAllUpperCase("  ")   = false
 * StringUtils.isAllUpperCase("ABC")  = true
 * StringUtils.isAllUpperCase("aBC") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains uppercase characters, and is
 * non-null
 * @since 3.0 Changed signature from isAllUpperCase(String) to
 * isAllUpperCase(CharSequence)
 */
public static boolean isAllUpperCase(CharSequence cs) {
    if (cs == null || isEmpty(cs)) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isUpperCase(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>//from   w  ww  .java2  s.  c om
 * Checks if the CharSequence contains only Unicode digits. A decimal point
 * is not a Unicode digit and returns false.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty CharSequence
 * (length()=0) will return {@code false}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isNumeric(null)   = false
 * StringUtils.isNumeric("")     = false
 * StringUtils.isNumeric("  ")   = false
 * StringUtils.isNumeric("123")  = true
 * StringUtils.isNumeric("12 3") = false
 * StringUtils.isNumeric("ab2c") = false
 * StringUtils.isNumeric("12-3") = false
 * StringUtils.isNumeric("12.3") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains digits, and is non-null
 * @since 3.0 Changed "" to return false and not true
 */
public static boolean isNumeric(CharSequence cs) {
    if (cs == null || cs.length() == 0) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isDigit(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>//from   w ww .ja  v a2s  . c  o  m
 * Checks if the CharSequence contains only Unicode letters.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty CharSequence
 * (length()=0) will return {@code false}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isAlpha(null)   = false
 * StringUtils.isAlpha("")     = false
 * StringUtils.isAlpha("  ")   = false
 * StringUtils.isAlpha("abc")  = true
 * StringUtils.isAlpha("ab2c") = false
 * StringUtils.isAlpha("ab-c") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains letters, and is non-null
 * @since 3.0 Changed "" to return false and not true
 */
public static boolean isAlpha(CharSequence cs) {
    if (cs == null || cs.length() == 0) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isLetter(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>// www .j a  v  a  2  s.c  o m
 * Checks if the CharSequence contains only Unicode letters or digits.
 * </p>
 * <p/>
 * <p>
 * {@code null} will return {@code false}. An empty CharSequence
 * (length()=0) will return {@code false}.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isAlphanumeric(null)   = false
 * StringUtils.isAlphanumeric("")     = false
 * StringUtils.isAlphanumeric("  ")   = false
 * StringUtils.isAlphanumeric("abc")  = true
 * StringUtils.isAlphanumeric("ab c") = false
 * StringUtils.isAlphanumeric("ab2c") = true
 * StringUtils.isAlphanumeric("ab-c") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if only contains letters or digits, and is non-null
 * @since 3.0 Changed "" to return false and not true
 */
public static boolean isAlphanumeric(CharSequence cs) {
    if (cs == null || cs.length() == 0) {
        return false;
    }
    int sz = cs.length();
    for (int i = 0; i < sz; i++) {
        if (!Character.isLetterOrDigit(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>//from www.  j  a va  2  s.c o m
 * Checks if a CharSequence is whitespace, empty ("") or null.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.isBlank(null)      = true
 * StringUtils.isBlank("")        = true
 * StringUtils.isBlank(" ")       = true
 * StringUtils.isBlank("bob")     = false
 * StringUtils.isBlank("  bob  ") = false
 * </pre>
 *
 * @param cs the CharSequence to check, may be null
 * @return {@code true} if the CharSequence is null, empty or whitespace
 * @since 3.0 Changed signature from isBlank(String) to
 * isBlank(CharSequence)
 */
public static boolean isBlank(CharSequence cs) {
    int strLen;
    if (cs == null || (strLen = cs.length()) == 0) {
        return true;
    }
    for (int i = 0; i < strLen; i++) {
        if (!Character.isWhitespace(cs.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.sjdf.platform.xss.StringUtils.java

/**
 * <p>/*from  www .  j a  va 2  s.  c o m*/
 * Checks that the CharSequence does not contain certain characters.
 * </p>
 * <p/>
 * <p>
 * A {@code null} CharSequence will return {@code true}. A {@code null}
 * invalid character array will return {@code true}. An empty CharSequence
 * (length()=0) always returns true.
 * </p>
 * <p/>
 * <pre>
 * StringUtils.containsNone(null, *)       = true
 * StringUtils.containsNone(*, null)       = true
 * StringUtils.containsNone("", *)         = true
 * StringUtils.containsNone("ab", '')      = true
 * StringUtils.containsNone("abab", 'xyz') = true
 * StringUtils.containsNone("ab1", 'xyz')  = true
 * StringUtils.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 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;
}