Example usage for java.lang Character getType

List of usage examples for java.lang Character getType

Introduction

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

Prototype

public static int getType(int codePoint) 

Source Link

Document

Returns a value indicating a character's general category.

Usage

From source file:com.legstar.csok.client.CicsSocket.java

/**
 * After initial connect, the host should reply with an ack plus a bunch of
 * attributes used to correlate this connection with host events.
 * /* w ww .jav a2  s  . c om*/
 * @throws RequestException if ack cannot be received
 */
private void recvConnectionAck() throws RequestException {
    String ackString = null;
    try {
        InputStream in = mClientSocket.getInputStream();
        ackString = getCharsFromHost(in, mHostProtocolCharset, MAX_PROT_REPLY_LEN);
        if (ackString == null || ackString.length() == 0) {
            throw (new RequestException("No response from host."));
        }
        /* If this is not a valid ACK, it could be an error report */
        if (REPLY_ACK_MSG_EC.compareTo(ackString.substring(0, REPLY_ACK_MSG_EC.length())) != 0) {
            /*
             * Sanity check for characters being displayable. We expect the
             * host error reply to start with an error code in uppercase
             * characters.
             */
            if (Character.getType(ackString.charAt(0)) == Character.UPPERCASE_LETTER) {
                throw (new RequestException(ackString));
            } else {
                throw (new RequestException("Unrecognized response from host."));
            }
        }
    } catch (IOException e) {
        throw (new RequestException(e));
    }
    if (_log.isDebugEnabled()) {
        _log.debug("Connection:" + mConnectionID + " Connection Ack received." + ackString);
    }
}

From source file:XmlChars.java

private static boolean isLetter2(char c) {
    // [84] Letter ::= BaseChar | Ideographic
    // [85] BaseChar ::= ... too much to repeat
    // [86] Ideographic ::= ... too much to repeat
    // [87] CombiningChar ::= ... too much to repeat

    ///*  w  w  w  .  j av  a2s.c  o  m*/
    // Optimize the typical case.
    //
    if (c >= 'a' && c <= 'z')
        return true;
    if (c == '>')
        return false;
    if (c >= 'A' && c <= 'Z')
        return true;

    //
    // Since the tables are too ridiculous to use in code,
    // we're using the footnotes here to drive this test.
    //
    switch (Character.getType(c)) {
    // app. B footnote says these are 'name start'
    // chars' ...
    case Character.LOWERCASE_LETTER: // Ll
    case Character.UPPERCASE_LETTER: // Lu
    case Character.OTHER_LETTER: // Lo
    case Character.TITLECASE_LETTER: // Lt
    case Character.LETTER_NUMBER: // Nl
        // ... and these are name characters 'other
        // than name start characters'
    case Character.COMBINING_SPACING_MARK: // Mc
    case Character.ENCLOSING_MARK: // Me
    case Character.NON_SPACING_MARK: // Mn
    case Character.MODIFIER_LETTER: // Lm
    case Character.DECIMAL_DIGIT_NUMBER: // Nd

        // OK, here we just have some exceptions to check...
        return !isCompatibilityChar(c)
                // per "5.14 of Unicode", rule out some combiners
                && !(c >= 0x20dd && c <= 0x20e0);

    default:
        // added a character ...
        return c == 0x0387;
    }
}

From source file:org.grails.datastore.bson.json.JsonWriter.java

