| 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 "ui/base/ime/chromeos/extension_ime_util.h" | 5 #include "ui/base/ime/chromeos/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 if (IsComponentExtensionIME(input_method_id)) | 54 if (IsComponentExtensionIME(input_method_id)) |
| 55 return input_method_id.substr(kComponentExtensionIMEPrefixLength + | 55 return input_method_id.substr(kComponentExtensionIMEPrefixLength + |
| 56 kExtensionIdLength); | 56 kExtensionIdLength); |
| 57 if (IsExtensionIME(input_method_id)) | 57 if (IsExtensionIME(input_method_id)) |
| 58 return input_method_id.substr(kExtensionIMEPrefixLength + | 58 return input_method_id.substr(kExtensionIMEPrefixLength + |
| 59 kExtensionIdLength); | 59 kExtensionIdLength); |
| 60 return input_method_id; | 60 return input_method_id; |
| 61 } | 61 } |
| 62 | 62 |
| 63 std::string GetInputMethodIDByEngineID(const std::string& engine_id) { | 63 std::string GetInputMethodIDByEngineID(const std::string& engine_id) { |
| 64 if (base::StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) || | 64 if (base::StartsWith(engine_id, kComponentExtensionIMEPrefix, |
| 65 base::StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) { | 65 base::CompareCase::SENSITIVE) || |
| 66 base::StartsWith(engine_id, kExtensionIMEPrefix, |
| 67 base::CompareCase::SENSITIVE)) { |
| 66 return engine_id; | 68 return engine_id; |
| 67 } | 69 } |
| 68 if (base::StartsWithASCII(engine_id, "xkb:", true)) | 70 if (base::StartsWith(engine_id, "xkb:", base::CompareCase::SENSITIVE)) |
| 69 return GetComponentInputMethodID(kXkbExtensionId, engine_id); | 71 return GetComponentInputMethodID(kXkbExtensionId, engine_id); |
| 70 if (base::StartsWithASCII(engine_id, "vkd_", true)) | 72 if (base::StartsWith(engine_id, "vkd_", base::CompareCase::SENSITIVE)) |
| 71 return GetComponentInputMethodID(kM17nExtensionId, engine_id); | 73 return GetComponentInputMethodID(kM17nExtensionId, engine_id); |
| 72 if (base::StartsWithASCII(engine_id, "nacl_mozc_", true)) | 74 if (base::StartsWith(engine_id, "nacl_mozc_", base::CompareCase::SENSITIVE)) |
| 73 return GetComponentInputMethodID(kMozcExtensionId, engine_id); | 75 return GetComponentInputMethodID(kMozcExtensionId, engine_id); |
| 74 if (base::StartsWithASCII(engine_id, "hangul_", true)) | 76 if (base::StartsWith(engine_id, "hangul_", |
| 77 base::CompareCase::SENSITIVE)) |
| 75 return GetComponentInputMethodID(kHangulExtensionId, engine_id); | 78 return GetComponentInputMethodID(kHangulExtensionId, engine_id); |
| 76 | 79 |
| 77 if (base::StartsWithASCII(engine_id, "zh-", true) && | 80 if (base::StartsWith(engine_id, "zh-", base::CompareCase::SENSITIVE) && |
| 78 engine_id.find("pinyin") != std::string::npos) { | 81 engine_id.find("pinyin") != std::string::npos) { |
| 79 return GetComponentInputMethodID(kChinesePinyinExtensionId, engine_id); | 82 return GetComponentInputMethodID(kChinesePinyinExtensionId, engine_id); |
| 80 } | 83 } |
| 81 if (base::StartsWithASCII(engine_id, "zh-", true) && | 84 if (base::StartsWith(engine_id, "zh-", base::CompareCase::SENSITIVE) && |
| 82 engine_id.find("zhuyin") != std::string::npos) { | 85 engine_id.find("zhuyin") != std::string::npos) { |
| 83 return GetComponentInputMethodID(kChineseZhuyinExtensionId, engine_id); | 86 return GetComponentInputMethodID(kChineseZhuyinExtensionId, engine_id); |
| 84 } | 87 } |
| 85 if (base::StartsWithASCII(engine_id, "zh-", true) && | 88 if (base::StartsWith(engine_id, "zh-", base::CompareCase::SENSITIVE) && |
| 86 engine_id.find("cangjie") != std::string::npos) { | 89 engine_id.find("cangjie") != std::string::npos) { |
| 87 return GetComponentInputMethodID(kChineseCangjieExtensionId, engine_id); | 90 return GetComponentInputMethodID(kChineseCangjieExtensionId, engine_id); |
| 88 } | 91 } |
| 89 if (engine_id.find("-t-i0-") != std::string::npos) | 92 if (engine_id.find("-t-i0-") != std::string::npos) |
| 90 return GetComponentInputMethodID(kT13nExtensionId, engine_id); | 93 return GetComponentInputMethodID(kT13nExtensionId, engine_id); |
| 91 | 94 |
| 92 return engine_id; | 95 return engine_id; |
| 93 } | 96 } |
| 94 | 97 |
| 95 bool IsExtensionIME(const std::string& input_method_id) { | 98 bool IsExtensionIME(const std::string& input_method_id) { |
| 96 return base::StartsWithASCII(input_method_id, kExtensionIMEPrefix, | 99 return base::StartsWith(input_method_id, kExtensionIMEPrefix, |
| 97 true /* Case sensitive */) && | 100 base::CompareCase::SENSITIVE) && |
| 98 input_method_id.size() > | 101 input_method_id.size() > |
| 99 kExtensionIMEPrefixLength + kExtensionIdLength; | 102 kExtensionIMEPrefixLength + kExtensionIdLength; |
| 100 } | 103 } |
| 101 | 104 |
| 102 bool IsComponentExtensionIME(const std::string& input_method_id) { | 105 bool IsComponentExtensionIME(const std::string& input_method_id) { |
| 103 return base::StartsWithASCII(input_method_id, kComponentExtensionIMEPrefix, | 106 return base::StartsWith(input_method_id, kComponentExtensionIMEPrefix, |
| 104 true /* Case sensitive */) && | 107 base::CompareCase::SENSITIVE) && |
| 105 input_method_id.size() > | 108 input_method_id.size() > |
| 106 kComponentExtensionIMEPrefixLength + kExtensionIdLength; | 109 kComponentExtensionIMEPrefixLength + kExtensionIdLength; |
| 107 } | 110 } |
| 108 | 111 |
| 109 bool IsMemberOfExtension(const std::string& input_method_id, | 112 bool IsMemberOfExtension(const std::string& input_method_id, |
| 110 const std::string& extension_id) { | 113 const std::string& extension_id) { |
| 111 return base::StartsWithASCII(input_method_id, | 114 return base::StartsWith(input_method_id, |
| 112 kExtensionIMEPrefix + extension_id, | 115 kExtensionIMEPrefix + extension_id, |
| 113 true /* Case sensitive */); | 116 base::CompareCase::SENSITIVE); |
| 114 } | 117 } |
| 115 | 118 |
| 116 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { | 119 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { |
| 117 if (IsComponentExtensionIME(input_method_id)) | 120 if (IsComponentExtensionIME(input_method_id)) |
| 118 return base::StartsWithASCII(GetComponentIDByInputMethodID(input_method_id), | 121 return base::StartsWith(GetComponentIDByInputMethodID(input_method_id), |
| 119 "xkb:", true); | 122 "xkb:", base::CompareCase::SENSITIVE); |
| 120 return false; | 123 return false; |
| 121 } | 124 } |
| 122 | 125 |
| 123 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { | 126 std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { |
| 124 if (IsKeyboardLayoutExtension(input_method_id)) | 127 if (IsKeyboardLayoutExtension(input_method_id)) |
| 125 return GetComponentIDByInputMethodID(input_method_id); | 128 return GetComponentIDByInputMethodID(input_method_id); |
| 126 return input_method_id; | 129 return input_method_id; |
| 127 } | 130 } |
| 128 | 131 |
| 129 } // namespace extension_ime_util | 132 } // namespace extension_ime_util |
| 130 } // namespace chromeos | 133 } // namespace chromeos |
| OLD | NEW |