Example usage for java.lang Character charValue

List of usage examples for java.lang Character charValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public char charValue() 

Source Link

Document

Returns the value of this Character object.

Usage

From source file:de.innovationgate.utils.WGUtils.java

/**
 * Creates a List based on string, that contains substring tokens divided by a
 * special divider string. Can be used to recreate lists that were
 * serialized by//from   w ww .j ava  2s .c  o m
 * {@link #serializeCollection serializeCollection}.
 * 
 * This command: WGUtils.deserializeCollection("a;b;c", ";")
 * 
 * Would create a list containing the three strings "a", "b" and "c".
 * 
 * 
 * @param colString
 *            The string that contains the list information
 * @param divider
 *            divider string that separates the substrings.
 * @param trimTokens
 *            Decides if the tokens are trimmed (via String.trim())
 *            before they are put into the list
 * @param stringDelimiter
 *            Describes a character that should be treated as string
 *            delimiter, like " or '. Text contained in these signs will be
 *            ignored when the split operation is done. Use null if you do
 *            not want to ignore strings.
 * @param removeTokenStringDelimiter
 *            If true and a string delimiter was given will remove delimiters that wrap whole tokens on output. So input string "'a','b'" will return strings "a" and "b" on deserialisation if the ' character was given as delimiter. 
 * @return A list consisting of the substrings inside the parameter string.
 *         Divider strings are omitted.
 */
public static List<String> deserializeCollection(String colString, String divider, boolean trimTokens,
        Character stringDelimiter, boolean removeTokenStringDelimiter) {

    List<String> col = new ArrayList<String>();
    int dividerLength = divider.length();
    if (dividerLength == 0) {
        throw new IllegalArgumentException("Cannot deserialize collection with empty string as divider");
    }

    String searchString = colString;
    if (stringDelimiter != null) {
        searchString = clearStrings(colString, stringDelimiter.charValue(),
                (divider.trim().equals("") ? 'X' : ' '));
    }

    int startPos = 0;
    int nowPos = searchString.indexOf(divider);
    String token;
    while (nowPos != -1) {
        token = colString.substring(startPos, nowPos);
        token = processDeserializedToken(token, trimTokens, stringDelimiter, removeTokenStringDelimiter);
        col.add(token);
        startPos = nowPos + dividerLength;
        nowPos = searchString.indexOf(divider, startPos);
    }

    if (startPos <= colString.length()) {
        token = colString.substring(startPos);
        token = processDeserializedToken(token, trimTokens, stringDelimiter, removeTokenStringDelimiter);
        col.add(token);
    }

    return col;
}

From source file:HTMLDecoder.java

public static String decode(String s) {
    String t;/* w w w.j a v a2 s.c  o m*/
    Character ch;
    int tmpPos, i;

    int maxPos = s.length();
    StringBuffer sb = new StringBuffer(maxPos);
    int curPos = 0;
    while (curPos < maxPos) {
        char c = s.charAt(curPos++);
        if (c == '&') {
            tmpPos = curPos;
            if (tmpPos < maxPos) {
                char d = s.charAt(tmpPos++);
                if (d == '#') {
                    if (tmpPos < maxPos) {
                        d = s.charAt(tmpPos++);
                        if (d == 'x' || d == 'X') {
                            if (tmpPos < maxPos) {
                                d = s.charAt(tmpPos++);
                                if (isHexDigit(d)) {
                                    while (tmpPos < maxPos) {
                                        d = s.charAt(tmpPos++);
                                        if (!isHexDigit(d)) {
                                            if (d == ';') {
                                                t = s.substring(curPos + 2, tmpPos - 1);
                                                try {
                                                    i = Integer.parseInt(t, 16);
                                                    if (i >= 0 && i < 65536) {
                                                        c = (char) i;
                                                        curPos = tmpPos;
                                                    }
                                                } catch (NumberFormatException e) {
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        } else if (isDigit(d)) {
                            while (tmpPos < maxPos) {
                                d = s.charAt(tmpPos++);
                                if (!isDigit(d)) {
                                    if (d == ';') {
                                        t = s.substring(curPos + 1, tmpPos - 1);
                                        try {
                                            i = Integer.parseInt(t);
                                            if (i >= 0 && i < 65536) {
                                                c = (char) i;
                                                curPos = tmpPos;
                                            }
                                        } catch (NumberFormatException e) {
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                } else if (isLetter(d)) {
                    while (tmpPos < maxPos) {
                        d = s.charAt(tmpPos++);
                        if (!isLetterOrDigit(d)) {
                            if (d == ';') {
                                t = s.substring(curPos, tmpPos - 1);
                                ch = (Character) charTable.get(t);
                                if (ch != null) {
                                    c = ch.charValue();
                                    curPos = tmpPos;
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
        sb.append(c);
    }
    return sb.toString();
}

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

/**
 * <p>//  w  w  w  . j  a  va 2  s.  c  om
 * Converts the character to a String that contains the one character.
 * </p>
 * 
 * <p>
 * For ASCII 7 bit characters, this uses a cache that will return the same
 * String object each time.
 * </p>
 * 
 * <p>
 * If <code>null</code> is passed in, <code>null</code> will be returned.
 * </p>
 * 
 * <pre>
 *   CharUtils.toString(null) = null
 *   CharUtils.toString(' ')  = " "
 *   CharUtils.toString('A')  = "A"
 * </pre>
 * 
 * @param ch
 *            the character to convert
 * @return a String containing the one specified character
 */
public static String charToString(Character ch) {
    if (ch == null) {
        return null;
    }
    return charToString(ch.charValue());
}