1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.inputmethod.compat;
18 
19 import java.lang.reflect.Method;
20 
21 public final class CharacterCompat {
22     // Note that Character.isAlphabetic(int), has been introduced in API level 19
23     // (Build.VERSION_CODE.KITKAT).
24     private static final Method METHOD_isAlphabetic = CompatUtils.getMethod(
25             Character.class, "isAlphabetic", int.class);
26 
CharacterCompat()27     private CharacterCompat() {
28         // This utility class is not publicly instantiable.
29     }
30 
isAlphabetic(final int code)31     public static boolean isAlphabetic(final int code) {
32         if (METHOD_isAlphabetic != null) {
33             return (Boolean)CompatUtils.invoke(null, false, METHOD_isAlphabetic, code);
34         }
35         switch (Character.getType(code)) {
36         case Character.UPPERCASE_LETTER:
37         case Character.LOWERCASE_LETTER:
38         case Character.TITLECASE_LETTER:
39         case Character.MODIFIER_LETTER:
40         case Character.OTHER_LETTER:
41         case Character.LETTER_NUMBER:
42             return true;
43         default:
44             return false;
45         }
46     }
47 }
48