Codebase list mozc / 38fb0e2
Support signed char in transliteration_rewriter.cc BUG= TEST= REF_BUG=31945229 REF_CL=135888401 REF_TIME=2016-10-12T16:20:40+09:00 REF_TIME_RAW=1476256840 +0900 Noriyuki Takahashi 7 years ago
2 changed file(s) with 29 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
2929
3030 MAJOR=2
3131 MINOR=19
32 BUILD=2633
32 BUILD=2634
3333 REVISION=102
3434 # This version represents the version of Mozc IME engine (converter, predictor,
3535 # etc.). This version info is included both in the Mozc server and in the Mozc
9090 }
9191 }
9292
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
93117 void ModifyT13nsForGodan(const string &key, vector<string> *t13ns) {
94118 static const char * const kKeycodeToT13nMap[] = {
95119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105129 const string &src = (*t13ns)[transliteration::HALF_ASCII];
106130 string dst;
107131 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) {
113136 dst.append(kKeycodeToT13nMap[*c]);
114137 } else {
115138 dst.append(1, *c);