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