private void writeStringHelper(final String str) throws IOException {
    writer.write('"');
    for (final char c : str.toCharArray()) {
        switch (c) {
        case '"':
            writer.write("\\\"");
            break;
        case '\\':
            writer.write("\\\\");
            break;
        case '\b':
            writer.write("\\b");
            break;
        case '\f':
            writer.write("\\f");
            break;
        case '\n':
            writer.write("\\n");
            break;
        case '\r':
            writer.write("\\r");
            break;
        case '\t':
            writer.write("\\t");
            break;
        default://from w  w  w  . ja  v a  2 s.c om
            switch (Character.getType(c)) {
            case Character.UPPERCASE_LETTER:
            case Character.LOWERCASE_LETTER:
            case Character.TITLECASE_LETTER:
            case Character.OTHER_LETTER:
            case Character.DECIMAL_DIGIT_NUMBER:
            case Character.LETTER_NUMBER:
            case Character.OTHER_NUMBER:
            case Character.SPACE_SEPARATOR:
            case Character.CONNECTOR_PUNCTUATION:
            case Character.DASH_PUNCTUATION:
            case Character.START_PUNCTUATION:
            case Character.END_PUNCTUATION:
            case Character.INITIAL_QUOTE_PUNCTUATION:
            case Character.FINAL_QUOTE_PUNCTUATION:
            case Character.OTHER_PUNCTUATION:
            case Character.MATH_SYMBOL:
            case Character.CURRENCY_SYMBOL:
            case Character.MODIFIER_SYMBOL:
            case Character.OTHER_SYMBOL:
                writer.write(c);
                break;
            default:
                writer.write("\\u");
                writer.write(Integer.toHexString((c & 0xf000) >> 12));
                writer.write(Integer.toHexString((c & 0x0f00) >> 8));
                writer.write(Integer.toHexString((c & 0x00f0) >> 4));
                writer.write(Integer.toHexString(c & 0x000f));
                break;
            }
            break;
        }
    }
    writer.write('"');
}

From source file:org.eclipse.jdt.ls.core.internal.contentassist.JavadocCompletionProposal.java

private String prepareTemplateComment(String comment, String indentation, IJavaProject project,
        String lineDelimiter) {/*from w  w  w.  ja  va  2s. c  o m*/
    //   trim comment start and end if any
    if (comment.endsWith("*/")) {
        comment = comment.substring(0, comment.length() - 2);
    }
    comment = comment.trim();
    if (comment.startsWith("/*")) { //$NON-NLS-1$
        if (comment.length() > 2 && comment.charAt(2) == '*') {
            comment = comment.substring(3); // remove '/**'
        } else {
            comment = comment.substring(2); // remove '/*'
        }
    }
    // trim leading spaces, but not new lines
    int nonSpace = 0;
    int len = comment.length();
    while (nonSpace < len && Character.getType(comment.charAt(nonSpace)) == Character.SPACE_SEPARATOR) {
        nonSpace++;
    }
    comment = comment.substring(nonSpace);
    return comment;
}

From source file:CharUtils.java

/**
 * True if character is a dash of some kind.
 * // w  w w .j  a  v  a2  s  . co  m
 * @param c
 *            Character to check for being a dash.
 * 
 * @return true if character is a dash.
 */

public static boolean isDash(char c) {
    return Character.getType(c) == Character.DASH_PUNCTUATION;
}

From source file:CharUtils.java

/**
 * True if string contains a dash of some kind.
 * /*  ww  w. ja  v  a2 s.  com*/
 * @param s
 *            String to check for containing a dash.
 * 
 * @return true if string contains a dash.
 */

public static boolean hasDash(String s) {
    boolean result = false;

    for (int i = 0; i < s.length(); i++) {
        result = (Character.getType(s.charAt(i)) == Character.DASH_PUNCTUATION);

        if (result)
            break;
    }

    return result;
}

From source file:CharUtils.java

/**
 * Evict dashes from a string.//from www.  j  a  v  a  2 s . co m
 * 
 * @param s
 *            String from which to evict dashes.
 * 
 * @return String with dashes evicted.
 */

public static String evictDashes(String s) {
    StringBuffer result = new StringBuffer();

    for (int i = 0; i < s.length(); i++) {
        if (Character.getType(s.charAt(i)) != Character.DASH_PUNCTUATION) {
            result.append(s.charAt(i));
        }
    }

    return result.toString();
}

From source file:org.apache.slider.common.tools.SliderUtils.java

public static boolean oldIsClusternameValid(String name) {
    if (name == null || name.isEmpty()) {
        return false;
    }// w  w w . j  a v a2 s . c om
    int first = name.charAt(0);
    if (0 == (Character.getType(first) & Character.LOWERCASE_LETTER)) {
        return false;
    }

    for (int i = 0; i < name.length(); i++) {
        int elt = (int) name.charAt(i);
        int t = Character.getType(elt);
        if (0 == (t & Character.LOWERCASE_LETTER) && 0 == (t & Character.DECIMAL_DIGIT_NUMBER) && elt != '-'
                && elt != '_') {
            return false;
        }
        if (!Character.isLetterOrDigit(elt) && elt != '-' && elt != '_') {
            return false;
        }
    }
    return true;
}

