Example usage for java.lang Character isISOControl

List of usage examples for java.lang Character isISOControl

Introduction

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

Prototype

public static boolean isISOControl(int codePoint) 

Source Link

Document

Determines if the referenced character (Unicode code point) is an ISO control character.

Usage

From source file:Main.java

public static void main(String[] args) {
    int cp1 = 0x008f, cp2 = 0x0123;

    boolean b1 = Character.isISOControl(cp1);
    boolean b2 = Character.isISOControl(cp2);

    System.out.println(b1);/*from  www.j a v a2 s  .  co  m*/
    System.out.println(b2);
}

From source file:Main.java

public static void main(String[] args) {
    char ch1 = ':', ch2 = '\u0013';

    boolean b1 = Character.isISOControl(ch1);
    boolean b2 = Character.isISOControl(ch2);

    System.out.println(b1);//from w w  w  .  j ava  2  s .co  m
    System.out.println(b2);
}

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;
        }// ww  w .  j  av a  2s .c o 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 a  va  2  s .  c om*/

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

From source file:Main.java

public static boolean isPrintableChar(char c) {
    Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
    return (!Character.isISOControl(c)) && block != null && block != Character.UnicodeBlock.SPECIALS;
}

From source file:com.twosigma.beaker.shared.module.util.ControlCharacterUtils.java

public static String escapeControlCharacters(final String value) {
    if (StringUtils.isNotEmpty(value)) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < value.length(); i++) {
            if (Character.isISOControl(value.charAt(i))) {
                sb.append(StringEscapeUtils.escapeJson(value.substring(i, i + 1)));
            } else {
                sb.append(value.charAt(i));
            }//from w w  w . ja va 2  s .c om
        }
        return sb.toString();
    }
    return StringUtils.EMPTY;
}

From source file:Main.java

/**
 * Encode a string so that it can be safely used as attribute value in
 * XML output./* w w  w.  j  av a2s .co  m*/
 * @param attribute the attribute value to be encoded.
 * @return a string representing the attribute value that can be safely
 *         used in XML output.
 */
public static String attributeEscape(String attribute) {
    final StringBuffer sb = new StringBuffer();
    if (attribute != null) {
        char c;
        final int l = attribute.length();
        for (int i = 0; i < l; i++) {
            c = attribute.charAt(i);
            switch (c) {
            case '<':
                sb.append("&lt;");
                break;
            case '>':
                sb.append("&gt;");
                break;
            case '\'':
                sb.append("&apos;");
                break;
            case '"':
                sb.append("&quot;");
                break;
            case '&':
                sb.append("&amp;");
                break;
            default:
                if (c > Byte.MAX_VALUE || Character.isISOControl(c)) {
                    sb.append("&#x");
                    sb.append(Integer.toHexString(c));
                    sb.append(';');
                } else {
                    sb.append(c);
                }
            }
        }
    }
    return sb.toString();
}

From source file:com.twosigma.beaker.shared.module.util.ControlCharacterUtils.java

public static boolean containsControlCharacters(final String value) {
    if (StringUtils.isNotEmpty(value)) {
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            if (!Character.isWhitespace(c) && Character.isISOControl(c)) {
                return true;
            }// w w w  . j  a v a 2s  .  com
        }
    }
    return false;
}

From source file:Main.java

/***
 * Fast xml formatter without loading xml into a document or using a 
 * serializer. //from   w  w  w  .  j a v a  2  s. co m
 * 
 * @param content
 * @param lineBreaker
 * @param nodeSpacer
 * @return
 */
