Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2016 Jared Rummler <jared.rummler@gmail.com>
 *
 * Licensed 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.
 *
 */

public class Main {
    /**
     * Indicates whether a character is classified as "Alphabetic" by the Unicode standard.
     *
     * @param c
     *     the character
     * @return true if the character is "Alphabetic"
     */
    public static boolean isAlphabetic(int c) {
        //http://www.unicode.org/Public/UNIDATA/UCD.html#Alphabetic
        //Generated from: Other_Alphabetic + Lu + Ll + Lt + Lm + Lo + Nl
        int generalCategory = Character.getType((char) c);
        switch (generalCategory) {
        case Character.UPPERCASE_LETTER: //Lu
        case Character.LOWERCASE_LETTER: //Ll
        case Character.TITLECASE_LETTER: //Lt
        case Character.MODIFIER_LETTER: //Lm
        case Character.OTHER_LETTER: //Lo
        case Character.LETTER_NUMBER: //Nl
            return true;
        default:
            //TODO if (ch in Other_Alphabetic) return true; (Probably need ICU4J for that)
            //Other_Alphabetic contains mostly more exotic characters
            return false;
        }
    }
}