Example usage for java.lang Character isDefined

List of usage examples for java.lang Character isDefined

Introduction

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

Prototype

public static boolean isDefined(int codePoint) 

Source Link

Document

Determines if a character (Unicode code point) is defined in Unicode.

Usage

From source file:Main.java

public static void main(String[] args) {
    char ch = '@';
    boolean b = Character.isDefined(ch);
    System.out.println("Character " + ch + " has defined meaning in Unicode is " + b);
}

From source file:Main.java

public static void main(String[] args) {
    int cp = 0x011111;
    boolean b = Character.isDefined(cp);
    System.out.println("cp has defined meaning in Unicode is " + b);
}

From source file:Main.java

public static void main(String[] args) throws java.io.IOException {
    char c = 'a';

    System.out.println("Character = " + (int) c);
    System.out.println("Defined = " + Character.isDefined(c));
    System.out.println("Digit = " + Character.isDigit(c));
    System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
    System.out.println("ISO control = " + Character.isISOControl(c));
    System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
    System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
    System.out.println("Letter = " + Character.isLetter(c));
    System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
    System.out.println("Lowercase = " + Character.isLowerCase(c));
    System.out.println("Space = " + Character.isSpaceChar(c));
    System.out.println("Titlecase = " + Character.isTitleCase(c));
    System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
    System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
    System.out.println("Uppercase = " + Character.isUpperCase(c));
    System.out.println("White space = " + Character.isWhitespace(c));

    byte[] types = { Character.COMBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION, Character.CONTROL,
            Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION, Character.DECIMAL_DIGIT_NUMBER,
            Character.ENCLOSING_MARK, Character.END_PUNCTUATION, Character.FORMAT, Character.LETTER_NUMBER,
            Character.LINE_SEPARATOR, Character.LOWERCASE_LETTER, Character.MATH_SYMBOL,
            Character.MODIFIER_SYMBOL, Character.NON_SPACING_MARK, Character.OTHER_LETTER,
            Character.OTHER_NUMBER, Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL,
            Character.PARAGRAPH_SEPARATOR, Character.PRIVATE_USE, Character.SPACE_SEPARATOR,
            Character.START_PUNCTUATION, Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
            Character.UPPERCASE_LETTER };

    String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control", "Currency symbol",
            "Dash punctuation", "Decimal digit number", "Enclosing mark", "End punctuation", "Format",
            "Letter number", "Line separator", "Lowercase letter", "Math symbol", "Modifier symbol",
            "Non spacing mark", "Other letter", "Other number", "Other punctuation", "Other symbol",
            "Paragraph separator", "Private use", "Space separator", "Start punctuation", "Surrogate",
            "Titlecase letter", "Unassigned", "Uppercase letter" };

    int type = Character.getType(c);

    for (int i = 0; i < types.length; i++)
        if (type == types[i]) {
            System.out.println("Type name = " + typeNames[i]);
            break;
        }/*from w w  w. java  2  s  .co m*/

    System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}

From source file:Classify.java

public static void main(String[] args) throws java.io.IOException {
    char c = '\u0beb'; // Tamil digit.

    System.out.println("Character = " + (int) c);
    System.out.println("Defined = " + Character.isDefined(c));
    System.out.println("Digit = " + Character.isDigit(c));
    System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
    System.out.println("ISO control = " + Character.isISOControl(c));
    System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
    System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
    System.out.println("Letter = " + Character.isLetter(c));
    System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
    System.out.println("Lowercase = " + Character.isLowerCase(c));
    System.out.println("Space = " + Character.isSpaceChar(c));
    System.out.println("Titlecase = " + Character.isTitleCase(c));
    System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
    System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
    System.out.println("Uppercase = " + Character.isUpperCase(c));
    System.out.println("White space = " + Character.isWhitespace(c));

    byte[] types = { Character.COMBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION, Character.CONTROL,
            Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION, Character.DECIMAL_DIGIT_NUMBER,
            Character.ENCLOSING_MARK, Character.END_PUNCTUATION, Character.FORMAT, Character.LETTER_NUMBER,
            Character.LINE_SEPARATOR, Character.LOWERCASE_LETTER, Character.MATH_SYMBOL,
            Character.MODIFIER_SYMBOL, Character.NON_SPACING_MARK, Character.OTHER_LETTER,
            Character.OTHER_NUMBER, Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL,
            Character.PARAGRAPH_SEPARATOR, Character.PRIVATE_USE, Character.SPACE_SEPARATOR,
            Character.START_PUNCTUATION, Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
            Character.UPPERCASE_LETTER };

    String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control", "Currency symbol",
            "Dash punctuation", "Decimal digit number", "Enclosing mark", "End punctuation", "Format",
            "Letter number", "Line separator", "Lowercase letter", "Math symbol", "Modifier symbol",
            "Non spacing mark", "Other letter", "Other number", "Other punctuation", "Other symbol",
            "Paragraph separator", "Private use", "Space separator", "Start punctuation", "Surrogate",
            "Titlecase letter", "Unassigned", "Uppercase letter" };

    int type = Character.getType(c);

    for (int i = 0; i < types.length; i++)
        if (type == types[i]) {
            System.out.println("Type name = " + typeNames[i]);
            break;
        }/*from   w  ww  .  j av a  2 s.c  o m*/

    System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}

