Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/spellcheck_common.h" | 5 #include "chrome/common/spellcheck_common.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 versioned_bdict_file_name = | 133 versioned_bdict_file_name = |
| 134 language + special_version_string[i].version + ".bdic"; | 134 language + special_version_string[i].version + ".bdic"; |
| 135 break; | 135 break; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 return dict_dir.AppendASCII(versioned_bdict_file_name); | 139 return dict_dir.AppendASCII(versioned_bdict_file_name); |
| 140 } | 140 } |
| 141 | 141 |
| 142 std::string GetCorrespondingSpellCheckLanguage(const std::string& language) { | 142 std::string GetCorrespondingSpellCheckLanguage(const std::string& language) { |
| 143 std::string best_match; | |
| 143 // Look for exact match in the Spell Check language list. | 144 // Look for exact match in the Spell Check language list. |
| 144 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); | 145 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); |
| 145 ++i) { | 146 ++i) { |
| 146 // First look for exact match in the language region of the list. | 147 // First look for exact match in the language region of the list. |
| 147 std::string spellcheck_language( | 148 std::string spellcheck_language( |
| 148 g_supported_spellchecker_languages[i].language); | 149 g_supported_spellchecker_languages[i].language); |
| 149 if (spellcheck_language == language) | 150 if (spellcheck_language == language) |
| 150 return language; | 151 return language; |
| 151 | 152 |
| 152 // Next, look for exact match in the language_region part of the list. | 153 // Next, look for exact match in the language_region part of the list. |
| 153 std::string spellcheck_language_region( | 154 std::string spellcheck_language_region( |
| 154 g_supported_spellchecker_languages[i].language_region); | 155 g_supported_spellchecker_languages[i].language_region); |
| 155 if (spellcheck_language_region == language) | 156 if (spellcheck_language_region == language) { |
| 156 return g_supported_spellchecker_languages[i].language; | 157 if (best_match.empty()) |
| 158 best_match = g_supported_spellchecker_languages[i].language; | |
|
please use gerrit instead
2016/05/02 18:02:28
If we're switching from returning the first elemen
Kevin Bailey
2016/05/02 18:20:45
The other functions depend on the current order. I
| |
| 159 } | |
| 157 } | 160 } |
| 158 | 161 |
| 159 // No match found - return blank. | 162 // No match found - return best match, if any. |
| 160 return std::string(); | 163 return best_match; |
|
please use gerrit instead
2016/05/02 18:02:28
Add a test case for blank best match.
Kevin Bailey
2016/05/02 18:20:45
I assume there already is one, since this is not n
| |
| 161 } | 164 } |
| 162 | 165 |
| 163 void SpellCheckLanguages(std::vector<std::string>* languages) { | 166 void SpellCheckLanguages(std::vector<std::string>* languages) { |
| 164 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); | 167 for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); |
| 165 ++i) { | 168 ++i) { |
| 166 languages->push_back(g_supported_spellchecker_languages[i].language); | 169 languages->push_back(g_supported_spellchecker_languages[i].language); |
| 167 } | 170 } |
| 168 } | 171 } |
| 169 | 172 |
| 170 void GetISOLanguageCountryCodeFromLocale(const std::string& locale, | 173 void GetISOLanguageCountryCodeFromLocale(const std::string& locale, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 181 error = U_ZERO_ERROR; | 184 error = U_ZERO_ERROR; |
| 182 uloc_getLanguage(id, language, arraysize(language), &error); | 185 uloc_getLanguage(id, language, arraysize(language), &error); |
| 183 country = uloc_getISO3Country(id); | 186 country = uloc_getISO3Country(id); |
| 184 } | 187 } |
| 185 *language_code = std::string(language); | 188 *language_code = std::string(language); |
| 186 *country_code = std::string(country); | 189 *country_code = std::string(country); |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace spellcheck_common | 192 } // namespace spellcheck_common |
| 190 } // namespace chrome | 193 } // namespace chrome |
| OLD | NEW |