OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 // Copied from i18n/localization/formatter.h with modifications. | |
Ryan Sleevi
2015/07/31 22:19:36
Seems like there should at least be a newline betw
jungshik at Google
2015/08/01 14:00:58
Before making the CL, I talked to OSPO and the two
| |
5 | |
6 #ifndef BASE_I18N_MESSAGE_FORMATTER_H_ | |
7 #define BASE_I18N_MESSAGE_FORMATTER_H_ | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/i18n/base_i18n_export.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/string16.h" | |
14 #include "base/strings/string_piece.h" | |
15 #include "base/time/time.h" | |
16 #include "third_party/icu/source/i18n/unicode/msgfmt.h" | |
17 | |
18 namespace base { | |
19 namespace i18n { | |
20 | |
21 class MessageFormatter; | |
22 | |
23 namespace internal { | |
24 | |
25 class BASE_I18N_EXPORT MessageArg { | |
26 public: | |
27 MessageArg(const char* s); | |
28 MessageArg(StringPiece s); | |
29 MessageArg(const std::string& s); | |
30 MessageArg(const string16& s); | |
31 MessageArg(int i); | |
32 MessageArg(double d); | |
33 MessageArg(const Time& t); | |
Ryan Sleevi
2015/07/31 22:19:36
You could forward declare base::Time and avoid the
jungshik at Google
2015/08/01 14:00:58
Done.
| |
34 | |
35 ~MessageArg(); | |
36 | |
37 private: | |
38 friend class base::i18n::MessageFormatter; | |
39 MessageArg(); | |
Ryan Sleevi
2015/07/31 22:19:36
style nits: newline between 38 and 39, newline bet
jungshik at Google
2015/08/01 14:00:58
Done.
| |
40 bool has_value(int* count) const; | |
41 scoped_ptr<icu::Formattable> formattable; | |
Ryan Sleevi
2015/07/31 22:19:36
You could forward declare this, but I'm guessing t
jungshik at Google
2015/08/01 14:00:58
Thanks for the suggestion.
Nothing in ICU against
Ryan Sleevi
2015/08/03 08:01:41
I guess the forward declaration doesn't really buy
| |
42 DISALLOW_COPY_AND_ASSIGN(MessageArg); | |
43 }; | |
44 | |
45 } // namespace internal | |
46 | |
47 // Message Formatter with the ICU message format syntax support. | |
48 // It can format strings (UTF-8 and UTF-16), numbers and base::Time with | |
49 // plural, gender and other 'selectors' support. This is handy if you | |
50 // have multiple parameters of differnt types and some of them require | |
51 // plural or gender/selector support. | |
52 // | |
53 // To use this API for locale-sensitive formatting, retrieve a 'message | |
54 // template' in the ICU message format from a message bundle (e.g. with | |
55 // l10n_util::GetStringUTF16()) and pass it to FormatWith{Named,Numbered}Args. | |
56 // | |
57 // MessageFormat specs: | |
58 // http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessageFormat.html | |
59 // http://icu-project.org/apiref/icu4c/classicu_1_1DecimalFormat.html#details | |
60 // Examples: | |
61 // http://userguide.icu-project.org/formatparse/messages | |
62 // message_formatter_unittest.cc | |
63 // go/plurals inside Google. | |
64 // TODO(jshin): Document this API at sites.chromium.org and add a reference | |
65 // here. | |
66 | |
67 class BASE_I18N_EXPORT MessageFormatter { | |
68 public: | |
69 static string16 FormatWithNamedArgs( | |
70 StringPiece16 msg, | |
71 StringPiece name0 = StringPiece(), | |
72 const internal::MessageArg& arg0 = internal::MessageArg(), | |
73 StringPiece name1 = StringPiece(), | |
74 const internal::MessageArg& arg1 = internal::MessageArg(), | |
75 StringPiece name2 = StringPiece(), | |
76 const internal::MessageArg& arg2 = internal::MessageArg(), | |
77 StringPiece name3 = StringPiece(), | |
78 const internal::MessageArg& arg3 = internal::MessageArg(), | |
79 StringPiece name4 = StringPiece(), | |
80 const internal::MessageArg& arg4 = internal::MessageArg(), | |
81 StringPiece name5 = StringPiece(), | |
82 const internal::MessageArg& arg5 = internal::MessageArg(), | |
83 StringPiece name6 = StringPiece(), | |
84 const internal::MessageArg& arg6 = internal::MessageArg()); | |
85 | |
86 static string16 FormatWithNumberedArgs( | |
87 StringPiece16 msg, | |
88 const internal::MessageArg& arg0 = internal::MessageArg(), | |
89 const internal::MessageArg& arg1 = internal::MessageArg(), | |
90 const internal::MessageArg& arg2 = internal::MessageArg(), | |
91 const internal::MessageArg& arg3 = internal::MessageArg(), | |
92 const internal::MessageArg& arg4 = internal::MessageArg(), | |
93 const internal::MessageArg& arg5 = internal::MessageArg(), | |
94 const internal::MessageArg& arg6 = internal::MessageArg()); | |
95 | |
96 private: | |
97 MessageFormatter() {} | |
98 DISALLOW_COPY_AND_ASSIGN(MessageFormatter); | |
99 }; | |
100 | |
101 } // namespace i18n | |
102 } // namespace base | |
103 #endif | |
OLD | NEW |