/src/icu/icu4c/source/i18n/unicode/dtfmtsym.h
Line | Count | Source (jump to first uncovered line) |
1 | | // © 2016 and later: Unicode, Inc. and others. |
2 | | // License & terms of use: http://www.unicode.org/copyright.html |
3 | | /* |
4 | | ******************************************************************************** |
5 | | * Copyright (C) 1997-2016, International Business Machines |
6 | | * Corporation and others. All Rights Reserved. |
7 | | ******************************************************************************** |
8 | | * |
9 | | * File DTFMTSYM.H |
10 | | * |
11 | | * Modification History: |
12 | | * |
13 | | * Date Name Description |
14 | | * 02/19/97 aliu Converted from java. |
15 | | * 07/21/98 stephen Added getZoneIndex() |
16 | | * Changed to match C++ conventions |
17 | | ******************************************************************************** |
18 | | */ |
19 | | |
20 | | #ifndef DTFMTSYM_H |
21 | | #define DTFMTSYM_H |
22 | | |
23 | | #include "unicode/utypes.h" |
24 | | |
25 | | #if U_SHOW_CPLUSPLUS_API |
26 | | |
27 | | #if !UCONFIG_NO_FORMATTING |
28 | | |
29 | | #include "unicode/calendar.h" |
30 | | #include "unicode/strenum.h" |
31 | | #include "unicode/uobject.h" |
32 | | #include "unicode/locid.h" |
33 | | #include "unicode/udat.h" |
34 | | #include "unicode/ures.h" |
35 | | |
36 | | /** |
37 | | * \file |
38 | | * \brief C++ API: Symbols for formatting dates. |
39 | | */ |
40 | | |
41 | | U_NAMESPACE_BEGIN |
42 | | |
43 | | /* forward declaration */ |
44 | | class SimpleDateFormat; |
45 | | class Hashtable; |
46 | | class CharString; |
47 | | |
48 | | /** |
49 | | * DateFormatSymbols is a public class for encapsulating localizable date-time |
50 | | * formatting data -- including timezone data. DateFormatSymbols is used by |
51 | | * DateFormat and SimpleDateFormat. |
52 | | * <P> |
53 | | * Rather than first creating a DateFormatSymbols to get a date-time formatter |
54 | | * by using a SimpleDateFormat constructor, clients are encouraged to create a |
55 | | * date-time formatter using the getTimeInstance(), getDateInstance(), or |
56 | | * getDateTimeInstance() method in DateFormat. Each of these methods can return a |
57 | | * date/time formatter initialized with a default format pattern along with the |
58 | | * date-time formatting data for a given or default locale. After a formatter is |
59 | | * created, clients may modify the format pattern using the setPattern function |
60 | | * as so desired. For more information on using these formatter factory |
61 | | * functions, see DateFormat. |
62 | | * <P> |
63 | | * If clients decide to create a date-time formatter with a particular format |
64 | | * pattern and locale, they can do so with new SimpleDateFormat(aPattern, |
65 | | * new DateFormatSymbols(aLocale)). This will load the appropriate date-time |
66 | | * formatting data from the locale. |
67 | | * <P> |
68 | | * DateFormatSymbols objects are clonable. When clients obtain a |
69 | | * DateFormatSymbols object, they can feel free to modify the date-time |
70 | | * formatting data as necessary. For instance, clients can |
71 | | * replace the localized date-time format pattern characters with the ones that |
72 | | * they feel easy to remember. Or they can change the representative cities |
73 | | * originally picked by default to using their favorite ones. |
74 | | * <P> |
75 | | * DateFormatSymbols are not expected to be subclassed. Data for a calendar is |
76 | | * loaded out of resource bundles. The 'type' parameter indicates the type of |
77 | | * calendar, for example, "gregorian" or "japanese". If the type is not gregorian |
78 | | * (or nullptr, or an empty string) then the type is appended to the resource name, |
79 | | * for example, 'Eras_japanese' instead of 'Eras'. If the resource 'Eras_japanese' did |
80 | | * not exist (even in root), then this class will fall back to just 'Eras', that is, |
81 | | * Gregorian data. Therefore, the calendar implementor MUST ensure that the root |
82 | | * locale at least contains any resources that are to be particularized for the |
83 | | * calendar type. |
84 | | */ |
85 | | class U_I18N_API DateFormatSymbols final : public UObject { |
86 | | public: |
87 | | /** |
88 | | * Construct a DateFormatSymbols object by loading format data from |
89 | | * resources for the default locale, in the default calendar (Gregorian). |
90 | | * <P> |
91 | | * NOTE: This constructor will never fail; if it cannot get resource |
92 | | * data for the default locale, it will return a last-resort object |
93 | | * based on hard-coded strings. |
94 | | * |
95 | | * @param status Status code. Failure |
96 | | * results if the resources for the default cannot be |
97 | | * found or cannot be loaded |
98 | | * @stable ICU 2.0 |
99 | | */ |
100 | | DateFormatSymbols(UErrorCode& status); |
101 | | |
102 | | /** |
103 | | * Construct a DateFormatSymbols object by loading format data from |
104 | | * resources for the given locale, in the default calendar (Gregorian). |
105 | | * |
106 | | * @param locale Locale to load format data from. |
107 | | * @param status Status code. Failure |
108 | | * results if the resources for the locale cannot be |
109 | | * found or cannot be loaded |
110 | | * @stable ICU 2.0 |
111 | | */ |
112 | | DateFormatSymbols(const Locale& locale, |
113 | | UErrorCode& status); |
114 | | |
115 | | #ifndef U_HIDE_INTERNAL_API |
116 | | /** |
117 | | * Construct a DateFormatSymbols object by loading format data from |
118 | | * resources for the default locale, in the default calendar (Gregorian). |
119 | | * <P> |
120 | | * NOTE: This constructor will never fail; if it cannot get resource |
121 | | * data for the default locale, it will return a last-resort object |
122 | | * based on hard-coded strings. |
123 | | * |
124 | | * @param type Type of calendar (as returned by Calendar::getType). |
125 | | * Will be used to access the correct set of strings. |
126 | | * (nullptr or empty string defaults to "gregorian".) |
127 | | * @param status Status code. Failure |
128 | | * results if the resources for the default cannot be |
129 | | * found or cannot be loaded |
130 | | * @internal |
131 | | */ |
132 | | DateFormatSymbols(const char *type, UErrorCode& status); |
133 | | |
134 | | /** |
135 | | * Construct a DateFormatSymbols object by loading format data from |
136 | | * resources for the given locale, in the default calendar (Gregorian). |
137 | | * |
138 | | * @param locale Locale to load format data from. |
139 | | * @param type Type of calendar (as returned by Calendar::getType). |
140 | | * Will be used to access the correct set of strings. |
141 | | * (nullptr or empty string defaults to "gregorian".) |
142 | | * @param status Status code. Failure |
143 | | * results if the resources for the locale cannot be |
144 | | * found or cannot be loaded |
145 | | * @internal |
146 | | */ |
147 | | DateFormatSymbols(const Locale& locale, |
148 | | const char *type, |
149 | | UErrorCode& status); |
150 | | #endif /* U_HIDE_INTERNAL_API */ |
151 | | |
152 | | /** |
153 | | * Copy constructor. |
154 | | * @stable ICU 2.0 |
155 | | */ |
156 | | DateFormatSymbols(const DateFormatSymbols&); |
157 | | |
158 | | /** |
159 | | * Assignment operator. |
160 | | * @stable ICU 2.0 |
161 | | */ |
162 | | DateFormatSymbols& operator=(const DateFormatSymbols&); |
163 | | |
164 | | /** |
165 | | * Destructor. This is nonvirtual because this class is not designed to be |
166 | | * subclassed. |
167 | | * @stable ICU 2.0 |
168 | | */ |
169 | | virtual ~DateFormatSymbols(); |
170 | | |
171 | | /** |
172 | | * Return true if another object is semantically equal to this one. |
173 | | * |
174 | | * @param other the DateFormatSymbols object to be compared with. |
175 | | * @return true if other is semantically equal to this. |
176 | | * @stable ICU 2.0 |
177 | | */ |
178 | | bool operator==(const DateFormatSymbols& other) const; |
179 | | |
180 | | /** |
181 | | * Return true if another object is semantically unequal to this one. |
182 | | * |
183 | | * @param other the DateFormatSymbols object to be compared with. |
184 | | * @return true if other is semantically unequal to this. |
185 | | * @stable ICU 2.0 |
186 | | */ |
187 | 0 | bool operator!=(const DateFormatSymbols& other) const { return !operator==(other); } |
188 | | |
189 | | /** |
190 | | * Gets abbreviated era strings. For example: "AD" and "BC". |
191 | | * |
192 | | * @param count Filled in with length of the array. |
193 | | * @return the era strings. |
194 | | * @stable ICU 2.0 |
195 | | */ |
196 | | const UnicodeString* getEras(int32_t& count) const; |
197 | | |
198 | | /** |
199 | | * Sets abbreviated era strings. For example: "AD" and "BC". |
200 | | * @param eras Array of era strings (DateFormatSymbols retains ownership.) |
201 | | * @param count Filled in with length of the array. |
202 | | * @stable ICU 2.0 |
203 | | */ |
204 | | void setEras(const UnicodeString* eras, int32_t count); |
205 | | |
206 | | /** |
207 | | * Gets era name strings. For example: "Anno Domini" and "Before Christ". |
208 | | * |
209 | | * @param count Filled in with length of the array. |
210 | | * @return the era name strings. |
211 | | * @stable ICU 3.4 |
212 | | */ |
213 | | const UnicodeString* getEraNames(int32_t& count) const; |
214 | | |
215 | | /** |
216 | | * Sets era name strings. For example: "Anno Domini" and "Before Christ". |
217 | | * @param eraNames Array of era name strings (DateFormatSymbols retains ownership.) |
218 | | * @param count Filled in with length of the array. |
219 | | * @stable ICU 3.6 |
220 | | */ |
221 | | void setEraNames(const UnicodeString* eraNames, int32_t count); |
222 | | |
223 | | /** |
224 | | * Gets narrow era strings. For example: "A" and "B". |
225 | | * |
226 | | * @param count Filled in with length of the array. |
227 | | * @return the narrow era strings. |
228 | | * @stable ICU 4.2 |
229 | | */ |
230 | | const UnicodeString* getNarrowEras(int32_t& count) const; |
231 | | |
232 | | /** |
233 | | * Sets narrow era strings. For example: "A" and "B". |
234 | | * @param narrowEras Array of narrow era strings (DateFormatSymbols retains ownership.) |
235 | | * @param count Filled in with length of the array. |
236 | | * @stable ICU 4.2 |
237 | | */ |
238 | | void setNarrowEras(const UnicodeString* narrowEras, int32_t count); |
239 | | |
240 | | /** |
241 | | * Gets month strings. For example: "January", "February", etc. |
242 | | * @param count Filled in with length of the array. |
243 | | * @return the month strings. (DateFormatSymbols retains ownership.) |
244 | | * @stable ICU 2.0 |
245 | | */ |
246 | | const UnicodeString* getMonths(int32_t& count) const; |
247 | | |
248 | | /** |
249 | | * Sets month strings. For example: "January", "February", etc. |
250 | | * |
251 | | * @param months the new month strings. (not adopted; caller retains ownership) |
252 | | * @param count Filled in with length of the array. |
253 | | * @stable ICU 2.0 |
254 | | */ |
255 | | void setMonths(const UnicodeString* months, int32_t count); |
256 | | |
257 | | /** |
258 | | * Gets short month strings. For example: "Jan", "Feb", etc. |
259 | | * |
260 | | * @param count Filled in with length of the array. |
261 | | * @return the short month strings. (DateFormatSymbols retains ownership.) |
262 | | * @stable ICU 2.0 |
263 | | */ |
264 | | const UnicodeString* getShortMonths(int32_t& count) const; |
265 | | |
266 | | /** |
267 | | * Sets short month strings. For example: "Jan", "Feb", etc. |
268 | | * @param count Filled in with length of the array. |
269 | | * @param shortMonths the new short month strings. (not adopted; caller retains ownership) |
270 | | * @stable ICU 2.0 |
271 | | */ |
272 | | void setShortMonths(const UnicodeString* shortMonths, int32_t count); |
273 | | |
274 | | /** |
275 | | * Selector for date formatting context |
276 | | * @stable ICU 3.6 |
277 | | */ |
278 | | enum DtContextType { |
279 | | FORMAT, |
280 | | STANDALONE, |
281 | | #ifndef U_HIDE_DEPRECATED_API |
282 | | /** |
283 | | * One more than the highest normal DtContextType value. |
284 | | * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. |
285 | | */ |
286 | | DT_CONTEXT_COUNT |
287 | | #endif // U_HIDE_DEPRECATED_API |
288 | | }; |
289 | | |
290 | | /** |
291 | | * Selector for date formatting width |
292 | | * @stable ICU 3.6 |
293 | | */ |
294 | | enum DtWidthType { |
295 | | ABBREVIATED, |
296 | | WIDE, |
297 | | NARROW, |
298 | | /** |
299 | | * Short width is currently only supported for weekday names. |
300 | | * @stable ICU 51 |
301 | | */ |
302 | | SHORT, |
303 | | #ifndef U_HIDE_DEPRECATED_API |
304 | | /** |
305 | | * One more than the highest normal DtWidthType value. |
306 | | * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. |
307 | | */ |
308 | | DT_WIDTH_COUNT = 4 |
309 | | #endif // U_HIDE_DEPRECATED_API |
310 | | }; |
311 | | |
312 | | /** |
313 | | * Gets month strings by width and context. For example: "January", "February", etc. |
314 | | * @param count Filled in with length of the array. |
315 | | * @param context The formatting context, either FORMAT or STANDALONE |
316 | | * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. |
317 | | * @return the month strings. (DateFormatSymbols retains ownership.) |
318 | | * @stable ICU 3.4 |
319 | | */ |
320 | | const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const; |
321 | | |
322 | | /** |
323 | | * Sets month strings by width and context. For example: "January", "February", etc. |
324 | | * |
325 | | * @param months The new month strings. (not adopted; caller retains ownership) |
326 | | * @param count Filled in with length of the array. |
327 | | * @param context The formatting context, either FORMAT or STANDALONE |
328 | | * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. |
329 | | * @stable ICU 3.6 |
330 | | */ |
331 | | void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width); |
332 | | |
333 | | /** |
334 | | * Gets wide weekday strings. For example: "Sunday", "Monday", etc. |
335 | | * @param count Filled in with length of the array. |
336 | | * @return the weekday strings. (DateFormatSymbols retains ownership.) |
337 | | * @stable ICU 2.0 |
338 | | */ |
339 | | const UnicodeString* getWeekdays(int32_t& count) const; |
340 | | |
341 | | |
342 | | /** |
343 | | * Sets wide weekday strings. For example: "Sunday", "Monday", etc. |
344 | | * @param weekdays the new weekday strings. (not adopted; caller retains ownership) |
345 | | * @param count Filled in with length of the array. |
346 | | * @stable ICU 2.0 |
347 | | */ |
348 | | void setWeekdays(const UnicodeString* weekdays, int32_t count); |
349 | | |
350 | | /** |
351 | | * Gets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is |
352 | | * misleading; it does not get the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.) |
353 | | * @param count Filled in with length of the array. |
354 | | * @return the abbreviated weekday strings. (DateFormatSymbols retains ownership.) |
355 | | * @stable ICU 2.0 |
356 | | */ |
357 | | const UnicodeString* getShortWeekdays(int32_t& count) const; |
358 | | |
359 | | /** |
360 | | * Sets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is |
361 | | * misleading; it does not set the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.) |
362 | | * @param abbrevWeekdays the new abbreviated weekday strings. (not adopted; caller retains ownership) |
363 | | * @param count Filled in with length of the array. |
364 | | * @stable ICU 2.0 |
365 | | */ |
366 | | void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count); |
367 | | |
368 | | /** |
369 | | * Gets weekday strings by width and context. For example: "Sunday", "Monday", etc. |
370 | | * @param count Filled in with length of the array. |
371 | | * @param context The formatting context, either FORMAT or STANDALONE |
372 | | * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW |
373 | | * @return the month strings. (DateFormatSymbols retains ownership.) |
374 | | * @stable ICU 3.4 |
375 | | */ |
376 | | const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const; |
377 | | |
378 | | /** |
379 | | * Sets weekday strings by width and context. For example: "Sunday", "Monday", etc. |
380 | | * @param weekdays The new weekday strings. (not adopted; caller retains ownership) |
381 | | * @param count Filled in with length of the array. |
382 | | * @param context The formatting context, either FORMAT or STANDALONE |
383 | | * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW |
384 | | * @stable ICU 3.6 |
385 | | */ |
386 | | void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width); |
387 | | |
388 | | /** |
389 | | * Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc. |
390 | | * @param count Filled in with length of the array. |
391 | | * @param context The formatting context, either FORMAT or STANDALONE |
392 | | * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. |
393 | | * @return the quarter strings. (DateFormatSymbols retains ownership.) |
394 | | * @stable ICU 3.6 |
395 | | */ |
396 | | const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const; |
397 | | |
398 | | /** |
399 | | * Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc. |
400 | | * |
401 | | * @param quarters The new quarter strings. (not adopted; caller retains ownership) |
402 | | * @param count Filled in with length of the array. |
403 | | * @param context The formatting context, either FORMAT or STANDALONE |
404 | | * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. |
405 | | * @stable ICU 3.6 |
406 | | */ |
407 | | void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width); |
408 | | |
409 | | /** |
410 | | * Gets AM/PM strings. For example: "AM" and "PM". |
411 | | * @param count Filled in with length of the array. |
412 | | * @return the weekday strings. (DateFormatSymbols retains ownership.) |
413 | | * @stable ICU 2.0 |
414 | | */ |
415 | | const UnicodeString* getAmPmStrings(int32_t& count) const; |
416 | | |
417 | | /** |
418 | | * Sets ampm strings. For example: "AM" and "PM". |
419 | | * @param ampms the new ampm strings. (not adopted; caller retains ownership) |
420 | | * @param count Filled in with length of the array. |
421 | | * @stable ICU 2.0 |
422 | | */ |
423 | | void setAmPmStrings(const UnicodeString* ampms, int32_t count); |
424 | | |
425 | | #ifndef U_HIDE_INTERNAL_API |
426 | | /** |
427 | | * This default time separator is used for formatting when the locale |
428 | | * doesn't specify any time separator, and always recognized when parsing. |
429 | | * @internal |
430 | | */ |
431 | | static const char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':' |
432 | | |
433 | | /** |
434 | | * This alternate time separator is always recognized when parsing. |
435 | | * @internal |
436 | | */ |
437 | | static const char16_t ALTERNATE_TIME_SEPARATOR = 0x002e; // '.' |
438 | | |
439 | | /** |
440 | | * Gets the time separator string. For example: ":". |
441 | | * @param result Output param which will receive the time separator string. |
442 | | * @return A reference to 'result'. |
443 | | * @internal |
444 | | */ |
445 | | UnicodeString& getTimeSeparatorString(UnicodeString& result) const; |
446 | | |
447 | | /** |
448 | | * Sets the time separator string. For example: ":". |
449 | | * @param newTimeSeparator the new time separator string. |
450 | | * @internal |
451 | | */ |
452 | | void setTimeSeparatorString(const UnicodeString& newTimeSeparator); |
453 | | #endif /* U_HIDE_INTERNAL_API */ |
454 | | |
455 | | /** |
456 | | * Gets cyclic year name strings if the calendar has them, by width and context. |
457 | | * For example: "jia-zi", "yi-chou", etc. |
458 | | * @param count Filled in with length of the array. |
459 | | * @param context The usage context: FORMAT, STANDALONE. |
460 | | * @param width The requested name width: WIDE, ABBREVIATED, NARROW. |
461 | | * @return The year name strings (DateFormatSymbols retains ownership), |
462 | | * or null if they are not available for this calendar. |
463 | | * @stable ICU 54 |
464 | | */ |
465 | | const UnicodeString* getYearNames(int32_t& count, |
466 | | DtContextType context, DtWidthType width) const; |
467 | | |
468 | | /** |
469 | | * Sets cyclic year name strings by width and context. For example: "jia-zi", "yi-chou", etc. |
470 | | * |
471 | | * @param yearNames The new cyclic year name strings (not adopted; caller retains ownership). |
472 | | * @param count The length of the array. |
473 | | * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported). |
474 | | * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported). |
475 | | * @stable ICU 54 |
476 | | */ |
477 | | void setYearNames(const UnicodeString* yearNames, int32_t count, |
478 | | DtContextType context, DtWidthType width); |
479 | | |
480 | | /** |
481 | | * Gets calendar zodiac name strings if the calendar has them, by width and context. |
482 | | * For example: "Rat", "Ox", "Tiger", etc. |
483 | | * @param count Filled in with length of the array. |
484 | | * @param context The usage context: FORMAT, STANDALONE. |
485 | | * @param width The requested name width: WIDE, ABBREVIATED, NARROW. |
486 | | * @return The zodiac name strings (DateFormatSymbols retains ownership), |
487 | | * or null if they are not available for this calendar. |
488 | | * @stable ICU 54 |
489 | | */ |
490 | | const UnicodeString* getZodiacNames(int32_t& count, |
491 | | DtContextType context, DtWidthType width) const; |
492 | | |
493 | | /** |
494 | | * Sets calendar zodiac name strings by width and context. For example: "Rat", "Ox", "Tiger", etc. |
495 | | * |
496 | | * @param zodiacNames The new zodiac name strings (not adopted; caller retains ownership). |
497 | | * @param count The length of the array. |
498 | | * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported). |
499 | | * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported). |
500 | | * @stable ICU 54 |
501 | | */ |
502 | | void setZodiacNames(const UnicodeString* zodiacNames, int32_t count, |
503 | | DtContextType context, DtWidthType width); |
504 | | |
505 | | #ifndef U_HIDE_INTERNAL_API |
506 | | /** |
507 | | * Somewhat temporary constants for leap month pattern types, adequate for supporting |
508 | | * just leap month patterns as needed for Chinese lunar calendar. |
509 | | * Eventually we will add full support for different month pattern types (needed for |
510 | | * other calendars such as Hindu) at which point this approach will be replaced by a |
511 | | * more complete approach. |
512 | | * @internal |
513 | | */ |
514 | | enum EMonthPatternType |
515 | | { |
516 | | kLeapMonthPatternFormatWide, |
517 | | kLeapMonthPatternFormatAbbrev, |
518 | | kLeapMonthPatternFormatNarrow, |
519 | | kLeapMonthPatternStandaloneWide, |
520 | | kLeapMonthPatternStandaloneAbbrev, |
521 | | kLeapMonthPatternStandaloneNarrow, |
522 | | kLeapMonthPatternNumeric, |
523 | | kMonthPatternsCount |
524 | | }; |
525 | | |
526 | | /** |
527 | | * Somewhat temporary function for getting complete set of leap month patterns for all |
528 | | * contexts & widths, indexed by EMonthPatternType values. Returns nullptr if calendar |
529 | | * does not have leap month patterns. Note, there is currently no setter for this. |
530 | | * Eventually we will add full support for different month pattern types (needed for |
531 | | * other calendars such as Hindu) at which point this approach will be replaced by a |
532 | | * more complete approach. |
533 | | * @param count Filled in with length of the array (may be 0). |
534 | | * @return The leap month patterns (DateFormatSymbols retains ownership). |
535 | | * May be nullptr if there are no leap month patterns for this calendar. |
536 | | * @internal |
537 | | */ |
538 | | const UnicodeString* getLeapMonthPatterns(int32_t& count) const; |
539 | | |
540 | | #endif /* U_HIDE_INTERNAL_API */ |
541 | | |
542 | | #ifndef U_HIDE_DEPRECATED_API |
543 | | /** |
544 | | * Gets timezone strings. These strings are stored in a 2-dimensional array. |
545 | | * @param rowCount Output param to receive number of rows. |
546 | | * @param columnCount Output param to receive number of columns. |
547 | | * @return The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.) |
548 | | * @deprecated ICU 3.6 |
549 | | */ |
550 | | const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const; |
551 | | #endif /* U_HIDE_DEPRECATED_API */ |
552 | | |
553 | | /** |
554 | | * Sets timezone strings. These strings are stored in a 2-dimensional array. |
555 | | * <p><b>Note:</b> SimpleDateFormat no longer use the zone strings stored in |
556 | | * a DateFormatSymbols. Therefore, the time zone strings set by this method |
557 | | * have no effects in an instance of SimpleDateFormat for formatting time |
558 | | * zones. |
559 | | * @param strings The timezone strings as a 2-d array to be copied. (not adopted; caller retains ownership) |
560 | | * @param rowCount The number of rows (count of first index). |
561 | | * @param columnCount The number of columns (count of second index). |
562 | | * @stable ICU 2.0 |
563 | | */ |
564 | | void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount); |
565 | | |
566 | | /** |
567 | | * Get the non-localized date-time pattern characters. |
568 | | * @return the non-localized date-time pattern characters |
569 | | * @stable ICU 2.0 |
570 | | */ |
571 | | static const char16_t* U_EXPORT2 getPatternUChars(); |
572 | | |
573 | | /** |
574 | | * Gets localized date-time pattern characters. For example: 'u', 't', etc. |
575 | | * <p> |
576 | | * Note: ICU no longer provides localized date-time pattern characters for a locale |
577 | | * starting ICU 3.8. This method returns the non-localized date-time pattern |
578 | | * characters unless user defined localized data is set by setLocalPatternChars. |
579 | | * @param result Output param which will receive the localized date-time pattern characters. |
580 | | * @return A reference to 'result'. |
581 | | * @stable ICU 2.0 |
582 | | */ |
583 | | UnicodeString& getLocalPatternChars(UnicodeString& result) const; |
584 | | |
585 | | /** |
586 | | * Sets localized date-time pattern characters. For example: 'u', 't', etc. |
587 | | * @param newLocalPatternChars the new localized date-time |
588 | | * pattern characters. |
589 | | * @stable ICU 2.0 |
590 | | */ |
591 | | void setLocalPatternChars(const UnicodeString& newLocalPatternChars); |
592 | | |
593 | | /** |
594 | | * Returns the locale for this object. Two flavors are available: |
595 | | * valid and actual locale. |
596 | | * @stable ICU 2.8 |
597 | | */ |
598 | | Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; |
599 | | |
600 | | /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API, |
601 | | they are needed for .h file declarations. */ |
602 | | /** |
603 | | * Constants for capitalization context usage types. |
604 | | * @internal |
605 | | */ |
606 | | enum ECapitalizationContextUsageType |
607 | | { |
608 | | #ifndef U_HIDE_INTERNAL_API |
609 | | kCapContextUsageOther = 0, |
610 | | kCapContextUsageMonthFormat, /* except narrow */ |
611 | | kCapContextUsageMonthStandalone, /* except narrow */ |
612 | | kCapContextUsageMonthNarrow, |
613 | | kCapContextUsageDayFormat, /* except narrow */ |
614 | | kCapContextUsageDayStandalone, /* except narrow */ |
615 | | kCapContextUsageDayNarrow, |
616 | | kCapContextUsageEraWide, |
617 | | kCapContextUsageEraAbbrev, |
618 | | kCapContextUsageEraNarrow, |
619 | | kCapContextUsageZoneLong, |
620 | | kCapContextUsageZoneShort, |
621 | | kCapContextUsageMetazoneLong, |
622 | | kCapContextUsageMetazoneShort, |
623 | | #endif /* U_HIDE_INTERNAL_API */ |
624 | | kCapContextUsageTypeCount = 14 |
625 | | }; |
626 | | |
627 | | /** |
628 | | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
629 | | * |
630 | | * @stable ICU 2.2 |
631 | | */ |
632 | | virtual UClassID getDynamicClassID() const override; |
633 | | |
634 | | /** |
635 | | * ICU "poor man's RTTI", returns a UClassID for this class. |
636 | | * |
637 | | * @stable ICU 2.2 |
638 | | */ |
639 | | static UClassID U_EXPORT2 getStaticClassID(); |
640 | | |
641 | | private: |
642 | | |
643 | | friend class SimpleDateFormat; |
644 | | friend class DateFormatSymbolsSingleSetter; // see udat.cpp |
645 | | |
646 | | /** |
647 | | * Abbreviated era strings. For example: "AD" and "BC". |
648 | | */ |
649 | | UnicodeString* fEras; |
650 | | int32_t fErasCount; |
651 | | |
652 | | /** |
653 | | * Era name strings. For example: "Anno Domini" and "Before Christ". |
654 | | */ |
655 | | UnicodeString* fEraNames; |
656 | | int32_t fEraNamesCount; |
657 | | |
658 | | /** |
659 | | * Narrow era strings. For example: "A" and "B". |
660 | | */ |
661 | | UnicodeString* fNarrowEras; |
662 | | int32_t fNarrowErasCount; |
663 | | |
664 | | /** |
665 | | * Month strings. For example: "January", "February", etc. |
666 | | */ |
667 | | UnicodeString* fMonths; |
668 | | int32_t fMonthsCount; |
669 | | |
670 | | /** |
671 | | * Short month strings. For example: "Jan", "Feb", etc. |
672 | | */ |
673 | | UnicodeString* fShortMonths; |
674 | | int32_t fShortMonthsCount; |
675 | | |
676 | | /** |
677 | | * Narrow month strings. For example: "J", "F", etc. |
678 | | */ |
679 | | UnicodeString* fNarrowMonths; |
680 | | int32_t fNarrowMonthsCount; |
681 | | |
682 | | /** |
683 | | * Standalone Month strings. For example: "January", "February", etc. |
684 | | */ |
685 | | UnicodeString* fStandaloneMonths; |
686 | | int32_t fStandaloneMonthsCount; |
687 | | |
688 | | /** |
689 | | * Standalone Short month strings. For example: "Jan", "Feb", etc. |
690 | | */ |
691 | | UnicodeString* fStandaloneShortMonths; |
692 | | int32_t fStandaloneShortMonthsCount; |
693 | | |
694 | | /** |
695 | | * Standalone Narrow month strings. For example: "J", "F", etc. |
696 | | */ |
697 | | UnicodeString* fStandaloneNarrowMonths; |
698 | | int32_t fStandaloneNarrowMonthsCount; |
699 | | |
700 | | /** |
701 | | * CLDR-style format wide weekday strings. For example: "Sunday", "Monday", etc. |
702 | | */ |
703 | | UnicodeString* fWeekdays; |
704 | | int32_t fWeekdaysCount; |
705 | | |
706 | | /** |
707 | | * CLDR-style format abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc. |
708 | | */ |
709 | | UnicodeString* fShortWeekdays; |
710 | | int32_t fShortWeekdaysCount; |
711 | | |
712 | | /** |
713 | | * CLDR-style format short weekday strings. For example: "Su", "Mo", etc. |
714 | | */ |
715 | | UnicodeString* fShorterWeekdays; |
716 | | int32_t fShorterWeekdaysCount; |
717 | | |
718 | | /** |
719 | | * CLDR-style format narrow weekday strings. For example: "S", "M", etc. |
720 | | */ |
721 | | UnicodeString* fNarrowWeekdays; |
722 | | int32_t fNarrowWeekdaysCount; |
723 | | |
724 | | /** |
725 | | * CLDR-style standalone wide weekday strings. For example: "Sunday", "Monday", etc. |
726 | | */ |
727 | | UnicodeString* fStandaloneWeekdays; |
728 | | int32_t fStandaloneWeekdaysCount; |
729 | | |
730 | | /** |
731 | | * CLDR-style standalone abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc. |
732 | | */ |
733 | | UnicodeString* fStandaloneShortWeekdays; |
734 | | int32_t fStandaloneShortWeekdaysCount; |
735 | | |
736 | | /** |
737 | | * CLDR-style standalone short weekday strings. For example: "Su", "Mo", etc. |
738 | | */ |
739 | | UnicodeString* fStandaloneShorterWeekdays; |
740 | | int32_t fStandaloneShorterWeekdaysCount; |
741 | | |
742 | | /** |
743 | | * Standalone Narrow weekday strings. For example: "Sun", "Mon", etc. |
744 | | */ |
745 | | UnicodeString* fStandaloneNarrowWeekdays; |
746 | | int32_t fStandaloneNarrowWeekdaysCount; |
747 | | |
748 | | /** |
749 | | * Ampm strings. For example: "AM" and "PM". |
750 | | */ |
751 | | UnicodeString* fAmPms; |
752 | | int32_t fAmPmsCount; |
753 | | |
754 | | /** |
755 | | * Narrow Ampm strings. For example: "a" and "p". |
756 | | */ |
757 | | UnicodeString* fNarrowAmPms; |
758 | | int32_t fNarrowAmPmsCount; |
759 | | |
760 | | /** |
761 | | * Time separator string. For example: ":". |
762 | | */ |
763 | | UnicodeString fTimeSeparator; |
764 | | |
765 | | /** |
766 | | * Quarter strings. For example: "1st quarter", "2nd quarter", etc. |
767 | | */ |
768 | | UnicodeString *fQuarters; |
769 | | int32_t fQuartersCount; |
770 | | |
771 | | /** |
772 | | * Short quarters. For example: "Q1", "Q2", etc. |
773 | | */ |
774 | | UnicodeString *fShortQuarters; |
775 | | int32_t fShortQuartersCount; |
776 | | |
777 | | /** |
778 | | * Narrow quarters. For example: "1", "2", etc. |
779 | | * (In many, but not all, locales, this is the same as "Q", but there are locales for which this isn't true.) |
780 | | */ |
781 | | UnicodeString *fNarrowQuarters; |
782 | | int32_t fNarrowQuartersCount; |
783 | | |
784 | | /** |
785 | | * Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc. |
786 | | */ |
787 | | UnicodeString *fStandaloneQuarters; |
788 | | int32_t fStandaloneQuartersCount; |
789 | | |
790 | | /** |
791 | | * Standalone short quarter strings. For example: "Q1", "Q2", etc. |
792 | | */ |
793 | | UnicodeString *fStandaloneShortQuarters; |
794 | | int32_t fStandaloneShortQuartersCount; |
795 | | |
796 | | /** |
797 | | * Standalone narrow quarter strings. For example: "1", "2", etc. |
798 | | * (In many, but not all, locales, this is the same as "q", but there are locales for which this isn't true.) |
799 | | */ |
800 | | UnicodeString *fStandaloneNarrowQuarters; |
801 | | int32_t fStandaloneNarrowQuartersCount; |
802 | | |
803 | | /** |
804 | | * All leap month patterns, for example "{0}bis". |
805 | | */ |
806 | | UnicodeString *fLeapMonthPatterns; |
807 | | int32_t fLeapMonthPatternsCount; |
808 | | |
809 | | /** |
810 | | * Cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai"; |
811 | | * currently we only have data for format/abbreviated. |
812 | | * For the others, just get from format/abbreviated, ignore set. |
813 | | */ |
814 | | UnicodeString *fShortYearNames; |
815 | | int32_t fShortYearNamesCount; |
816 | | |
817 | | /** |
818 | | * Cyclic zodiac names, for example "Rat", "Ox", "Tiger", etc.; |
819 | | * currently we only have data for format/abbreviated. |
820 | | * For the others, just get from format/abbreviated, ignore set. |
821 | | */ |
822 | | UnicodeString *fShortZodiacNames; |
823 | | int32_t fShortZodiacNamesCount; |
824 | | |
825 | | /** |
826 | | * Localized names of time zones in this locale. This is a |
827 | | * two-dimensional array of strings of size n by m, |
828 | | * where m is at least 5 and up to 7. Each of the n rows is an |
829 | | * entry containing the localized names for a single TimeZone. |
830 | | * |
831 | | * Each such row contains (with i ranging from 0..n-1): |
832 | | * |
833 | | * zoneStrings[i][0] - time zone ID |
834 | | * example: America/Los_Angeles |
835 | | * zoneStrings[i][1] - long name of zone in standard time |
836 | | * example: Pacific Standard Time |
837 | | * zoneStrings[i][2] - short name of zone in standard time |
838 | | * example: PST |
839 | | * zoneStrings[i][3] - long name of zone in daylight savings time |
840 | | * example: Pacific Daylight Time |
841 | | * zoneStrings[i][4] - short name of zone in daylight savings time |
842 | | * example: PDT |
843 | | * zoneStrings[i][5] - location name of zone |
844 | | * example: United States (Los Angeles) |
845 | | * zoneStrings[i][6] - long generic name of zone |
846 | | * example: Pacific Time |
847 | | * zoneStrings[i][7] - short generic of zone |
848 | | * example: PT |
849 | | * |
850 | | * The zone ID is not localized; it corresponds to the ID |
851 | | * value associated with a system time zone object. All other entries |
852 | | * are localized names. If a zone does not implement daylight savings |
853 | | * time, the daylight savings time names are ignored. |
854 | | * |
855 | | * Note:CLDR 1.5 introduced metazone and its historical mappings. |
856 | | * This simple two-dimensional array is no longer sufficient to represent |
857 | | * localized names and its historic changes. Since ICU 3.8.1, localized |
858 | | * zone names extracted from ICU locale data is stored in a ZoneStringFormat |
859 | | * instance. But we still need to support the old way of customizing |
860 | | * localized zone names, so we keep this field for the purpose. |
861 | | */ |
862 | | UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings |
863 | | UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale |
864 | | int32_t fZoneStringsRowCount; |
865 | | int32_t fZoneStringsColCount; |
866 | | |
867 | | Locale fZSFLocale; // Locale used for getting ZoneStringFormat |
868 | | |
869 | | /** |
870 | | * Localized date-time pattern characters. For example: use 'u' as 'y'. |
871 | | */ |
872 | | UnicodeString fLocalPatternChars; |
873 | | |
874 | | /** |
875 | | * Capitalization transforms. For each usage type, the first array element indicates |
876 | | * whether to titlecase for uiListOrMenu context, the second indicates whether to |
877 | | * titlecase for stand-alone context. |
878 | | */ |
879 | | UBool fCapitalization[kCapContextUsageTypeCount][2]; |
880 | | |
881 | | /** |
882 | | * Abbreviated (== short) day period strings. |
883 | | */ |
884 | | UnicodeString *fAbbreviatedDayPeriods; |
885 | | int32_t fAbbreviatedDayPeriodsCount; |
886 | | |
887 | | /** |
888 | | * Wide day period strings. |
889 | | */ |
890 | | UnicodeString *fWideDayPeriods; |
891 | | int32_t fWideDayPeriodsCount; |
892 | | |
893 | | /** |
894 | | * Narrow day period strings. |
895 | | */ |
896 | | UnicodeString *fNarrowDayPeriods; |
897 | | int32_t fNarrowDayPeriodsCount; |
898 | | |
899 | | /** |
900 | | * Stand-alone abbreviated (== short) day period strings. |
901 | | */ |
902 | | UnicodeString *fStandaloneAbbreviatedDayPeriods; |
903 | | int32_t fStandaloneAbbreviatedDayPeriodsCount; |
904 | | |
905 | | /** |
906 | | * Stand-alone wide day period strings. |
907 | | */ |
908 | | UnicodeString *fStandaloneWideDayPeriods; |
909 | | int32_t fStandaloneWideDayPeriodsCount; |
910 | | |
911 | | /** |
912 | | * Stand-alone narrow day period strings. |
913 | | */ |
914 | | UnicodeString *fStandaloneNarrowDayPeriods; |
915 | | int32_t fStandaloneNarrowDayPeriodsCount; |
916 | | |
917 | | private: |
918 | | /** valid/actual locale information |
919 | | * these are always ICU locales, so the length should not be a problem |
920 | | */ |
921 | | CharString* validLocale = nullptr; |
922 | | CharString* actualLocale = nullptr; |
923 | | |
924 | | DateFormatSymbols() = delete; // default constructor not implemented |
925 | | |
926 | | /** |
927 | | * Called by the constructors to actually load data from the resources |
928 | | * |
929 | | * @param locale The locale to get symbols for. |
930 | | * @param type Calendar Type (as from Calendar::getType()) |
931 | | * @param status Input/output parameter, set to success or |
932 | | * failure code upon return. |
933 | | * @param useLastResortData determine if use last resort data |
934 | | */ |
935 | | void initializeData(const Locale& locale, const char *type, |
936 | | UErrorCode& status, UBool useLastResortData = false); |
937 | | |
938 | | /** |
939 | | * Copy or alias an array in another object, as appropriate. |
940 | | * |
941 | | * @param dstArray the copy destination array. |
942 | | * @param dstCount fill in with the length of 'dstArray'. |
943 | | * @param srcArray the source array to be copied. |
944 | | * @param srcCount the length of items to be copied from the 'srcArray'. |
945 | | */ |
946 | | static void assignArray(UnicodeString*& dstArray, |
947 | | int32_t& dstCount, |
948 | | const UnicodeString* srcArray, |
949 | | int32_t srcCount); |
950 | | |
951 | | /** |
952 | | * Return true if the given arrays' contents are equal, or if the arrays are |
953 | | * identical (pointers are equal). |
954 | | * |
955 | | * @param array1 one array to be compared with. |
956 | | * @param array2 another array to be compared with. |
957 | | * @param count the length of items to be copied. |
958 | | * @return true if the given arrays' contents are equal, or if the arrays are |
959 | | * identical (pointers are equal). |
960 | | */ |
961 | | static UBool arrayCompare(const UnicodeString* array1, |
962 | | const UnicodeString* array2, |
963 | | int32_t count); |
964 | | |
965 | | /** |
966 | | * Create a copy, in fZoneStrings, of the given zone strings array. The |
967 | | * member variables fZoneStringsRowCount and fZoneStringsColCount should be |
968 | | * set already by the caller. |
969 | | */ |
970 | | void createZoneStrings(const UnicodeString *const * otherStrings); |
971 | | |
972 | | /** |
973 | | * Delete all the storage owned by this object. |
974 | | */ |
975 | | void dispose(); |
976 | | |
977 | | /** |
978 | | * Copy all of the other's data to this. |
979 | | * @param other the object to be copied. |
980 | | */ |
981 | | void copyData(const DateFormatSymbols& other); |
982 | | |
983 | | /** |
984 | | * Create zone strings array by locale if not yet available |
985 | | */ |
986 | | void initZoneStringsArray(); |
987 | | |
988 | | /** |
989 | | * Delete just the zone strings. |
990 | | */ |
991 | | void disposeZoneStrings(); |
992 | | |
993 | | /** |
994 | | * Returns the date format field index of the pattern character c, |
995 | | * or UDAT_FIELD_COUNT if c is not a pattern character. |
996 | | */ |
997 | | static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c); |
998 | | |
999 | | /** |
1000 | | * Returns true if f (with its pattern character repeated count times) is a numeric field. |
1001 | | */ |
1002 | | static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count); |
1003 | | |
1004 | | /** |
1005 | | * Returns true if c (repeated count times) is the pattern character for a numeric field. |
1006 | | */ |
1007 | | static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count); |
1008 | | public: |
1009 | | #ifndef U_HIDE_INTERNAL_API |
1010 | | /** |
1011 | | * Gets a DateFormatSymbols by locale. |
1012 | | * Unlike the constructors which always use gregorian calendar, this |
1013 | | * method uses the calendar in the locale. If the locale contains no |
1014 | | * explicit calendar, this method uses the default calendar for that |
1015 | | * locale. |
1016 | | * @param locale the locale. |
1017 | | * @param status error returned here. |
1018 | | * @return the new DateFormatSymbols which the caller owns. |
1019 | | * @internal For ICU use only. |
1020 | | */ |
1021 | | static DateFormatSymbols * U_EXPORT2 createForLocale( |
1022 | | const Locale &locale, UErrorCode &status); |
1023 | | #endif /* U_HIDE_INTERNAL_API */ |
1024 | | }; |
1025 | | |
1026 | | U_NAMESPACE_END |
1027 | | |
1028 | | #endif /* #if !UCONFIG_NO_FORMATTING */ |
1029 | | |
1030 | | #endif /* U_SHOW_CPLUSPLUS_API */ |
1031 | | |
1032 | | #endif // _DTFMTSYM |
1033 | | //eof |