dtfmtsym.h 38 KB

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