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