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.latin;
18 
19 import com.android.inputmethod.latin.common.Constants;
20 
21 import java.util.Locale;
22 
23 /**
24  * Utility methods related contacts dictionary.
25  */
26 public class ContactsDictionaryUtils {
27 
28     /**
29      * Returns the index of the last letter in the word, starting from position startIndex.
30      */
getWordEndPosition(final String string, final int len, final int startIndex)31     public static int getWordEndPosition(final String string, final int len,
32             final int startIndex) {
33         int end;
34         int cp = 0;
35         for (end = startIndex + 1; end < len; end += Character.charCount(cp)) {
36             cp = string.codePointAt(end);
37             if (cp != Constants.CODE_DASH && cp != Constants.CODE_SINGLE_QUOTE
38                    && !Character.isLetter(cp)) {
39                 break;
40             }
41         }
42         return end;
43     }
44 
45     /**
46      * Returns true if the locale supports using first name and last name as bigrams.
47      */
useFirstLastBigramsForLocale(final Locale locale)48     public static boolean useFirstLastBigramsForLocale(final Locale locale) {
49         // TODO: Add firstname/lastname bigram rules for other languages.
50         if (locale != null && locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
51             return true;
52         }
53         return false;
54     }
55 }
56