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

Side by Side Diff: source/i18n/unicode/measfmt.h

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 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 | « source/i18n/unicode/filteredbrk.h ('k') | source/i18n/unicode/measunit.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ********************************************************************** 2 **********************************************************************
3 * Copyright (c) 2004-2014, International Business Machines 3 * Copyright (c) 2004-2015, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ********************************************************************** 5 **********************************************************************
6 * Author: Alan Liu 6 * Author: Alan Liu
7 * Created: April 20, 2004 7 * Created: April 20, 2004
8 * Since: ICU 3.0 8 * Since: ICU 3.0
9 ********************************************************************** 9 **********************************************************************
10 */ 10 */
11 #ifndef MEASUREFORMAT_H 11 #ifndef MEASUREFORMAT_H
12 #define MEASUREFORMAT_H 12 #define MEASUREFORMAT_H
13 13
14 #include "unicode/utypes.h" 14 #include "unicode/utypes.h"
15 15
16 #if !UCONFIG_NO_FORMATTING 16 #if !UCONFIG_NO_FORMATTING
17 17
18 #include "unicode/format.h" 18 #include "unicode/format.h"
19 #include "unicode/udat.h" 19 #include "unicode/udat.h"
20 20
21 /** 21 /**
22 * \file 22 * \file
23 * \brief C++ API: Formatter for measure objects. 23 * \brief C++ API: Formatter for measure objects.
24 */ 24 */
25 25
26 /** 26 /**
27 * Constants for various widths. 27 * Constants for various widths.
28 * There are 4 widths: Wide, Short, Narrow, Numeric. 28 * There are 4 widths: Wide, Short, Narrow, Numeric.
29 * For example, for English, when formatting "3 hours" 29 * For example, for English, when formatting "3 hours"
30 * Wide is "3 hours"; short is "3 hrs"; narrow is "3h"; 30 * Wide is "3 hours"; short is "3 hrs"; narrow is "3h";
31 * formatting "3 hours 17 minutes" as numeric give "3:17" 31 * formatting "3 hours 17 minutes" as numeric give "3:17"
32 * @draft ICU 53 32 * @stable ICU 53
33 */ 33 */
34 enum UMeasureFormatWidth { 34 enum UMeasureFormatWidth {
35 35
36 #ifndef U_HIDE_DRAFT_API
37 // Wide, short, and narrow must be first and in this order. 36 // Wide, short, and narrow must be first and in this order.
38 /** 37 /**
39 * Spell out measure units. 38 * Spell out measure units.
40 * @draft ICU 53 39 * @stable ICU 53
41 */ 40 */
42 UMEASFMT_WIDTH_WIDE, 41 UMEASFMT_WIDTH_WIDE,
43 42
44 /** 43 /**
45 * Abbreviate measure units. 44 * Abbreviate measure units.
46 * @draft ICU 53 45 * @stable ICU 53
47 */ 46 */
48 UMEASFMT_WIDTH_SHORT, 47 UMEASFMT_WIDTH_SHORT,
49 48
50 /** 49 /**
51 * Use symbols for measure units when possible. 50 * Use symbols for measure units when possible.
52 * @draft ICU 53 51 * @stable ICU 53
53 */ 52 */
54 UMEASFMT_WIDTH_NARROW, 53 UMEASFMT_WIDTH_NARROW,
55 54
56 /** 55 /**
57 * Completely omit measure units when possible. For example, format 56 * Completely omit measure units when possible. For example, format
58 * '5 hours, 37 minutes' as '5:37' 57 * '5 hours, 37 minutes' as '5:37'
59 * @draft ICU 53 58 * @stable ICU 53
60 */ 59 */
61 UMEASFMT_WIDTH_NUMERIC, 60 UMEASFMT_WIDTH_NUMERIC,
62 #endif /* U_HIDE_DRAFT_API */
63 61
64 /** 62 /**
65 * Count of values in this enum. 63 * Count of values in this enum.
66 * @draft ICU 53 64 * @stable ICU 53
67 */ 65 */
68 UMEASFMT_WIDTH_COUNT = 4 66 UMEASFMT_WIDTH_COUNT = 4
69 }; 67 };
70 /** @draft ICU 53 */ 68 /** @stable ICU 53 */
71 typedef enum UMeasureFormatWidth UMeasureFormatWidth; 69 typedef enum UMeasureFormatWidth UMeasureFormatWidth;
72 70
73 U_NAMESPACE_BEGIN 71 U_NAMESPACE_BEGIN
74 72
75 class Measure; 73 class Measure;
76 class MeasureUnit; 74 class MeasureUnit;
77 class NumberFormat; 75 class NumberFormat;
78 class PluralRules; 76 class PluralRules;
79 class MeasureFormatCacheData; 77 class MeasureFormatCacheData;
80 class SharedNumberFormat; 78 class SharedNumberFormat;
81 class SharedPluralRules; 79 class SharedPluralRules;
82 class QuantityFormatter; 80 class QuantityFormatter;
83 class SimplePatternFormatter; 81 class SimplePatternFormatter;
84 class ListFormatter; 82 class ListFormatter;
85 class DateFormat; 83 class DateFormat;
86 84
87 /** 85 /**
88 * 86 *
89 * A formatter for measure objects. 87 * A formatter for measure objects.
90 * 88 *
91 * @see Format 89 * @see Format
92 * @author Alan Liu 90 * @author Alan Liu
93 * @stable ICU 3.0 91 * @stable ICU 3.0
94 */ 92 */
95 class U_I18N_API MeasureFormat : public Format { 93 class U_I18N_API MeasureFormat : public Format {
96 public: 94 public:
97 using Format::parseObject; 95 using Format::parseObject;
98 using Format::format; 96 using Format::format;
99 97
100 #ifndef U_HIDE_DRAFT_API
101 /** 98 /**
102 * Constructor. 99 * Constructor.
103 * @draft ICU 53 100 * @stable ICU 53
104 */ 101 */
105 MeasureFormat( 102 MeasureFormat(
106 const Locale &locale, UMeasureFormatWidth width, UErrorCode &status) ; 103 const Locale &locale, UMeasureFormatWidth width, UErrorCode &status) ;
107 104
108 /** 105 /**
109 * Constructor. 106 * Constructor.
110 * @draft ICU 53 107 * @stable ICU 53
111 */ 108 */
112 MeasureFormat( 109 MeasureFormat(
113 const Locale &locale, 110 const Locale &locale,
114 UMeasureFormatWidth width, 111 UMeasureFormatWidth width,
115 NumberFormat *nfToAdopt, 112 NumberFormat *nfToAdopt,
116 UErrorCode &status); 113 UErrorCode &status);
117 #endif /* U_HIDE_DRAFT_API */
118 114
119 /** 115 /**
120 * Copy constructor. 116 * Copy constructor.
121 * @draft ICU 53 117 * @stable ICU 3.0
122 */ 118 */
123 MeasureFormat(const MeasureFormat &other); 119 MeasureFormat(const MeasureFormat &other);
124 120
125 /** 121 /**
126 * Assignment operator. 122 * Assignment operator.
127 * @draft ICU 53 123 * @stable ICU 3.0
128 */ 124 */
129 MeasureFormat &operator=(const MeasureFormat &rhs); 125 MeasureFormat &operator=(const MeasureFormat &rhs);
130 126
131 /** 127 /**
132 * Destructor. 128 * Destructor.
133 * @stable ICU 3.0 129 * @stable ICU 3.0
134 */ 130 */
135 virtual ~MeasureFormat(); 131 virtual ~MeasureFormat();
136 132
137 /** 133 /**
138 * Return true if given Format objects are semantically equal. 134 * Return true if given Format objects are semantically equal.
139 * @draft ICU 53 135 * @stable ICU 53
140 */ 136 */
141 virtual UBool operator==(const Format &other) const; 137 virtual UBool operator==(const Format &other) const;
142 138
143 /** 139 /**
144 * Clones this object polymorphically. 140 * Clones this object polymorphically.
145 * @draft ICU 53 141 * @stable ICU 53
146 */ 142 */
147 virtual Format *clone() const; 143 virtual Format *clone() const;
148 144
149 /** 145 /**
150 * Formats object to produce a string. 146 * Formats object to produce a string.
151 * @draft ICU 53 147 * @stable ICU 53
152 */ 148 */
153 virtual UnicodeString &format( 149 virtual UnicodeString &format(
154 const Formattable &obj, 150 const Formattable &obj,
155 UnicodeString &appendTo, 151 UnicodeString &appendTo,
156 FieldPosition &pos, 152 FieldPosition &pos,
157 UErrorCode &status) const; 153 UErrorCode &status) const;
158 154
159 /** 155 /**
160 * Parse a string to produce an object. This implementation sets 156 * Parse a string to produce an object. This implementation sets
161 * status to U_UNSUPPORTED_ERROR. 157 * status to U_UNSUPPORTED_ERROR.
162 * 158 *
163 * @draft ICU 53 159 * @draft ICU 53
164 */ 160 */
165 virtual void parseObject( 161 virtual void parseObject(
166 const UnicodeString &source, 162 const UnicodeString &source,
167 Formattable &reslt, 163 Formattable &reslt,
168 ParsePosition &pos) const; 164 ParsePosition &pos) const;
169 165
170 #ifndef U_HIDE_DRAFT_API
171 /** 166 /**
172 * Formats measure objects to produce a string. An example of such a 167 * Formats measure objects to produce a string. An example of such a
173 * formatted string is 3 meters, 3.5 centimeters. Measure objects appear 168 * formatted string is 3 meters, 3.5 centimeters. Measure objects appear
174 * in the formatted string in the same order they appear in the "measures" 169 * in the formatted string in the same order they appear in the "measures"
175 * array. The NumberFormat of this object is used only to format the amount 170 * array. The NumberFormat of this object is used only to format the amount
176 * of the very last measure. The other amounts are formatted with zero 171 * of the very last measure. The other amounts are formatted with zero
177 * decimal places while rounding toward zero. 172 * decimal places while rounding toward zero.
178 * @param measures array of measure objects. 173 * @param measures array of measure objects.
179 * @param measureCount the number of measure objects. 174 * @param measureCount the number of measure objects.
180 * @param appendTo formatted string appended here. 175 * @param appendTo formatted string appended here.
181 * @param pos the field position. 176 * @param pos the field position.
182 * @param status the error. 177 * @param status the error.
183 * @return appendTo reference 178 * @return appendTo reference
184 * 179 *
185 * @draft ICU 53 180 * @stable ICU 53
186 */ 181 */
187 UnicodeString &formatMeasures( 182 UnicodeString &formatMeasures(
188 const Measure *measures, 183 const Measure *measures,
189 int32_t measureCount, 184 int32_t measureCount,
190 UnicodeString &appendTo, 185 UnicodeString &appendTo,
191 FieldPosition &pos, 186 FieldPosition &pos,
192 UErrorCode &status) const; 187 UErrorCode &status) const;
193 #endif /* U_HIDE_DRAFT_API */
194 188
195 #ifndef U_HIDE_INTERNAL_API 189 #ifndef U_HIDE_DRAFT_API
196 /** 190 /**
197 * Works like formatMeasures but adds a per unit. An example of such a 191 * Formats a single measure per unit. An example of such a
198 * formatted string is 3 meters, 3.5 centimeters per second. 192 * formatted string is 3.5 meters per second.
199 * @param measures array of measure objects. 193 * @param measure The measure object. In above example, 3.5 meters.
200 * @param measureCount the number of measure objects. 194 * @param perUnit The per unit. In above example, it is
201 * @param perUnit The per unit. In the example formatted string, 195 * *MeasureUnit::createSecond(status).
202 * it is *MeasureUnit::createSecond(status).
203 * @param appendTo formatted string appended here. 196 * @param appendTo formatted string appended here.
204 * @param pos the field position. 197 * @param pos the field position.
205 * @param status the error. 198 * @param status the error.
206 * @return appendTo reference 199 * @return appendTo reference
207 * 200 *
208 * @internal Technology preview 201 * @draft ICU 55
209 */ 202 */
210 UnicodeString &formatMeasuresPer( 203 UnicodeString &formatMeasurePerUnit(
211 const Measure *measures, 204 const Measure &measure,
212 int32_t measureCount,
213 const MeasureUnit &perUnit, 205 const MeasureUnit &perUnit,
214 UnicodeString &appendTo, 206 UnicodeString &appendTo,
215 FieldPosition &pos, 207 FieldPosition &pos,
216 UErrorCode &status) const; 208 UErrorCode &status) const;
217 #endif /* U_HIDE_INTERNAL_API */ 209
210 #endif /* U_HIDE_DRAFT_API */
218 211
219 /** 212 /**
220 * Return a formatter for CurrencyAmount objects in the given 213 * Return a formatter for CurrencyAmount objects in the given
221 * locale. 214 * locale.
222 * @param locale desired locale 215 * @param locale desired locale
223 * @param ec input-output error code 216 * @param ec input-output error code
224 * @return a formatter object, or NULL upon error 217 * @return a formatter object, or NULL upon error
225 * @stable ICU 3.0 218 * @stable ICU 3.0
226 */ 219 */
227 static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale, 220 static MeasureFormat* U_EXPORT2 createCurrencyFormat(const Locale& locale,
(...skipping 10 matching lines...) Expand all
238 231
239 /** 232 /**
240 * Return the class ID for this class. This is useful only for comparing to 233 * Return the class ID for this class. This is useful only for comparing to
241 * a return value from getDynamicClassID(). For example: 234 * a return value from getDynamicClassID(). For example:
242 * <pre> 235 * <pre>
243 * . Base* polymorphic_pointer = createPolymorphicObject(); 236 * . Base* polymorphic_pointer = createPolymorphicObject();
244 * . if (polymorphic_pointer->getDynamicClassID() == 237 * . if (polymorphic_pointer->getDynamicClassID() ==
245 * . erived::getStaticClassID()) ... 238 * . erived::getStaticClassID()) ...
246 * </pre> 239 * </pre>
247 * @return The class ID for all objects of this class. 240 * @return The class ID for all objects of this class.
248 * @draft ICU 53 241 * @stable ICU 53
249 */ 242 */
250 static UClassID U_EXPORT2 getStaticClassID(void); 243 static UClassID U_EXPORT2 getStaticClassID(void);
251 244
252 /** 245 /**
253 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This 246 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
254 * method is to implement a simple version of RTTI, since not all C++ 247 * method is to implement a simple version of RTTI, since not all C++
255 * compilers support genuine RTTI. Polymorphic operator==() and clone() 248 * compilers support genuine RTTI. Polymorphic operator==() and clone()
256 * methods call this method. 249 * methods call this method.
257 * 250 *
258 * @return The class ID for this object. All objects of a 251 * @return The class ID for this object. All objects of a
259 * given class have the same class ID. Objects of 252 * given class have the same class ID. Objects of
260 * other classes have different class IDs. 253 * other classes have different class IDs.
261 * @draft ICU 53 254 * @stable ICU 53
262 */ 255 */
263 virtual UClassID getDynamicClassID(void) const; 256 virtual UClassID getDynamicClassID(void) const;
264 257
265 protected: 258 protected:
266 /** 259 /**
267 * Default constructor. 260 * Default constructor.
268 * @stable ICU 3.0 261 * @stable ICU 3.0
269 */ 262 */
270 MeasureFormat(); 263 MeasureFormat();
271 264
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 UErrorCode &status) const; 333 UErrorCode &status) const;
341 334
342 const SimplePatternFormatter *getPerUnitFormatter( 335 const SimplePatternFormatter *getPerUnitFormatter(
343 int32_t index, 336 int32_t index,
344 int32_t widthIndex) const; 337 int32_t widthIndex) const;
345 338
346 const SimplePatternFormatter *getPerFormatter( 339 const SimplePatternFormatter *getPerFormatter(
347 int32_t widthIndex, 340 int32_t widthIndex,
348 UErrorCode &status) const; 341 UErrorCode &status) const;
349 342
350 int32_t withPerUnit( 343 int32_t withPerUnitAndAppend(
351 const UnicodeString &formatted, 344 const UnicodeString &formatted,
352 const MeasureUnit &perUnit, 345 const MeasureUnit &perUnit,
353 UnicodeString &appendTo, 346 UnicodeString &appendTo,
354 UErrorCode &status) const; 347 UErrorCode &status) const;
355 348
356 UnicodeString &formatMeasure( 349 UnicodeString &formatMeasure(
357 const Measure &measure, 350 const Measure &measure,
358 const NumberFormat &nf, 351 const NumberFormat &nf,
359 UnicodeString &appendTo, 352 UnicodeString &appendTo,
360 FieldPosition &pos, 353 FieldPosition &pos,
(...skipping 19 matching lines...) Expand all
380 UDateFormatField smallestField, 373 UDateFormatField smallestField,
381 const Formattable &smallestAmount, 374 const Formattable &smallestAmount,
382 UnicodeString &appendTo, 375 UnicodeString &appendTo,
383 UErrorCode &status) const; 376 UErrorCode &status) const;
384 }; 377 };
385 378
386 U_NAMESPACE_END 379 U_NAMESPACE_END
387 380
388 #endif // #if !UCONFIG_NO_FORMATTING 381 #endif // #if !UCONFIG_NO_FORMATTING
389 #endif // #ifndef MEASUREFORMAT_H 382 #endif // #ifndef MEASUREFORMAT_H
OLDNEW
« no previous file with comments | « source/i18n/unicode/filteredbrk.h ('k') | source/i18n/unicode/measunit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698