90 | 90 |
}
|
91 | 91 |
}
|
92 | 92 |
|
|
93 |
// Function object to check if c >= 0 && c < upper_bound, where T is
|
|
94 |
// std::true_type when char is unsigned; otherwise T is std::false_type. By
|
|
95 |
// using template class instead of a function, we can avoid the compiler warning
|
|
96 |
// about unused function.
|
|
97 |
template <typename T>
|
|
98 |
struct IsNonnegativeAndLessThan {
|
|
99 |
bool operator()(char c, size_t upper_bound) const;
|
|
100 |
};
|
|
101 |
|
|
102 |
template <>
|
|
103 |
struct IsNonnegativeAndLessThan<std::true_type> {
|
|
104 |
bool operator()(char c, size_t upper_bound) const {
|
|
105 |
// No check for "0 <= *c" for unsigned case.
|
|
106 |
return c < upper_bound;
|
|
107 |
}
|
|
108 |
};
|
|
109 |
|
|
110 |
template <>
|
|
111 |
struct IsNonnegativeAndLessThan<std::false_type> {
|
|
112 |
bool operator()(char c, size_t upper_bound) const {
|
|
113 |
return c >= 0 && static_cast<size_t>(c) < upper_bound;
|
|
114 |
}
|
|
115 |
};
|
|
116 |
|
93 | 117 |
void ModifyT13nsForGodan(const string &key, vector<string> *t13ns) {
|
94 | 118 |
static const char * const kKeycodeToT13nMap[] = {
|
95 | 119 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
105 | 129 |
const string &src = (*t13ns)[transliteration::HALF_ASCII];
|
106 | 130 |
string dst;
|
107 | 131 |
for (string::const_iterator c = src.begin(); c != src.end(); ++c) {
|
108 | |
// Won't check "0 <= *c" here as string::value_type must be configured
|
109 | |
// to be unsigned in Mozc.
|
110 | |
static_assert(std::is_unsigned<string::value_type>::value,
|
111 | |
"string::value must be unsigned.");
|
112 | |
if (*c < arraysize(kKeycodeToT13nMap) && kKeycodeToT13nMap[*c] != NULL) {
|
|
132 |
using IsNonnegativeAndLessThanType =
|
|
133 |
IsNonnegativeAndLessThan<std::is_unsigned<string::value_type>::type>;
|
|
134 |
if (IsNonnegativeAndLessThanType()(*c, arraysize(kKeycodeToT13nMap)) &&
|
|
135 |
kKeycodeToT13nMap[*c] != NULL) {
|
113 | 136 |
dst.append(kKeycodeToT13nMap[*c]);
|
114 | 137 |
} else {
|
115 | 138 |
dst.append(1, *c);
|