| 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 // This file defines a helper class for selecting a supported language from a | 5 // This file defines a helper class for selecting a supported language from a |
| 6 // set of candidates. | 6 // set of candidates. |
| 7 | 7 |
| 8 #include "chrome/installer/util/language_selector.h" | 8 #include "chrome/installer/util/language_selector.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // selected translation. | 255 // selected translation. |
| 256 // static | 256 // static |
| 257 bool LanguageSelector::SelectIf(const std::vector<std::wstring>& candidates, | 257 bool LanguageSelector::SelectIf(const std::vector<std::wstring>& candidates, |
| 258 SelectPred_Fn select_predicate, | 258 SelectPred_Fn select_predicate, |
| 259 std::wstring* matched_name, | 259 std::wstring* matched_name, |
| 260 int* matched_offset) { | 260 int* matched_offset) { |
| 261 std::wstring candidate; | 261 std::wstring candidate; |
| 262 for (std::vector<std::wstring>::const_iterator scan = candidates.begin(), | 262 for (std::vector<std::wstring>::const_iterator scan = candidates.begin(), |
| 263 end = candidates.end(); scan != end; ++scan) { | 263 end = candidates.end(); scan != end; ++scan) { |
| 264 candidate.assign(*scan); | 264 candidate.assign(*scan); |
| 265 StringToLowerASCII(&candidate); | 265 base::StringToLowerASCII(&candidate); |
| 266 if (select_predicate(candidate, matched_offset)) { | 266 if (select_predicate(candidate, matched_offset)) { |
| 267 matched_name->assign(*scan); | 267 matched_name->assign(*scan); |
| 268 return true; | 268 return true; |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 return false; | 272 return false; |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Select the best-fit translation from the ordered list |candidates|. | 275 // Select the best-fit translation from the ordered list |candidates|. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 287 VLOG(1) << "No suitable language found for any candidates."; | 287 VLOG(1) << "No suitable language found for any candidates."; |
| 288 | 288 |
| 289 // Our fallback is "en-us" | 289 // Our fallback is "en-us" |
| 290 matched_candidate_.assign(&kFallbackLanguage[0], | 290 matched_candidate_.assign(&kFallbackLanguage[0], |
| 291 arraysize(kFallbackLanguage) - 1); | 291 arraysize(kFallbackLanguage) - 1); |
| 292 offset_ = kFallbackLanguageOffset; | 292 offset_ = kFallbackLanguageOffset; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 } // namespace installer | 296 } // namespace installer |
| OLD | NEW |