OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 contains implementation details, the public interface is declared | 5 // This file contains implementation details, the public interface is declared |
6 // in time_format.h. | 6 // in time_format.h. |
7 | 7 |
8 #ifndef UI_BASE_L10N_FORMATTER_H_ | 8 #ifndef UI_BASE_L10N_FORMATTER_H_ |
9 #define UI_BASE_L10N_FORMATTER_H_ | 9 #define UI_BASE_L10N_FORMATTER_H_ |
10 | 10 |
| 11 #include <memory> |
| 12 |
11 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "third_party/icu/source/common/unicode/unistr.h" | 15 #include "third_party/icu/source/common/unicode/unistr.h" |
15 #include "third_party/icu/source/i18n/unicode/msgfmt.h" | 16 #include "third_party/icu/source/i18n/unicode/msgfmt.h" |
16 #include "third_party/icu/source/i18n/unicode/plurrule.h" | 17 #include "third_party/icu/source/i18n/unicode/plurrule.h" |
17 #include "ui/base/l10n/time_format.h" | 18 #include "ui/base/l10n/time_format.h" |
18 #include "ui/base/ui_base_export.h" | 19 #include "ui/base/ui_base_export.h" |
19 | 20 |
20 namespace ui { | 21 namespace ui { |
21 | 22 |
22 struct Pluralities; | 23 struct Pluralities; |
23 | 24 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 void Format(Unit unit, int value, icu::UnicodeString* formatted_string) const; | 60 void Format(Unit unit, int value, icu::UnicodeString* formatted_string) const; |
60 | 61 |
61 void Format(TwoUnits units, | 62 void Format(TwoUnits units, |
62 int value_1, | 63 int value_1, |
63 int value_2, | 64 int value_2, |
64 icu::UnicodeString* formatted_string) const; | 65 icu::UnicodeString* formatted_string) const; |
65 | 66 |
66 private: | 67 private: |
67 // Create a hard-coded fallback message format for plural formatting. | 68 // Create a hard-coded fallback message format for plural formatting. |
68 // This will never be called unless translators make a mistake. | 69 // This will never be called unless translators make a mistake. |
69 scoped_ptr<icu::MessageFormat> CreateFallbackFormat( | 70 std::unique_ptr<icu::MessageFormat> CreateFallbackFormat( |
70 const icu::PluralRules& rules, | 71 const icu::PluralRules& rules, |
71 const Pluralities& pluralities) const; | 72 const Pluralities& pluralities) const; |
72 | 73 |
73 scoped_ptr<icu::MessageFormat> InitFormat(const Pluralities& pluralities); | 74 std::unique_ptr<icu::MessageFormat> InitFormat( |
| 75 const Pluralities& pluralities); |
74 | 76 |
75 scoped_ptr<icu::MessageFormat> simple_format_[UNIT_COUNT]; | 77 std::unique_ptr<icu::MessageFormat> simple_format_[UNIT_COUNT]; |
76 scoped_ptr<icu::MessageFormat> detailed_format_[TWO_UNITS_COUNT][2]; | 78 std::unique_ptr<icu::MessageFormat> detailed_format_[TWO_UNITS_COUNT][2]; |
77 | 79 |
78 DISALLOW_IMPLICIT_CONSTRUCTORS(Formatter); | 80 DISALLOW_IMPLICIT_CONSTRUCTORS(Formatter); |
79 }; | 81 }; |
80 | 82 |
81 // Class to hold all Formatters, intended to be used in a global LazyInstance. | 83 // Class to hold all Formatters, intended to be used in a global LazyInstance. |
82 class UI_BASE_EXPORT FormatterContainer { | 84 class UI_BASE_EXPORT FormatterContainer { |
83 public: | 85 public: |
84 FormatterContainer(); | 86 FormatterContainer(); |
85 ~FormatterContainer(); | 87 ~FormatterContainer(); |
86 | 88 |
87 const Formatter* Get(TimeFormat::Format format, | 89 const Formatter* Get(TimeFormat::Format format, |
88 TimeFormat::Length length) const; | 90 TimeFormat::Length length) const; |
89 | 91 |
90 void ResetForTesting() { | 92 void ResetForTesting() { |
91 Shutdown(); | 93 Shutdown(); |
92 Initialize(); | 94 Initialize(); |
93 } | 95 } |
94 | 96 |
95 private: | 97 private: |
96 void Initialize(); | 98 void Initialize(); |
97 void Shutdown(); | 99 void Shutdown(); |
98 | 100 |
99 scoped_ptr<Formatter> | 101 std::unique_ptr<Formatter> formatter_[TimeFormat::FORMAT_COUNT] |
100 formatter_[TimeFormat::FORMAT_COUNT][TimeFormat::LENGTH_COUNT]; | 102 [TimeFormat::LENGTH_COUNT]; |
101 | 103 |
102 DISALLOW_COPY_AND_ASSIGN(FormatterContainer); | 104 DISALLOW_COPY_AND_ASSIGN(FormatterContainer); |
103 }; | 105 }; |
104 | 106 |
105 // Windows compilation requires full definition of FormatterContainer before | 107 // Windows compilation requires full definition of FormatterContainer before |
106 // LazyInstance<FormatterContainter> may be declared. | 108 // LazyInstance<FormatterContainter> may be declared. |
107 extern UI_BASE_EXPORT base::LazyInstance<FormatterContainer> g_container; | 109 extern UI_BASE_EXPORT base::LazyInstance<FormatterContainer> g_container; |
108 | 110 |
109 // For use in unit tests only. | 111 // For use in unit tests only. |
110 extern UI_BASE_EXPORT bool formatter_force_fallback; | 112 extern UI_BASE_EXPORT bool formatter_force_fallback; |
111 | 113 |
112 } // namespace ui | 114 } // namespace ui |
113 | 115 |
114 #endif // UI_BASE_L10N_FORMATTER_H_ | 116 #endif // UI_BASE_L10N_FORMATTER_H_ |
OLD | NEW |