From source file:net.sf.morph.transform.converters.TextToNumberConverter.java

/**
 * Remove any characters that should be ignored when performing the
 * conversion./*from  w w w . j  a  va  2 s  .  com*/
 * 
 * @param string
 *            the input string
 * @param locale
 *            the locale
 * @return <code>string</code>, with all characters that should be
 *         ignored removed
 */
private StringBuffer removeIgnoredCharacters(String string, Locale locale) {
    StringBuffer charactersToParse = new StringBuffer();
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
    for (int i = 0; i < string.length(); i++) {
        char currentChar = string.charAt(i);
        if (getWhitespaceHandling() == WHITESPACE_IGNORE && Character.isWhitespace(currentChar)) {
            continue;
        }
        if (getCurrencyHandling() == CURRENCY_IGNORE
                && Character.getType(currentChar) == Character.CURRENCY_SYMBOL) {
            continue;
        }
        if (getPercentageHandling() == PERCENTAGE_IGNORE) {
            if (currentChar == symbols.getPercent()) {
                continue;
            }
        }
        if (getParenthesesHandling() == PARENTHESES_IGNORE) {
            if (currentChar == LEFT_PARENTHESES || currentChar == RIGHT_PARENTHESES) {
                continue;
            }
        }
        charactersToParse.append(currentChar);
    }
    return charactersToParse;
}

From source file:ome.services.blitz.test.utests.FilePathRestrictionsTest.java

/**
 * Test that transformation matrices are transitively closed upon combination.
 *//* w w  w  .  ja  v a 2s  .com*/
@Test
public void testTransitiveTransformationClosure() {
    final SetMultimap<Integer, Integer> transformationMatrixX = HashMultimap.create();
    final SetMultimap<Integer, Integer> transformationMatrixY = HashMultimap.create();
    final SetMultimap<Integer, Integer> transformationMatrixZ = HashMultimap.create();
    final SetMultimap<Integer, Integer> transformationMatrixXYZ = HashMultimap.create();

    for (int codePoint = 0; codePoint < 0x100; codePoint++) {
        if (Character.getType(codePoint) == Character.CONTROL) {
            transformationMatrixXYZ.put(codePoint, 90);
        }
    }

    /*
     * 65  66
     *       
     *      67   68
     *          
     *      70   69
     */

    transformationMatrixX.put(65, 66);
    transformationMatrixX.put(65, 67);

    transformationMatrixY.put(66, 67);
    transformationMatrixY.put(66, 68);

    transformationMatrixZ.put(67, 70);
    transformationMatrixZ.put(68, 69);

    transformationMatrixXYZ.put(65, 69);
    transformationMatrixXYZ.put(65, 70);
    transformationMatrixXYZ.put(66, 69);
    transformationMatrixXYZ.put(66, 70);
    transformationMatrixXYZ.put(67, 70);
    transformationMatrixXYZ.put(68, 69);

    final Set<Character> safeCharacters = ImmutableSet.of('Z');

    final FilePathRestrictions rulesX = new FilePathRestrictions(transformationMatrixX, null, null, null,
            safeCharacters);
    final FilePathRestrictions rulesY = new FilePathRestrictions(transformationMatrixY, null, null, null,
            safeCharacters);
    final FilePathRestrictions rulesZ = new FilePathRestrictions(transformationMatrixZ, null, null, null,
            safeCharacters);

    final FilePathRestrictions rulesXYZ = FilePathRestrictions.combineFilePathRestrictions(rulesX, rulesY,
            rulesZ);
    assertEqualMultimaps(rulesXYZ.transformationMatrix, transformationMatrixXYZ);

    final FilePathRestrictions rulesZYX = FilePathRestrictions.combineFilePathRestrictions(rulesZ, rulesY,
            rulesX);
    assertEqualMultimaps(rulesZYX.transformationMatrix, transformationMatrixXYZ);
}