Example usage for java.lang Character MIN_SUPPLEMENTARY_CODE_POINT

List of usage examples for java.lang Character MIN_SUPPLEMENTARY_CODE_POINT

Introduction

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

Prototype

int MIN_SUPPLEMENTARY_CODE_POINT

To view the source code for java.lang Character MIN_SUPPLEMENTARY_CODE_POINT.

Click Source Link

Document

The minimum value of a <a href="http://www.unicode.org/glossary/#supplementary_code_point"> Unicode supplementary code point</a>, constant U+10000 .

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out//from  ww  w .j  av a 2  s  .  com
            .println("Character.MIN_SUPPLEMENTARY_CODE_POINT:" + (int) Character.MIN_SUPPLEMENTARY_CODE_POINT);
}

From source file:Main.java

/**
 * This method descodes a string that was previously encoded for being XML
 * safe. It is the exact opposite of xmlEncode
 *
 * @param s the string to decode//from  ww  w. j  av  a  2 s. com
 * @return the decoded string
 * @exception IllegalArgumentException if the string cannot be decoded */
public static String xmlDecode(String s) throws IllegalArgumentException {
    if (s == null)
        return s;

    int idxS = s.indexOf('&');
    if (idxS < 0)
        return s;

    StringBuilder sb = new StringBuilder(s.length());

    int idxE, idx, size;
    char c, c_1;
    int prev = 0;

    while (idxS != -1) {
        idxE = s.indexOf(';', idxS);
        if (idxE < 0)
            throw new IllegalArgumentException("missing ';' in: " + s.substring(idxS));

        sb.append(s.substring(prev, idxS));

        idx = idxS + 1;
        size = idxE - idxS - 1;
        if (size < 2)
            throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
        c = s.charAt(idx);
        c_1 = s.charAt(idx + 1);
        switch (c) {
        case 'l':
            if (size != 2)
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            if (c_1 == 't')
                sb.append('<');
            else
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            break;

        case 'g':
            if (size != 2)
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            if (c_1 == 't')
                sb.append('>');
            else
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            break;

        case 'q':
            if (size != 4)
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            if (c_1 != 'u' || s.charAt(idx + 2) != 'o' || s.charAt(idx + 3) != 't')
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            else
                sb.append('"');
            break;

        case 'a':
            if (size == 3) {
                if (c_1 != 'm' || s.charAt(idx + 2) != 'p')
                    throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
                else
                    sb.append('&');
            } else if (size == 4) {
                if (c_1 != 'p' || s.charAt(idx + 2) != 'o' || s.charAt(idx + 3) != 's')
                    throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
                else
                    sb.append('\'');
            } else
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            break;

        case '#':
            int codePoint;
            try {
                codePoint = (c_1 == 'x') ? Integer.parseInt(s.substring(idx + 2, idxE), 16)
                        : Integer.parseInt(s.substring(idx + 1, idxE));
            } catch (NumberFormatException ex) {
                throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
            }

            if (codePoint < 0)
                throw new IllegalArgumentException(
                        "invalid character codepoint: " + s.substring(idxS, idxE + 1));

            if (codePoint < Character.MIN_SUPPLEMENTARY_CODE_POINT)
                sb.append((char) codePoint);
            else
                sb.append(Character.toChars(codePoint));
            break;

        default:
            throw new IllegalArgumentException("invalid escape tag: " + s.substring(idxS, idxE + 1));
        }
        prev = idxE + 1;
        idxS = s.indexOf("&", prev);
    }
    if (prev < s.length())
        sb.append(s.substring(prev));

    return sb.toString();
}

From source file:com.buaa.cfs.io.UTF8.java

private static char highSurrogate(int codePoint) {
    return (char) ((codePoint >>> 10)
            + (Character.MIN_HIGH_SURROGATE - (Character.MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
}