blob: e0ecc0e1da4fd3a69a03f3121a0cb66ad02794d9 [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
satok0cb20972012-03-13 22:07:56 +090023#include "defines.h"
24
satok552c3c22012-03-13 16:33:47 +090025namespace latinime {
26
27class AdditionalProximityChars {
28 private:
29 static const std::string LOCALE_EN_US;
30 static const int EN_US_ADDITIONAL_A_SIZE = 4;
satok0cb20972012-03-13 22:07:56 +090031 static const int32_t EN_US_ADDITIONAL_A[];
satok552c3c22012-03-13 16:33:47 +090032 static const int EN_US_ADDITIONAL_E_SIZE = 4;
satok0cb20972012-03-13 22:07:56 +090033 static const int32_t EN_US_ADDITIONAL_E[];
satok552c3c22012-03-13 16:33:47 +090034 static const int EN_US_ADDITIONAL_I_SIZE = 4;
satok0cb20972012-03-13 22:07:56 +090035 static const int32_t EN_US_ADDITIONAL_I[];
satok552c3c22012-03-13 16:33:47 +090036 static const int EN_US_ADDITIONAL_O_SIZE = 4;
satok0cb20972012-03-13 22:07:56 +090037 static const int32_t EN_US_ADDITIONAL_O[];
satok552c3c22012-03-13 16:33:47 +090038 static const int EN_US_ADDITIONAL_U_SIZE = 4;
satok0cb20972012-03-13 22:07:56 +090039 static const int32_t EN_US_ADDITIONAL_U[];
satok552c3c22012-03-13 16:33:47 +090040
satok0cb20972012-03-13 22:07:56 +090041 static bool isEnLocale(const std::string *locale_str) {
satok552c3c22012-03-13 16:33:47 +090042 return locale_str && locale_str->size() >= LOCALE_EN_US.size()
satok0cb20972012-03-13 22:07:56 +090043 && LOCALE_EN_US.compare(0, LOCALE_EN_US.size(), *locale_str);
satok552c3c22012-03-13 16:33:47 +090044 }
45
46 public:
satok0cb20972012-03-13 22:07:56 +090047 static int getAdditionalCharsSize(const std::string* locale_str, const int32_t c) {
satok552c3c22012-03-13 16:33:47 +090048 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
satok0cb20972012-03-13 22:07:56 +090067 static const int32_t* getAdditionalChars(const std::string *locale_str, const int32_t c) {
satok552c3c22012-03-13 16:33:47 +090068 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
satok0cb20972012-03-13 22:07:56 +090087 static bool hasAdditionalChars(const std::string *locale_str, const int32_t c) {
satok552c3c22012-03-13 16:33:47 +090088 return getAdditionalCharsSize(locale_str, c) > 0;
89 }
90};
91
92}
93
94#endif // LATINIME_ADDITIONAL_PROXIMITY_CHARS_H