Tell whether the given character is in the "low unicode" (two-byte) range. - Java java.lang

Java examples for java.lang:String Unicode

Description

Tell whether the given character is in the "low unicode" (two-byte) range.

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        int cNum = 42;
        System.out.println(isLowUnicode(cNum));
    }/*from   www  .j ava2  s.  co  m*/

    private static final int UC_LOW1 = 0x0;
    private static final int UC_HIGH1 = 0x8;
    private static final int UC_LOW2 = 0xB;
    private static final int UC_HIGH2 = 0xC;
    private static final int UC_LOW3 = 0xE;
    private static final int UC_HIGH3 = 0x1F;
    private static final int UC_LOW4 = 0x7F;
    private static final int UC_HIGH4 = 0xFFFF;

    /**
     * Tell whether the given character is in the "low unicode" (two-byte) range.
     *
     * @param cNum the character.
     * @return true if it's a low unicode character.
     */
    private static boolean isLowUnicode(final int cNum) {
        return cNum >= UC_LOW1 && cNum <= UC_HIGH1 || cNum == UC_LOW2
                || cNum == UC_HIGH2 || cNum >= UC_LOW3 && cNum <= UC_HIGH3
                || cNum >= UC_LOW4 && cNum <= UC_HIGH4;
    }
}

Related Tutorials