blob: e0049d949fb553d554dc759bd657842922fcb41c [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;
satok5eec5742012-03-13 18:26:23 +090029 static const uint32_t EN_US_ADDITIONAL_A[];
satok552c3c22012-03-13 16:33:47 +090030 static const int EN_US_ADDITIONAL_E_SIZE = 4;
satok5eec5742012-03-13 18:26:23 +090031 static const uint32_t EN_US_ADDITIONAL_E[];
satok552c3c22012-03-13 16:33:47 +090032 static const int EN_US_ADDITIONAL_I_SIZE = 4;
satok5eec5742012-03-13 18:26:23 +090033 static const uint32_t EN_US_ADDITIONAL_I[];
satok552c3c22012-03-13 16:33:47 +090034 static const int EN_US_ADDITIONAL_O_SIZE = 4;
satok5eec5742012-03-13 18:26:23 +090035 static const uint32_t EN_US_ADDITIONAL_O[];
satok552c3c22012-03-13 16:33:47 +090036 static const int EN_US_ADDITIONAL_U_SIZE = 4;
satok5eec5742012-03-13 18:26:23 +090037 static const uint32_t EN_US_ADDITIONAL_U[];
satok552c3c22012-03-13 16:33:47 +090038
satok5eec5742012-03-13 18:26:23 +090039 static bool isEnLocale(const std::string* locale_str) {
satok552c3c22012-03-13 16:33:47 +090040 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:
satok5eec5742012-03-13 18:26:23 +090045 static int getAdditionalCharsSize(const std::string* locale_str, const uint16_t c) {
satok552c3c22012-03-13 16:33:47 +090046 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
satok5eec5742012-03-13 18:26:23 +090065 static const uint32_t* getAdditionalChars(const std::string* locale_str, const uint32_t c) {
satok552c3c22012-03-13 16:33:47 +090066 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
satok5eec5742012-03-13 18:26:23 +090085 static bool hasAdditionalChars(const std::string* locale_str, const uint32_t c) {
satok552c3c22012-03-13 16:33:47 +090086 return getAdditionalCharsSize(locale_str, c) > 0;
87 }
88};
89
90}
91
92#endif // LATINIME_ADDITIONAL_PROXIMITY_CHARS_H