From source file:it.geosolutions.httpproxy.utils.Utils.java

/**
 * @param ch//  w  w  w.j  a  v  a2 s .c o m
 * @return
 */
final static int escapeHtmlFull(int ch) {
    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9') {
        // safe
        return ch;
    } else if (Character.isWhitespace(ch)) {
        if (ch != '\n' && ch != '\r' && ch != '\t')
            // safe
            return ch;
    } else if (Character.isDefined(ch)) {
        // safe
        return ch;
    } else if (Character.isISOControl(ch)) {
        // paranoid version:isISOControl which are not isWhitespace
        // removed !
        // do nothing do not include in output !
        return -1;
    } else if (Character.isHighSurrogate((char) ch)) {
        // do nothing do not include in output !
        return -1;
    } else if (Character.isLowSurrogate((char) ch)) {
        // wrong char[] sequence, //TODO: LOG !!!
        return -1;
    }

    return -1;
}

From source file:com.nesscomputing.syslog4j.impl.message.modifier.escape.HTMLEntityEscapeSyslogMessageModifier.java

/**
 * escapeHtml(String) is based partly on the article posted here: http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java
 * with the addition of common characters and modifications for Java 1.4 support.
 *
 * @param message/*from  w w w  .  j  ava 2s  .c om*/
 * @return Returns a message where any HTML entity characters are escaped.
 */
public static String escapeHtml(String message) {
    StringBuffer b = new StringBuffer(message.length());

    for (int i = 0; i < message.length(); i++) {
        char ch = message.charAt(i);

        if (ch == '<') {
            b.append("&lt;");
        } else if (ch == '>') {
            b.append("&gt;");
        } else if (ch == '"') {
            b.append("&quot;");
        } else if (ch == '\'') {
            b.append("&#39;");
        } else if (ch == '&') {
            b.append("&amp;");
        } else if (ch >= ' ' && ch <= '~') {
            b.append(ch);
        } else if (Character.isWhitespace(ch)) {
            b.append("&#").append((int) ch).append(";");
        } else if (Character.isISOControl(ch)) {
            continue; // Ignore character
        } else if (Character.isDefined(ch)) {
            b.append("&#").append((int) ch).append(";");
        }
    }

    return b.toString();
}

From source file:ddf.catalog.transformer.xml.EscapingPrintWriter.java

private static boolean isWellKnownCharacter(char c) {
    return Character.isDefined(c) && !Character.isISOControl(c) && !Character.isSurrogate(c);
}

From source file:net.sf.keystore_explorer.utilities.io.HexUtil.java

private static String getHexClearLineDump(byte[] bytes, int len) {
    StringBuffer sbHex = new StringBuffer();
    StringBuffer sbClr = new StringBuffer();

    for (int cnt = 0; cnt < len; cnt++) {
        // Convert byte to int
        byte b = bytes[cnt];
        int i = b & 0xFF;

        // First part of byte will be one hex char
        int i1 = (int) Math.floor(i / 16);

        // Second part of byte will be one hex char
        int i2 = i % 16;

        // Get hex characters
        sbHex.append(Character.toUpperCase(Character.forDigit(i1, 16)));
        sbHex.append(Character.toUpperCase(Character.forDigit(i2, 16)));

        if ((cnt + 1) < len) {
            // Divider between hex characters
            sbHex.append(' ');
        }//ww w. ja  v  a 2s. co  m

        // Get clear character

        // Character to display if character not defined in Unicode or is a
        // control charcter
        char c = '.';

        // Not a control character and defined in Unicode
        if ((!Character.isISOControl((char) i)) && (Character.isDefined((char) i))) {
            Character clr = new Character((char) i);
            c = clr.charValue();
        }

        sbClr.append(c);
    }

    /*
     * Put both dumps together in one string (hex, clear) with appropriate
     * padding between them (pad to array length)
     */
    StringBuffer strBuff = new StringBuffer();

    strBuff.append(sbHex.toString());

    int i = bytes.length - len;
    for (int cnt = 0; cnt < i; cnt++) {
        strBuff.append("   "); // Each missing byte takes up three spaces
    }

    strBuff.append("   "); // The gap between hex and clear output is three
    // spaces
    strBuff.append(sbClr.toString());

    return strBuff.toString();
}

