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#include <vector> 22 23#include "defines.h" 24 25namespace latinime { 26 27class AdditionalProximityChars { 28 private: 29 DISALLOW_IMPLICIT_CONSTRUCTORS(AdditionalProximityChars); 30 static const int LOCALE_EN_US_SIZE = 2; 31 static const int LOCALE_EN_US[LOCALE_EN_US_SIZE]; 32 static const int EN_US_ADDITIONAL_A_SIZE = 4; 33 static const int EN_US_ADDITIONAL_A[]; 34 static const int EN_US_ADDITIONAL_E_SIZE = 4; 35 static const int EN_US_ADDITIONAL_E[]; 36 static const int EN_US_ADDITIONAL_I_SIZE = 4; 37 static const int EN_US_ADDITIONAL_I[]; 38 static const int EN_US_ADDITIONAL_O_SIZE = 4; 39 static const int EN_US_ADDITIONAL_O[]; 40 static const int EN_US_ADDITIONAL_U_SIZE = 4; 41 static const int EN_US_ADDITIONAL_U[]; 42 43 AK_FORCE_INLINE static bool isEnLocale(const std::vector<int> *locale) { 44 const int NCHARS = NELEMS(LOCALE_EN_US); 45 if (locale->size() < NCHARS) { 46 return false; 47 } 48 for (int i = 0; i < NCHARS; ++i) { 49 if ((*locale)[i] != LOCALE_EN_US[i]) { 50 return false; 51 } 52 } 53 return true; 54 } 55 56 public: 57 static int getAdditionalCharsSize(const std::vector<int> *locale, const int c) { 58 if (!isEnLocale(locale)) { 59 return 0; 60 } 61 switch (c) { 62 case 'a': 63 return EN_US_ADDITIONAL_A_SIZE; 64 case 'e': 65 return EN_US_ADDITIONAL_E_SIZE; 66 case 'i': 67 return EN_US_ADDITIONAL_I_SIZE; 68 case 'o': 69 return EN_US_ADDITIONAL_O_SIZE; 70 case 'u': 71 return EN_US_ADDITIONAL_U_SIZE; 72 default: 73 return 0; 74 } 75 } 76 77 static const int *getAdditionalChars(const std::vector<int> *locale, const int c) { 78 if (!isEnLocale(locale)) { 79 return 0; 80 } 81 switch (c) { 82 case 'a': 83 return EN_US_ADDITIONAL_A; 84 case 'e': 85 return EN_US_ADDITIONAL_E; 86 case 'i': 87 return EN_US_ADDITIONAL_I; 88 case 'o': 89 return EN_US_ADDITIONAL_O; 90 case 'u': 91 return EN_US_ADDITIONAL_U; 92 default: 93 return 0; 94 } 95 } 96}; 97} // namespace latinime 98#endif // LATINIME_ADDITIONAL_PROXIMITY_CHARS_H 99