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

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: comments addressed Created 5 years, 4 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
« no previous file with comments | « base/base.gypi ('k') | base/i18n/message_formatter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
5 #ifndef BASE_I18N_MESSAGE_FORMATTER_H_
6 #define BASE_I18N_MESSAGE_FORMATTER_H_
7
8 #include <string>
9
10 #include "base/i18n/base_i18n_export.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/string_piece.h"
14 // For versioned icu namespace
15 #include "third_party/icu/source/common/unicode/uversion.h"
16
17 U_NAMESPACE_BEGIN
18 class Formattable;
19 U_NAMESPACE_END
20
21 namespace base {
22
23 class Time;
24
25 namespace i18n {
26
27 class MessageFormatter;
28
29 namespace internal {
30
31 class BASE_I18N_EXPORT MessageArg {
32 public:
33 MessageArg(const char* s);
34 MessageArg(StringPiece s);
35 MessageArg(const std::string& s);
36 MessageArg(const string16& s);
37 MessageArg(int i);
38 MessageArg(double d);
39 MessageArg(const Time& t);
40 ~MessageArg();
41
42 private:
43 friend class base::i18n::MessageFormatter;
44 MessageArg();
45 // Tests if this argument has a value, and if so increments *count.
46 bool has_value(int* count) const;
47 scoped_ptr<icu::Formattable> formattable;
48 DISALLOW_COPY_AND_ASSIGN(MessageArg);
49 };
50
51 } // namespace internal
52
53 // Message Formatter with the ICU message format syntax support.
54 // It can format strings (UTF-8 and UTF-16), numbers and base::Time with
55 // plural, gender and other 'selectors' support. This is handy if you
56 // have multiple parameters of differnt types and some of them require
57 // plural or gender/selector support.
58 //
59 // To use this API for locale-sensitive formatting, retrieve a 'message
60 // template' in the ICU message format from a message bundle (e.g. with
61 // l10n_util::GetStringUTF16()) and pass it to FormatWith{Named,Numbered}Args.
62 //
63 // MessageFormat specs:
64 // http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessageFormat.html
65 // http://icu-project.org/apiref/icu4c/classicu_1_1DecimalFormat.html#details
66 // Examples:
67 // http://userguide.icu-project.org/formatparse/messages
68 // message_formatter_unittest.cc
69 // go/plurals inside Google.
70 // TODO(jshin): Document this API at sites.chromium.org and add a reference
71 // here.
72
73 class BASE_I18N_EXPORT MessageFormatter {
74 public:
75 static string16 FormatWithNamedArgs(
76 StringPiece16 msg,
77 StringPiece name0 = StringPiece(),
78 const internal::MessageArg& arg0 = internal::MessageArg(),
79 StringPiece name1 = StringPiece(),
80 const internal::MessageArg& arg1 = internal::MessageArg(),
81 StringPiece name2 = StringPiece(),
82 const internal::MessageArg& arg2 = internal::MessageArg(),
83 StringPiece name3 = StringPiece(),
84 const internal::MessageArg& arg3 = internal::MessageArg(),
85 StringPiece name4 = StringPiece(),
86 const internal::MessageArg& arg4 = internal::MessageArg(),
87 StringPiece name5 = StringPiece(),
88 const internal::MessageArg& arg5 = internal::MessageArg(),
89 StringPiece name6 = StringPiece(),
90 const internal::MessageArg& arg6 = internal::MessageArg());
91
92 static string16 FormatWithNumberedArgs(
93 StringPiece16 msg,
94 const internal::MessageArg& arg0 = internal::MessageArg(),
95 const internal::MessageArg& arg1 = internal::MessageArg(),
96 const internal::MessageArg& arg2 = internal::MessageArg(),
97 const internal::MessageArg& arg3 = internal::MessageArg(),
98 const internal::MessageArg& arg4 = internal::MessageArg(),
99 const internal::MessageArg& arg5 = internal::MessageArg(),
100 const internal::MessageArg& arg6 = internal::MessageArg());
101
102 private:
103 MessageFormatter() {}
104 DISALLOW_COPY_AND_ASSIGN(MessageFormatter);
105 };
106
107 } // namespace i18n
108 } // namespace base
109 #endif
brettw 2015/08/04 17:04:19 Blank line before this, need header guard comment
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/i18n/message_formatter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698