Checks if the given character c is a spacing modifier. - Java java.lang

Java examples for java.lang:char

Description

Checks if the given character c is a spacing modifier.

Demo Code

/*// w w  w.  j  av a 2s .  c  o  m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package com.java2s;

public class Main {
    /**
     * Checks if the given character c is a spacing modifier.
     * @param c the character to check
     * @return true of the character is a spacing modifier.
     */
    public static boolean isSpacingModifier(final char c) {
        final int cval = (int) c;
        final int hiByte = cval >>> 8;
        switch (hiByte) {
        case 0x02: // SPACING MODIFIERS
            return isInRange(c, 0x02B0, 0x02FF);

        case 0x03: // GREEK
            return c == 0x0374 || c == 0x037A;

        case 0x05: // ARMENIAN
            return c == 0x0559;

        case 0x06: // ARABIC
            return c == 0x0640 || c == 0x06E5 || c == 0x06E6;

        case 0x07: // NKO
            return c == 0x07F4 || c == 0x07F5 || c == 0x07FA;

        case 0x09: // DEVANAGARI
            return c == 0x0971;

        case 0x0E: // THAI, LAO
            return c == 0x0E46 || c == 0x0EC6;

        case 0x10: // GEORGIAN
            return c == 0x10FC;

        case 0x17: // KHMER
            return c == 0x17D7;

        case 0x18: // MONGOLIAN
            return c == 0x1843;

        case 0x1C: // OL CHIKI
            return isInRange(c, 0x1C78, 0x1C7D);

        case 0x1D: // Additional Modifiers
            return isInRange(c, 0x1D2C, 0x1D61) || c == 0x1D78
                    || isInRange(c, 0x1D9B, 0x1DBF)
                    || isInRange(c, 0x20E8, 0x20F0);

        case 0x20:
            return isInRange(c, 0x2090, 0x2094);

        case 0x2C:
            return c == 0x2C7D;

        case 0x2D: // TIFINAGH
            return c == 0x2D6F;

        case 0x2E:
            return c == 0x2E2F;

        case 0x30:
            return c == 0x3005 || isInRange(c, 0x3031, 0x3035)
                    || c == 0x303B || isInRange(c, 0x309D, 0x309E)
                    || isInRange(c, 0x30FC, 0x30FE);

        default:
            return false;
        }
    }

    /**
     * Checks if a given character c is within the range l .. h (inclusive).
     * @param c the character to check for
     * @param l the low value of the range
     * @param h the high value of the range
     * @return true if the character is i the range.
     */
    private static boolean isInRange(final char c, final int l, final int h) {
        return (c >= l && c <= h);
    }
}

Related Tutorials