1 /* 2 * Copyright (C) 2012 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 #ifndef LATINIME_ADDITIONAL_PROXIMITY_CHARS_H 18 #define LATINIME_ADDITIONAL_PROXIMITY_CHARS_H 19 20 #include <cstring> 21 22 #include "defines.h" 23 24 namespace latinime { 25 26 class AdditionalProximityChars { 27 private: 28 DISALLOW_IMPLICIT_CONSTRUCTORS(AdditionalProximityChars); 29 static const char *LOCALE_EN_US; 30 static const int EN_US_ADDITIONAL_A_SIZE = 4; 31 static const int EN_US_ADDITIONAL_A[]; 32 static const int EN_US_ADDITIONAL_E_SIZE = 4; 33 static const int EN_US_ADDITIONAL_E[]; 34 static const int EN_US_ADDITIONAL_I_SIZE = 4; 35 static const int EN_US_ADDITIONAL_I[]; 36 static const int EN_US_ADDITIONAL_O_SIZE = 4; 37 static const int EN_US_ADDITIONAL_O[]; 38 static const int EN_US_ADDITIONAL_U_SIZE = 4; 39 static const int EN_US_ADDITIONAL_U[]; 40 41 AK_FORCE_INLINE static bool isEnLocale(const char *localeStr) { 42 const size_t LOCALE_EN_US_SIZE = strlen(LOCALE_EN_US); 43 return localeStr && strlen(localeStr) >= LOCALE_EN_US_SIZE 44 && strncmp(localeStr, LOCALE_EN_US, LOCALE_EN_US_SIZE) == 0; 45 } 46 47 public: 48 static int getAdditionalCharsSize(const char *const localeStr, const int c) { 49 if (!isEnLocale(localeStr)) { 50 return 0; 51 } 52 switch (c) { 53 case 'a': 54 return EN_US_ADDITIONAL_A_SIZE; 55 case 'e': 56 return EN_US_ADDITIONAL_E_SIZE; 57 case 'i': 58 return EN_US_ADDITIONAL_I_SIZE; 59 case 'o': 60 return EN_US_ADDITIONAL_O_SIZE; 61 case 'u': 62 return EN_US_ADDITIONAL_U_SIZE; 63 default: 64 return 0; 65 } 66 } 67 68 static const int *getAdditionalChars(const char *const localeStr, const int c) { 69 if (!isEnLocale(localeStr)) { 70 return 0; 71 } 72 switch (c) { 73 case 'a': 74 return EN_US_ADDITIONAL_A; 75 case 'e': 76 return EN_US_ADDITIONAL_E; 77 case 'i': 78 return EN_US_ADDITIONAL_I; 79 case 'o': 80 return EN_US_ADDITIONAL_O; 81 case 'u': 82 return EN_US_ADDITIONAL_U; 83 default: 84 return 0; 85 } 86 } 87 }; 88 } // namespace latinime 89 #endif // LATINIME_ADDITIONAL_PROXIMITY_CHARS_H 90