Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: base/i18n/message_formatter.h

Issue 1140153005: ICU msg format support with more than one arguments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: drop unnecessary dep. on base_i18n from api_registration Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
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/strings/string16.h"
13 #include "base/strings/string_piece.h"
14 #include "base/time/time.h"
15 #include "third_party/icu/source/i18n/unicode/msgfmt.h"
16
17 namespace base {
18 namespace i18n {
19
20 class MessageFormatter;
21
22 namespace internal {
23
24 class BASE_I18N_EXPORT MessageArg {
25 public:
26 MessageArg(const char* s);
27 MessageArg(StringPiece s);
28 MessageArg(const std::string& s);
29 MessageArg(const string16& s);
30 MessageArg(int i);
31 MessageArg(double d);
32 MessageArg(const Time& t);
33
34 ~MessageArg();
35
36 private:
37 friend class base::i18n::MessageFormatter;
38 MessageArg() : f(NULL) {} // for "no argument"
Avi (use Gerrit) 2015/07/30 19:19:48 nullptr
jungshik at Google 2015/07/31 21:36:15 Done. Had to move to cc when I also switched to us
39 bool def(int *count) const;
Ryan Sleevi 2015/07/30 23:21:51 Seems like this should be documented, and perhaps
jungshik at Google 2015/07/31 21:36:15 Changed it to has_value().
40 icu::Formattable *f;
Avi (use Gerrit) 2015/07/30 19:19:48 Previous two lines, * goes on the type, not the va
jungshik at Google 2015/07/31 21:36:15 Done.
41 DISALLOW_COPY_AND_ASSIGN(MessageArg);
42 };
43
44 } // namespace internal
45
46 // Message Formatter with the ICU message format syntax support.
47 // It can format strings (UTF-8 and UTF-16), numbers and base::Time with
48 // plural, gender and other 'selectors' support. This is handy if you
49 // have multiple parameters of differnt types and some of them require
50 // plural or gender/selector support.
51 //
52 // To use this API for locale-sensitive formatting, retrieve a 'message
53 // template' in the ICU message format from a message bundle (e.g. with
54 // l10n_util::GetStringUTF16()) and pass it to FormatWith{Named,Numbered}Args.
55 //
56 // MessageFormat specs:
57 // http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessageFormat.html
58 // http://icu-project.org/apiref/icu4c/classicu_1_1DecimalFormat.html#details
59 // Examples:
60 // http://userguide.icu-project.org/formatparse/messages
61 // message_formatter_unittest.cc
62 // go/plurals inside Google.
63 // TODO(jshin): Document this API at sites.chromium.org and add a reference
64 // here.
65
66 class BASE_I18N_EXPORT MessageFormatter {
67 public:
68 static string16 FormatWithNamedArgs(
69 StringPiece16 msg,
70 StringPiece name0 = StringPiece(),
71 const internal::MessageArg& arg0 = internal::MessageArg(),
Ryan Sleevi 2015/07/30 23:21:51 I'm somewhat surprised this compiles. I thought th
jungshik at Google 2015/07/31 21:36:15 I guess it's compiled because I have 'friend class
72 StringPiece name1 = StringPiece(),
73 const internal::MessageArg& arg1 = internal::MessageArg(),
74 StringPiece name2 = StringPiece(),
75 const internal::MessageArg& arg2 = internal::MessageArg(),
76 StringPiece name3 = StringPiece(),
77 const internal::MessageArg& arg3 = internal::MessageArg(),
78 StringPiece name4 = StringPiece(),
79 const internal::MessageArg& arg4 = internal::MessageArg(),
80 StringPiece name5 = StringPiece(),
81 const internal::MessageArg& arg5 = internal::MessageArg(),
82 StringPiece name6 = StringPiece(),
83 const internal::MessageArg& arg6 = internal::MessageArg());
84
85 static string16 FormatWithNumberedArgs(
86 StringPiece16 msg,
87 const internal::MessageArg& arg0 = internal::MessageArg(),
88 const internal::MessageArg& arg1 = internal::MessageArg(),
89 const internal::MessageArg& arg2 = internal::MessageArg(),
90 const internal::MessageArg& arg3 = internal::MessageArg(),
91 const internal::MessageArg& arg4 = internal::MessageArg(),
92 const internal::MessageArg& arg5 = internal::MessageArg(),
93 const internal::MessageArg& arg6 = internal::MessageArg());
94
95 private:
96 MessageFormatter() {}
97 DISALLOW_COPY_AND_ASSIGN(MessageFormatter);
98 };
99
100 } // namespace i18n
101 } // namespace base
102 #endif
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/i18n/message_formatter.cc » ('j') | base/i18n/message_formatter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698