| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // This file declares a helper class for selecting a supported language from a |
| 6 // set of candidates. |
| 7 |
| 8 #ifndef CHROME_INSTALLER_UTIL_LANGUAGE_SELECTOR_H_ |
| 9 #define CHROME_INSTALLER_UTIL_LANGUAGE_SELECTOR_H_ |
| 10 #pragma once |
| 11 |
| 12 #include <string> |
| 13 #include <vector> |
| 14 |
| 15 #include "base/basictypes.h" |
| 16 |
| 17 namespace installer_util { |
| 18 |
| 19 // A helper class for selecting a supported language from a set of candidates. |
| 20 // By default, the candidates are retrieved from the operating system. |
| 21 class LanguageSelector { |
| 22 public: |
| 23 // Default constructor will select from the set of languages supported by the |
| 24 // operating system. |
| 25 LanguageSelector(); |
| 26 |
| 27 // Constructor for testing purposes. |
| 28 explicit LanguageSelector(const std::vector<std::wstring>& candidates); |
| 29 |
| 30 ~LanguageSelector(); |
| 31 |
| 32 // The offset of the matched language (i.e., IDS_L10N_OFFSET_*). |
| 33 int offset() const { return offset_; } |
| 34 |
| 35 // The full name of the candidate language for which a match was found. |
| 36 const std::wstring& matched_candidate() const { return matched_candidate_; } |
| 37 |
| 38 // The name of the selected translation. |
| 39 std::wstring selected_translation() const { return GetLanguageName(offset_); } |
| 40 |
| 41 // Returns the name of a translation given its offset. |
| 42 static std::wstring GetLanguageName(int offset); |
| 43 |
| 44 private: |
| 45 typedef bool (*SelectPred_Fn)(const std::wstring&, int*); |
| 46 |
| 47 static bool SelectIf(const std::vector<std::wstring>& candidates, |
| 48 SelectPred_Fn select_predicate, |
| 49 std::wstring* matched_name, int* matched_offset); |
| 50 void DoSelect(const std::vector<std::wstring>& candidates); |
| 51 |
| 52 std::wstring matched_candidate_; |
| 53 int offset_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(LanguageSelector); |
| 56 }; |
| 57 |
| 58 } // namespace installer_util. |
| 59 |
| 60 #endif // CHROME_INSTALLER_UTIL_LANGUAGE_SELECTOR_H_ |
| OLD | NEW |