Add std:: prefix for base/, renderer/, and unix/
BUG=#392
TEST=unittest
REF_BUG=
REF_CL=181915556
REF_TIME=2018-01-15T10:19:45+09:00
REF_TIME_RAW=1515979185 +0900
Hiroyuki Komatsu
6 years ago
204 | 204 | void Reset(); |
205 | 205 | |
206 | 206 | int verbose_level() const { |
207 | return max(FLAGS_v, config_verbose_level_); | |
207 | return std::max(FLAGS_v, config_verbose_level_); | |
208 | 208 | } |
209 | 209 | |
210 | 210 | void set_verbose_level(int level) { |
283 | 283 | DCHECK_NE(log_file_path.size(), 0); |
284 | 284 | std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf8_to_wide; |
285 | 285 | real_log_stream_ = new std::ofstream( |
286 | utf8_to_wide.from_bytes(log_file_path).c_str(), ios::app); | |
286 | utf8_to_wide.from_bytes(log_file_path).c_str(), std::ios::app); | |
287 | 287 | #elif !defined(OS_ANDROID) |
288 | 288 | // On non-Android platform, change file mode in addition. |
289 | 289 | // Android uses logcat instead of log file. |
290 | 290 | DCHECK_NE(log_file_path.size(), 0); |
291 | real_log_stream_ = new std::ofstream(log_file_path.c_str(), ios::app); | |
291 | real_log_stream_ = new std::ofstream(log_file_path.c_str(), std::ios::app); | |
292 | 292 | ::chmod(log_file_path.c_str(), 0600); |
293 | 293 | #endif // OS_ANDROID |
294 | 294 | DCHECK(!use_cerr_ || !real_log_stream_); |
38 | 38 | |
39 | 39 | using size_type = StringPiece::size_type; |
40 | 40 | |
41 | ostream &operator<<(ostream &o, const StringPiece &piece) { | |
41 | std::ostream &operator<<(std::ostream &o, const StringPiece &piece) { | |
42 | 42 | o.write(piece.data(), static_cast<std::streamsize>(piece.size())); |
43 | 43 | return o; |
44 | 44 | } |
54 | 54 | } |
55 | 55 | |
56 | 56 | size_type StringPiece::copy(char *buf, size_type n, size_type pos) const { |
57 | const size_type ret = min(length_ - pos, n); | |
57 | const size_type ret = std::min(length_ - pos, n); | |
58 | 58 | memcpy(buf, ptr_ + pos, ret); |
59 | 59 | return ret; |
60 | 60 | } |
87 | 87 | } |
88 | 88 | |
89 | 89 | if (s.empty()) { |
90 | return min(length_, pos); | |
91 | } | |
92 | ||
93 | const char *last = ptr_ + min(length_ - s.length_, pos) + s.length_; | |
90 | return std::min(length_, pos); | |
91 | } | |
92 | ||
93 | const char *last = ptr_ + std::min(length_ - s.length_, pos) + s.length_; | |
94 | 94 | const char *result = std::find_end(ptr_, last, s.ptr_, s.ptr_ + s.length_); |
95 | 95 | return result != last ? result - ptr_ : npos; |
96 | 96 | } |
100 | 100 | return npos; |
101 | 101 | } |
102 | 102 | |
103 | for (size_type i = min(pos, length_ - 1); ; --i) { | |
103 | for (size_type i = std::min(pos, length_ - 1); ; --i) { | |
104 | 104 | if (ptr_[i] == c) { |
105 | 105 | return i; |
106 | 106 | } |
196 | 196 | |
197 | 197 | bool lookup[UCHAR_MAX + 1] = { false }; |
198 | 198 | BuildLookupTable(s, lookup); |
199 | for (size_type i = min(pos, length_ - 1); ; --i) { | |
199 | for (size_type i = std::min(pos, length_ - 1); ; --i) { | |
200 | 200 | if (lookup[static_cast<unsigned char>(ptr_[i])]) { |
201 | 201 | return i; |
202 | 202 | } |
213 | 213 | return npos; |
214 | 214 | } |
215 | 215 | |
216 | size_type i = min(pos, length_ - 1); | |
216 | size_type i = std::min(pos, length_ - 1); | |
217 | 217 | if (s.length_ == 0) { |
218 | 218 | return i; |
219 | 219 | } |
239 | 239 | return npos; |
240 | 240 | } |
241 | 241 | |
242 | for (size_type i = min(pos, length_ - 1); ; --i) { | |
242 | for (size_type i = std::min(pos, length_ - 1); ; --i) { | |
243 | 243 | if (ptr_[i] != c) |
244 | 244 | return i; |
245 | 245 | if (i == 0) |
209 | 209 | }; |
210 | 210 | |
211 | 211 | // allow StringPiece to be logged (needed for unit testing). |
212 | extern ostream &operator<<(ostream &o, const StringPiece &piece); | |
212 | extern std::ostream &operator<<(std::ostream &o, const StringPiece &piece); | |
213 | 213 | |
214 | 214 | inline StringPiece ClippedSubstr(StringPiece sp, size_t pos, |
215 | 215 | size_t n = StringPiece::npos) { |
29 | 29 | |
30 | 30 | MAJOR=2 |
31 | 31 | MINOR=23 |
32 | BUILD=2788 | |
32 | BUILD=2789 | |
33 | 33 | REVISION=102 |
34 | 34 | # This version represents the version of Mozc IME engine (converter, predictor, |
35 | 35 | # etc.). This version info is included both in the Mozc server and in the Mozc |
54 | 54 | const int focused_index = candidates.focused_index(); |
55 | 55 | const int total_items = candidates.size(); |
56 | 56 | |
57 | stringstream footer_string; | |
57 | std::stringstream footer_string; | |
58 | 58 | return Util::StringPrintf("%d/%d ", focused_index + 1, total_items); |
59 | 59 | } |
60 | 60 | |
292 | 292 | FontSpec::FONTSET_FOOTER_LABEL, |
293 | 293 | candidates_.footer().label()); |
294 | 294 | footer_size.width += label_string_size.width; |
295 | footer_size.height = max(footer_size.height, label_string_size.height); | |
295 | footer_size.height = std::max(footer_size.height, label_string_size.height); | |
296 | 296 | } else if (candidates_.footer().has_sub_label()) { |
297 | 297 | const Size label_string_size = text_renderer_->GetPixelSize( |
298 | 298 | FontSpec::FONTSET_FOOTER_LABEL, |
299 | 299 | candidates_.footer().sub_label()); |
300 | 300 | footer_size.width += label_string_size.width; |
301 | footer_size.height = max(footer_size.height, label_string_size.height); | |
301 | footer_size.height = std::max(footer_size.height, label_string_size.height); | |
302 | 302 | } |
303 | 303 | |
304 | 304 | if (candidates_.footer().index_visible()) { |
306 | 306 | FontSpec::FONTSET_FOOTER_INDEX, |
307 | 307 | GetIndexGuideString(candidates_)); |
308 | 308 | footer_size.width += index_guide_size.width; |
309 | footer_size.height = max(footer_size.height, index_guide_size.height); | |
309 | footer_size.height = std::max(footer_size.height, index_guide_size.height); | |
310 | 310 | } |
311 | 311 | |
312 | 312 | if (candidates_.candidate_size() < candidates_.size()) { |
56 | 56 | protected: |
57 | 57 | void LoadFontSpec(const string &font_description); |
58 | 58 | void ReleaseFontSpec(); |
59 | vector<FontInfo> fonts_; | |
59 | std::vector<FontInfo> fonts_; | |
60 | 60 | bool is_initialized_; |
61 | 61 | std::unique_ptr<GtkWrapperInterface> gtk_; |
62 | 62 |
28 | 28 | |
29 | 29 | #include "unix/ibus/key_event_handler.h" |
30 | 30 | |
31 | #include <map> | |
32 | ||
33 | 31 | #include "base/logging.h" |
34 | 32 | #include "base/port.h" |
35 | 33 | #include "base/singleton.h" |
166 | 164 | |
167 | 165 | // Modifier key event fires |
168 | 166 | key_event->mutable_modifier_keys()->Clear(); |
169 | for (set<commands::KeyEvent::ModifierKey>::const_iterator it = | |
167 | for (std::set<commands::KeyEvent::ModifierKey>::const_iterator it = | |
170 | 168 | modifiers_to_be_sent_.begin(); |
171 | 169 | it != modifiers_to_be_sent_.end(); |
172 | 170 | ++it) { |
65 | 65 | // Non modifier key is pressed or not after all keys are released. |
66 | 66 | bool is_non_modifier_key_pressed_; |
67 | 67 | // Currently pressed modifier keys. It is set of keyval. |
68 | set<guint> currently_pressed_modifiers_; | |
68 | std::set<guint> currently_pressed_modifiers_; | |
69 | 69 | // Pending modifier keys. |
70 | set<commands::KeyEvent::ModifierKey> modifiers_to_be_sent_; | |
70 | std::set<commands::KeyEvent::ModifierKey> modifiers_to_be_sent_; | |
71 | 71 | |
72 | 72 | DISALLOW_COPY_AND_ASSIGN(KeyEventHandler); |
73 | 73 | }; |
436 | 436 | |
437 | 437 | void KeyTranslator::Init() { |
438 | 438 | for (int i = 0; i < arraysize(special_key_map); ++i) { |
439 | CHECK(special_key_map_.insert(make_pair(special_key_map[i].from, | |
440 | special_key_map[i].to)).second); | |
439 | CHECK(special_key_map_.insert( | |
440 | std::make_pair(special_key_map[i].from, | |
441 | special_key_map[i].to)).second); | |
441 | 442 | } |
442 | 443 | for (int i = 0; i < arraysize(modifier_key_map_data); ++i) { |
443 | 444 | CHECK(modifier_key_map_.insert( |
444 | make_pair(modifier_key_map_data[i].from, | |
445 | modifier_key_map_data[i].to)).second); | |
445 | std::make_pair(modifier_key_map_data[i].from, | |
446 | modifier_key_map_data[i].to)).second); | |
446 | 447 | } |
447 | 448 | for (int i = 0; i < arraysize(modifier_mask_map_data); ++i) { |
448 | 449 | CHECK(modifier_mask_map_.insert( |
449 | make_pair(modifier_mask_map_data[i].from, | |
450 | modifier_mask_map_data[i].to)).second); | |
450 | std::make_pair(modifier_mask_map_data[i].from, | |
451 | modifier_mask_map_data[i].to)).second); | |
451 | 452 | } |
452 | 453 | for (int i = 0; i < arraysize(kana_map_jp); ++i) { |
453 | 454 | CHECK(kana_map_jp_.insert( |
454 | make_pair(kana_map_jp[i].code, make_pair( | |
455 | kana_map_jp[i].no_shift, kana_map_jp[i].shift))).second); | |
455 | std::make_pair(kana_map_jp[i].code, | |
456 | std::make_pair(kana_map_jp[i].no_shift, | |
457 | kana_map_jp[i].shift))).second); | |
456 | 458 | } |
457 | 459 | for (int i = 0; i < arraysize(kana_map_us); ++i) { |
458 | 460 | CHECK(kana_map_us_.insert( |
459 | make_pair(kana_map_us[i].code, make_pair( | |
460 | kana_map_us[i].no_shift, kana_map_us[i].shift))).second); | |
461 | std::make_pair(kana_map_us[i].code, | |
462 | std::make_pair(kana_map_us[i].no_shift, | |
463 | kana_map_us[i].shift))).second); | |
461 | 464 | } |
462 | 465 | } |
463 | 466 |
56 | 56 | commands::KeyEvent *out_event) const; |
57 | 57 | |
58 | 58 | private: |
59 | typedef map<guint, commands::KeyEvent::SpecialKey> SpecialKeyMap; | |
60 | typedef map<guint, commands::KeyEvent::ModifierKey> ModifierKeyMap; | |
61 | typedef map<guint, pair<string, string> > KanaMap; | |
59 | typedef std::map<guint, commands::KeyEvent::SpecialKey> SpecialKeyMap; | |
60 | typedef std::map<guint, commands::KeyEvent::ModifierKey> ModifierKeyMap; | |
61 | typedef std::map<guint, std::pair<string, string> > KanaMap; | |
62 | 62 | |
63 | 63 | // Returns true iff key is modifier key such as SHIFT, ALT, or CAPSLOCK. |
64 | 64 | bool IsModifierKey(guint keyval, |
80 | 80 | LocaleBasedMessageTranslator::LocaleBasedMessageTranslator( |
81 | 81 | const string &locale_name) { |
82 | 82 | // Currently we support ja_JP.UTF-8 and ja_JP.utf8 only. |
83 | vector<string> tokens; | |
83 | std::vector<string> tokens; | |
84 | 84 | Util::SplitStringUsing(locale_name, ".", &tokens); |
85 | 85 | if (tokens.size() != 2) { |
86 | 86 | return; |
107 | 107 | |
108 | 108 | string LocaleBasedMessageTranslator::MaybeTranslate( |
109 | 109 | const string &message) const { |
110 | map<string, string>::const_iterator itr = | |
110 | std::map<string, string>::const_iterator itr = | |
111 | 111 | utf8_japanese_map_.find(message); |
112 | 112 | if (itr == utf8_japanese_map_.end()) { |
113 | 113 | return message; |
69 | 69 | virtual string MaybeTranslate(const string &message) const; |
70 | 70 | |
71 | 71 | private: |
72 | map<string, string> utf8_japanese_map_; | |
72 | std::map<string, string> utf8_japanese_map_; | |
73 | 73 | DISALLOW_COPY_AND_ASSIGN(LocaleBasedMessageTranslator); |
74 | 74 | }; |
75 | 75 |
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | |
206 | const size_t selection_start = min(cursor_pos, anchor_pos); | |
206 | const size_t selection_start = std::min(cursor_pos, anchor_pos); | |
207 | 207 | const size_t selection_length = abs(info->relative_selected_length); |
208 | 208 | Util::SubStringPiece(surrounding_text, 0, selection_start) |
209 | 209 | .CopyToString(&info->preceding_text); |
160 | 160 | config::Config::PreeditMethod preedit_method_; |
161 | 161 | |
162 | 162 | // Unique IDs of candidates that are currently shown. |
163 | vector<int32> unique_candidate_ids_; | |
163 | std::vector<int32> unique_candidate_ids_; | |
164 | 164 | |
165 | 165 | friend class LaunchToolTest; |
166 | 166 | FRIEND_TEST(LaunchToolTest, LaunchToolTest); |
47 | 47 | static_assert(sizeof(int64) == sizeof(llabs(0)), |
48 | 48 | "|llabs(0)| must returns a 64-bit integer."); |
49 | 49 | const int64 kInt32AbsMax = |
50 | llabs(static_cast<int64>(numeric_limits<int32>::max())); | |
50 | llabs(static_cast<int64>(std::numeric_limits<int32>::max())); | |
51 | 51 | const int64 kInt32AbsMin = |
52 | llabs(static_cast<int64>(numeric_limits<int32>::min())); | |
52 | llabs(static_cast<int64>(std::numeric_limits<int32>::min())); | |
53 | 53 | const int64 kInt32SafeAbsMax = |
54 | min(kInt32AbsMax, kInt32AbsMin); | |
54 | std::min(kInt32AbsMax, kInt32AbsMin); | |
55 | 55 | |
56 | 56 | const int64 diff = static_cast<int64>(from) - static_cast<int64>(to); |
57 | 57 | if (llabs(diff) > kInt32SafeAbsMax) { |