From source file:net.opentsdb.contrib.tsquare.ExtendedTsdbMetricParser.java

private Metric parseSingleMetricWithoutTags(final String metricString) {
    Metric metric = null;// w w w.jav a  2  s.  com

    if (metricString.indexOf(':') < 0) {
        // EXTENSION: This is a metric only expression. We auto-detect the aggregator
        // based on the metric name, or use the default.
        Aggregator agg = aggregatorFactory.getAggregatorForMetric(metricString);
        metric = new Metric(metricString, metricString, (agg == null ? defaultAggregator : agg));
    } else {
        // Otherwise, this might be a standard expression with some extra sauce...
        final String[] parts = StringUtils.delimitedListToStringArray(metricString, ":");
        Preconditions.checkState(parts.length > 1, "Invalid metric: %s", metricString);

        // Metric name is always the last element, regardless of format.  ASSUMING we've stripped
        // tag expressions off the end.
        final String metricName = parts[parts.length - 1];

        // EXTENSION: Logic in determineAggregator() allows for empty or auto-detect 
        // aggregators.  See the doc on that method for details.
        metric = new Metric(metricString, metricName, determineAggregator(metricName, parts[0]));

        // Handle parsing of rate and downsampler.
        if (parts.length > 2 && parts.length <= 4) {
            for (int i = 1; i < parts.length - 1; i++) {
                final String p = parts[i];
                if ("rate".equals(p)) {
                    metric.setRate(true);
                } else if (Character.isDefined(p.charAt(0)) && p.indexOf('-') > 0) { // 1h-sum
                    final String[] downsampleParts = StringUtils.split(p, "-");
                    long downsampleMillis = new DateTimeExpressionParser().setBaseTimeMillis(0) // ... parse a relative duration
                            .setPositiveOffset(true).parseRequired(downsampleParts[0]);

                    // Convert to epoch SECONDS.
                    metric.setDownsampleIntervalSeconds(
                            (int) TimeUnit.MILLISECONDS.toSeconds(downsampleMillis));

                    // EXTENSION: Again, determineAggregator() allows for empty or auto-detected
                    // downsamplers.
                    metric.setDownsampler(determineAggregator(metricName, downsampleParts[1]));
                } else {
                    throw new IllegalStateException("Invalid characters in metric: " + p);
                }
            }
        } else if (parts.length != 2) {
            throw new IllegalStateException("Metric has invalid parsed length: " + parts.length);
        }
    }

    return metric;
}

From source file:com.gatf.xstream.GatfPrettyPrintWriter.java

private void writeText(String text, boolean isAttribute) {
    int length = text.length();
    for (int i = 0; i < length; i++) {
        char c = text.charAt(i);
        switch (c) {
        case '\0':
            if (mode == XML_QUIRKS) {
                this.writer.write(NULL);
            } else {
                throw new StreamException("Invalid character 0x0 in XML stream");
            }//from   w  w w . ja  v  a  2s  . co  m
            break;
        case '&':
            this.writer.write(AMP);
            break;
        case '<':
            this.writer.write(LT);
            break;
        case '>':
            this.writer.write(GT);
            break;
        case '"':
            this.writer.write(QUOT);
            break;
        case '\'':
            this.writer.write(APOS);
            break;
        case '\r':
            this.writer.write(CR);
            break;
        case '\t':
        case '\n':
            if (!isAttribute) {
                this.writer.write(c);
                break;
            }
        default:
            if (Character.isDefined(c) && !Character.isISOControl(c)) {
                if (mode != XML_QUIRKS) {
                    if (c > '\ud7ff' && c < '\ue000') {
                        throw new StreamException(
                                "Invalid character 0x" + Integer.toHexString(c) + " in XML stream");
                    }
                }
                this.writer.write(c);
            } else {
                if (mode == XML_1_0) {
                    if (c < 9 || c == '\u000b' || c == '\u000c' || c == '\u000e'
                            || (c >= '\u000f' && c <= '\u001f')) {
                        throw new StreamException(
                                "Invalid character 0x" + Integer.toHexString(c) + " in XML 1.0 stream");
                    }
                }
                if (mode != XML_QUIRKS) {
                    if (c == '\ufffe' || c == '\uffff') {
                        throw new StreamException(
                                "Invalid character 0x" + Integer.toHexString(c) + " in XML stream");
                    }
                }
                this.writer.write("&#x");
                this.writer.write(Integer.toHexString(c));
                this.writer.write(';');
            }
        }
    }
}