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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 false)) << "kLanguageToOffsetWildcards is not sorted"; | 117 false)) << "kLanguageToOffsetWildcards is not sorted"; |
118 } | 118 } |
119 #endif // !defined(NDEBUG) | 119 #endif // !defined(NDEBUG) |
120 | 120 |
121 // A less-than overload to do slightly more efficient searches in the | 121 // A less-than overload to do slightly more efficient searches in the |
122 // sorted arrays. | 122 // sorted arrays. |
123 bool operator<(const LangToOffset& left, const std::wstring& right) { | 123 bool operator<(const LangToOffset& left, const std::wstring& right) { |
124 return left.language < right; | 124 return left.language < right; |
125 } | 125 } |
126 | 126 |
127 // A less-than overload to do slightly more efficient searches in the | |
128 // sorted arrays. | |
129 bool operator<(const std::wstring& left, const LangToOffset& right) { | |
130 return left < right.language; | |
131 } | |
132 | |
133 // A not-so-efficient less-than overload for the same uses as above. | |
134 bool operator<(const LangToOffset& left, const LangToOffset& right) { | |
135 return std::wstring(left.language) < right.language; | |
136 } | |
137 | |
138 // A compare function for searching in a sorted array by offset. | 127 // A compare function for searching in a sorted array by offset. |
139 bool IsOffsetLessThan(const LangToOffset& left, const LangToOffset& right) { | 128 bool IsOffsetLessThan(const LangToOffset& left, const LangToOffset& right) { |
140 return left.offset < right.offset; | 129 return left.offset < right.offset; |
141 } | 130 } |
142 | 131 |
143 // Binary search in one of the sorted arrays to find the offset corresponding to | 132 // Binary search in one of the sorted arrays to find the offset corresponding to |
144 // a given language |name|. | 133 // a given language |name|. |
145 bool TryFindOffset(const LangToOffset* first, const LangToOffset* last, | 134 bool TryFindOffset(const LangToOffset* first, const LangToOffset* last, |
146 const std::wstring& name, int* offset) { | 135 const std::wstring& name, int* offset) { |
147 const LangToOffset* search_result = std::lower_bound(first, last, name); | 136 const LangToOffset* search_result = std::lower_bound(first, last, name); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 VLOG(1) << "No suitable language found for any candidates."; | 272 VLOG(1) << "No suitable language found for any candidates."; |
284 | 273 |
285 // Our fallback is "en-us" | 274 // Our fallback is "en-us" |
286 matched_candidate_.assign(&kFallbackLanguage[0], | 275 matched_candidate_.assign(&kFallbackLanguage[0], |
287 arraysize(kFallbackLanguage) - 1); | 276 arraysize(kFallbackLanguage) - 1); |
288 offset_ = kFallbackLanguageOffset; | 277 offset_ = kFallbackLanguageOffset; |
289 } | 278 } |
290 } | 279 } |
291 | 280 |
292 } // namespace installer | 281 } // namespace installer |
OLD | NEW |