OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/ime/extension_ime_util.h" | 5 #include "chromeos/ime/extension_ime_util.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 | 8 |
9 namespace chromeos { | 9 namespace chromeos { |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 std::string GetComponentInputMethodID(const std::string& extension_id, | 33 std::string GetComponentInputMethodID(const std::string& extension_id, |
34 const std::string& engine_id) { | 34 const std::string& engine_id) { |
35 DCHECK(!extension_id.empty()); | 35 DCHECK(!extension_id.empty()); |
36 DCHECK(!engine_id.empty()); | 36 DCHECK(!engine_id.empty()); |
37 return kComponentExtensionIMEPrefix + extension_id + engine_id; | 37 return kComponentExtensionIMEPrefix + extension_id + engine_id; |
38 } | 38 } |
39 | 39 |
40 std::string GetExtensionIDFromInputMethodID( | 40 std::string GetExtensionIDFromInputMethodID( |
41 const std::string& input_method_id) { | 41 const std::string& input_method_id) { |
42 if (IsExtensionIME(input_method_id) && | 42 if (IsExtensionIME(input_method_id)) { |
43 input_method_id.size() >= kExtensionIMEPrefixLength + | |
44 kExtensionIdLength) { | |
45 return input_method_id.substr(kExtensionIMEPrefixLength, | 43 return input_method_id.substr(kExtensionIMEPrefixLength, |
46 kExtensionIdLength); | 44 kExtensionIdLength); |
47 } | 45 } |
48 if (IsComponentExtensionIME(input_method_id) && | 46 if (IsComponentExtensionIME(input_method_id)) { |
49 input_method_id.size() >= kComponentExtensionIMEPrefixLength + | |
50 kExtensionIdLength) { | |
51 return input_method_id.substr(kComponentExtensionIMEPrefixLength, | 47 return input_method_id.substr(kComponentExtensionIMEPrefixLength, |
52 kExtensionIdLength); | 48 kExtensionIdLength); |
53 } | 49 } |
54 return ""; | 50 return ""; |
55 } | 51 } |
56 | 52 |
57 std::string GetComponentIDByInputMethodID(const std::string& input_method_id) { | 53 std::string GetComponentIDByInputMethodID(const std::string& input_method_id) { |
58 if (IsComponentExtensionIME(input_method_id)) | 54 if (IsComponentExtensionIME(input_method_id)) |
59 return input_method_id.substr(kComponentExtensionIMEPrefixLength + | 55 return input_method_id.substr(kComponentExtensionIMEPrefixLength + |
60 kExtensionIdLength); | 56 kExtensionIdLength); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 88 } |
93 if (engine_id.find("-t-i0-") != std::string::npos) | 89 if (engine_id.find("-t-i0-") != std::string::npos) |
94 return GetComponentInputMethodID(kT13nExtensionId, engine_id); | 90 return GetComponentInputMethodID(kT13nExtensionId, engine_id); |
95 | 91 |
96 return engine_id; | 92 return engine_id; |
97 } | 93 } |
98 | 94 |
99 bool IsExtensionIME(const std::string& input_method_id) { | 95 bool IsExtensionIME(const std::string& input_method_id) { |
100 return StartsWithASCII(input_method_id, | 96 return StartsWithASCII(input_method_id, |
101 kExtensionIMEPrefix, | 97 kExtensionIMEPrefix, |
102 true); // Case sensitive. | 98 true /* Case sensitive */) && |
| 99 input_method_id.size() > kExtensionIMEPrefixLength + |
| 100 kExtensionIdLength; |
103 } | 101 } |
104 | 102 |
105 bool IsComponentExtensionIME(const std::string& input_method_id) { | 103 bool IsComponentExtensionIME(const std::string& input_method_id) { |
106 return StartsWithASCII(input_method_id, | 104 return StartsWithASCII(input_method_id, |
107 kComponentExtensionIMEPrefix, | 105 kComponentExtensionIMEPrefix, |
108 true); // Case sensitive. | 106 true /* Case sensitive */) && |
| 107 input_method_id.size() > kComponentExtensionIMEPrefixLength + |
| 108 kExtensionIdLength; |
109 } | 109 } |
110 | 110 |
111 bool IsMemberOfExtension(const std::string& input_method_id, | 111 bool IsMemberOfExtension(const std::string& input_method_id, |
112 const std::string& extension_id) { | 112 const std::string& extension_id) { |
113 return StartsWithASCII(input_method_id, | 113 return StartsWithASCII(input_method_id, |
114 kExtensionIMEPrefix + extension_id, | 114 kExtensionIMEPrefix + extension_id, |
115 true); // Case sensitive. | 115 true /* Case sensitive */); |
116 } | 116 } |
117 | 117 |
118 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { | 118 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { |
119 std::string prefix = kComponentExtensionIMEPrefix; | 119 std::string prefix = kComponentExtensionIMEPrefix; |
120 return StartsWithASCII(input_method_id, prefix + kXkbExtensionId, true); | 120 return StartsWithASCII(input_method_id, prefix + kXkbExtensionId, true); |
121 } | 121 } |
122 | 122 |
123 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { | 123 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { |
124 if (IsKeyboardLayoutExtension(input_method_id)) | 124 if (IsKeyboardLayoutExtension(input_method_id)) |
125 return GetComponentIDByInputMethodID(input_method_id); | 125 return GetComponentIDByInputMethodID(input_method_id); |
126 return input_method_id; | 126 return input_method_id; |
127 } | 127 } |
128 | 128 |
129 } // namespace extension_ime_util | 129 } // namespace extension_ime_util |
130 } // namespace chromeos | 130 } // namespace chromeos |
OLD | NEW |