public static String prettyPrintNoDoc(String content, String lineBreaker, String nodeSpacer) {

    if (content == null || content.length() == 0) {
        return null;
    } else {
        StringBuilder prettyPrintBuilder = new StringBuilder(content.length() + 200);

        boolean inQuote = false;
        boolean inData = false;
        int nodeDepth = 0;
        char prevCh = 0;
        char lastMeaningfulChar = 0;

        for (int i = 0; i < content.length(); i++) {

            char ch = content.charAt(i);

            char nextCh = i < content.length() - 1 ? content.charAt(i + 1) : 0;

            if (inData) { // We are in <!-- or <!CDATA[[ block, find when to
                          // exit it
                if ('>' == ch && prettyPrintBuilder.length() >= 2) {
                    String lastTwoChar = prettyPrintBuilder.substring(prettyPrintBuilder.length() - 2);
                    if ("--".equals(lastTwoChar) || "]]".equals(lastTwoChar)) {
                        inData = false;

                        lastMeaningfulChar = '>';
                    }
                }

                prettyPrintBuilder.append(ch);

            } else if (inQuote) { // in the quote, fine when to exit it
                if ('"' == ch) {
                    inQuote = false;
                }

                prettyPrintBuilder.append(ch);

            } else { // Not in quote or data
                if (Character.isWhitespace(ch)) {
                    if (!Character.isISOControl(prevCh) && !Character.isWhitespace(prevCh) && '>' != prevCh) {
                        prettyPrintBuilder.append(' ');
                    }
                    ch = 0;
                } else if ('"' == ch) {
                    inQuote = true;
                } else if ('<' == ch) { // We are at the start of a node

                    if ('?' == nextCh) { // Start declaration node
                        // move the nodeDepth to -1;
                        nodeDepth = -1;
                    } else if ('!' == nextCh) { // Start Data node
                        inData = true;
                        prettyPrintBuilder.append(lineBreaker);
                        appendSpace(prettyPrintBuilder, nodeSpacer, nodeDepth + 1);
                    } else if (i > 1) { // We are at the start of a regular
                        // node or closing a regular node

                        if ('>' == lastMeaningfulChar) { // A node just
                            // finished
                            // above
                            prettyPrintBuilder.append(lineBreaker);

                            if ('/' == nextCh) {// At closing of an node
                                // section </
                                appendSpace(prettyPrintBuilder, nodeSpacer, nodeDepth);
                                nodeDepth--;
                            } else { // At starting of a node
                                nodeDepth++;
                                appendSpace(prettyPrintBuilder, nodeSpacer, nodeDepth);
                            }
                        } else if ('/' == nextCh) { // At closing of an node
                            nodeDepth--;
                        }

                    }
                } else if ('/' == ch && '>' == nextCh) { // closing a node with />
                    nodeDepth--;
                }

                if (!Character.isISOControl(ch) && ch != 0) {
                    prettyPrintBuilder.append(ch);

                    if (!Character.isWhitespace(ch)) {
                        lastMeaningfulChar = ch;
                    }
                }
            }

            prevCh = ch;
        }
        return prettyPrintBuilder.toString();
    }

}

From source file:com.exalttech.trex.ui.views.streams.viewer.PacketParser.java

/**
 * Format payload//w w w  . j ava 2s. co  m
 *
 * @param payLoad
 * @return
 */
static String formatPayLoad(String payLoad) {
    int line = 0;
    String dim;
    StringBuilder finalHex = new StringBuilder();
    char[] arr = payLoad.toCharArray();

    for (int i = 0; i < arr.length; i++) {
        line++;
        dim = "";
        if (line == 16) {
            dim = "\n";
            line = 0;
        }
        int nVal = (int) arr[i];
        // Is character ISO control
        boolean bISO = Character.isISOControl(arr[i]);
        // Is Ignorable identifier
        boolean bIgnorable = Character.isIdentifierIgnorable(arr[i]);
        // Remove tab and other unwanted characters..
        if (nVal == 9 || bISO || bIgnorable) {
            arr[i] = '.';
        } else if (nVal > 255) {
            arr[i] = '.';
        }
        if (arr[i] == '\n' || arr[i] == '\r' || arr[i] == ' ' || arr[i] == '\0') {
            finalHex.append('.').append(dim);
        } else {
            finalHex.append(arr[i]).append(dim);
        }
    }
    return finalHex.toString();
}