dtfmtsym.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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. #ifndef DTFMTSYM_H
  20. #define DTFMTSYM_H
  21. #include "unicode/utypes.h"
  22. #if U_SHOW_CPLUSPLUS_API
  23. #if !UCONFIG_NO_FORMATTING
  24. #include "unicode/calendar.h"
  25. #include "unicode/strenum.h"
  26. #include "unicode/uobject.h"
  27. #include "unicode/locid.h"
  28. #include "unicode/udat.h"
  29. #include "unicode/ures.h"
  30. /**
  31. * \file
  32. * \brief C++ API: Symbols for formatting dates.
  33. */
  34. U_NAMESPACE_BEGIN
  35. /* forward declaration */
  36. class SimpleDateFormat;
  37. class Hashtable;
  38. /**
  39. * DateFormatSymbols is a public class for encapsulating localizable date-time
  40. * formatting data -- including timezone data. DateFormatSymbols is used by
  41. * DateFormat and SimpleDateFormat.
  42. * <P>
  43. * Rather than first creating a DateFormatSymbols to get a date-time formatter
  44. * by using a SimpleDateFormat constructor, clients are encouraged to create a
  45. * date-time formatter using the getTimeInstance(), getDateInstance(), or
  46. * getDateTimeInstance() method in DateFormat. Each of these methods can return a
  47. * date/time formatter initialized with a default format pattern along with the
  48. * date-time formatting data for a given or default locale. After a formatter is
  49. * created, clients may modify the format pattern using the setPattern function
  50. * as so desired. For more information on using these formatter factory
  51. * functions, see DateFormat.
  52. * <P>
  53. * If clients decide to create a date-time formatter with a particular format
  54. * pattern and locale, they can do so with new SimpleDateFormat(aPattern,
  55. * new DateFormatSymbols(aLocale)). This will load the appropriate date-time
  56. * formatting data from the locale.
  57. * <P>
  58. * DateFormatSymbols objects are clonable. When clients obtain a
  59. * DateFormatSymbols object, they can feel free to modify the date-time
  60. * formatting data as necessary. For instance, clients can
  61. * replace the localized date-time format pattern characters with the ones that
  62. * they feel easy to remember. Or they can change the representative cities
  63. * originally picked by default to using their favorite ones.
  64. * <P>
  65. * DateFormatSymbols are not expected to be subclassed. Data for a calendar is
  66. * loaded out of resource bundles. The 'type' parameter indicates the type of
  67. * calendar, for example, "gregorian" or "japanese". If the type is not gregorian
  68. * (or nullptr, or an empty string) then the type is appended to the resource name,
  69. * for example, 'Eras_japanese' instead of 'Eras'. If the resource 'Eras_japanese' did
  70. * not exist (even in root), then this class will fall back to just 'Eras', that is,
  71. * Gregorian data. Therefore, the calendar implementor MUST ensure that the root
  72. * locale at least contains any resources that are to be particularized for the
  73. * calendar type.
  74. */
  75. class U_I18N_API DateFormatSymbols final : public UObject {
  76. public:
  77. /**
  78. * Construct a DateFormatSymbols object by loading format data from
  79. * resources for the default locale, in the default calendar (Gregorian).
  80. * <P>
  81. * NOTE: This constructor will never fail; if it cannot get resource
  82. * data for the default locale, it will return a last-resort object
  83. * based on hard-coded strings.
  84. *
  85. * @param status Status code. Failure
  86. * results if the resources for the default cannot be
  87. * found or cannot be loaded
  88. * @stable ICU 2.0
  89. */
  90. DateFormatSymbols(UErrorCode& status);
  91. /**
  92. * Construct a DateFormatSymbols object by loading format data from
  93. * resources for the given locale, in the default calendar (Gregorian).
  94. *
  95. * @param locale Locale to load format data from.
  96. * @param status Status code. Failure
  97. * results if the resources for the locale cannot be
  98. * found or cannot be loaded
  99. * @stable ICU 2.0
  100. */
  101. DateFormatSymbols(const Locale& locale,
  102. UErrorCode& status);
  103. #ifndef U_HIDE_INTERNAL_API
  104. /**
  105. * Construct a DateFormatSymbols object by loading format data from
  106. * resources for the default locale, in the default calendar (Gregorian).
  107. * <P>
  108. * NOTE: This constructor will never fail; if it cannot get resource
  109. * data for the default locale, it will return a last-resort object
  110. * based on hard-coded strings.
  111. *
  112. * @param type Type of calendar (as returned by Calendar::getType).
  113. * Will be used to access the correct set of strings.
  114. * (nullptr or empty string defaults to "gregorian".)
  115. * @param status Status code. Failure
  116. * results if the resources for the default cannot be
  117. * found or cannot be loaded
  118. * @internal
  119. */
  120. DateFormatSymbols(const char *type, UErrorCode& status);
  121. /**
  122. * Construct a DateFormatSymbols object by loading format data from
  123. * resources for the given locale, in the default calendar (Gregorian).
  124. *
  125. * @param locale Locale to load format data from.
  126. * @param type Type of calendar (as returned by Calendar::getType).
  127. * Will be used to access the correct set of strings.
  128. * (nullptr or empty string defaults to "gregorian".)
  129. * @param status Status code. Failure
  130. * results if the resources for the locale cannot be
  131. * found or cannot be loaded
  132. * @internal
  133. */
  134. DateFormatSymbols(const Locale& locale,
  135. const char *type,
  136. UErrorCode& status);
  137. #endif /* U_HIDE_INTERNAL_API */
  138. /**
  139. * Copy constructor.
  140. * @stable ICU 2.0
  141. */
  142. DateFormatSymbols(const DateFormatSymbols&);
  143. /**
  144. * Assignment operator.
  145. * @stable ICU 2.0
  146. */
  147. DateFormatSymbols& operator=(const DateFormatSymbols&);
  148. /**
  149. * Destructor. This is nonvirtual because this class is not designed to be
  150. * subclassed.
  151. * @stable ICU 2.0
  152. */
  153. virtual ~DateFormatSymbols();
  154. /**
  155. * Return true if another object is semantically equal to this one.
  156. *
  157. * @param other the DateFormatSymbols object to be compared with.
  158. * @return true if other is semantically equal to this.
  159. * @stable ICU 2.0
  160. */
  161. bool operator==(const DateFormatSymbols& other) const;
  162. /**
  163. * Return true if another object is semantically unequal to this one.
  164. *
  165. * @param other the DateFormatSymbols object to be compared with.
  166. * @return true if other is semantically unequal to this.
  167. * @stable ICU 2.0
  168. */
  169. bool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
  170. /**
  171. * Gets abbreviated era strings. For example: "AD" and "BC".
  172. *
  173. * @param count Filled in with length of the array.
  174. * @return the era strings.
  175. * @stable ICU 2.0
  176. */
  177. const UnicodeString* getEras(int32_t& count) const;
  178. /**
  179. * Sets abbreviated era strings. For example: "AD" and "BC".
  180. * @param eras Array of era strings (DateFormatSymbols retains ownership.)
  181. * @param count Filled in with length of the array.
  182. * @stable ICU 2.0
  183. */
  184. void setEras(const UnicodeString* eras, int32_t count);
  185. /**
  186. * Gets era name strings. For example: "Anno Domini" and "Before Christ".
  187. *
  188. * @param count Filled in with length of the array.
  189. * @return the era name strings.
  190. * @stable ICU 3.4
  191. */
  192. const UnicodeString* getEraNames(int32_t& count) const;
  193. /**
  194. * Sets era name strings. For example: "Anno Domini" and "Before Christ".
  195. * @param eraNames Array of era name strings (DateFormatSymbols retains ownership.)
  196. * @param count Filled in with length of the array.
  197. * @stable ICU 3.6
  198. */
  199. void setEraNames(const UnicodeString* eraNames, int32_t count);
  200. /**
  201. * Gets narrow era strings. For example: "A" and "B".
  202. *
  203. * @param count Filled in with length of the array.
  204. * @return the narrow era strings.
  205. * @stable ICU 4.2
  206. */
  207. const UnicodeString* getNarrowEras(int32_t& count) const;
  208. /**
  209. * Sets narrow era strings. For example: "A" and "B".
  210. * @param narrowEras Array of narrow era strings (DateFormatSymbols retains ownership.)
  211. * @param count Filled in with length of the array.
  212. * @stable ICU 4.2
  213. */
  214. void setNarrowEras(const UnicodeString* narrowEras, int32_t count);
  215. /**
  216. * Gets month strings. For example: "January", "February", etc.
  217. * @param count Filled in with length of the array.
  218. * @return the month strings. (DateFormatSymbols retains ownership.)
  219. * @stable ICU 2.0
  220. */
  221. const UnicodeString* getMonths(int32_t& count) const;
  222. /**
  223. * Sets month strings. For example: "January", "February", etc.
  224. *
  225. * @param months the new month strings. (not adopted; caller retains ownership)
  226. * @param count Filled in with length of the array.
  227. * @stable ICU 2.0
  228. */
  229. void setMonths(const UnicodeString* months, int32_t count);
  230. /**
  231. * Gets short month strings. For example: "Jan", "Feb", etc.
  232. *
  233. * @param count Filled in with length of the array.
  234. * @return the short month strings. (DateFormatSymbols retains ownership.)
  235. * @stable ICU 2.0
  236. */
  237. const UnicodeString* getShortMonths(int32_t& count) const;
  238. /**
  239. * Sets short month strings. For example: "Jan", "Feb", etc.
  240. * @param count Filled in with length of the array.
  241. * @param shortMonths the new short month strings. (not adopted; caller retains ownership)
  242. * @stable ICU 2.0
  243. */
  244. void setShortMonths(const UnicodeString* shortMonths, int32_t count);
  245. /**
  246. * Selector for date formatting context
  247. * @stable ICU 3.6
  248. */
  249. enum DtContextType {
  250. FORMAT,
  251. STANDALONE,
  252. #ifndef U_HIDE_DEPRECATED_API
  253. /**
  254. * One more than the highest normal DtContextType value.
  255. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  256. */
  257. DT_CONTEXT_COUNT
  258. #endif // U_HIDE_DEPRECATED_API
  259. };
  260. /**
  261. * Selector for date formatting width
  262. * @stable ICU 3.6
  263. */
  264. enum DtWidthType {
  265. ABBREVIATED,
  266. WIDE,
  267. NARROW,
  268. /**
  269. * Short width is currently only supported for weekday names.
  270. * @stable ICU 51
  271. */
  272. SHORT,
  273. #ifndef U_HIDE_DEPRECATED_API
  274. /**
  275. * One more than the highest normal DtWidthType value.
  276. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  277. */
  278. DT_WIDTH_COUNT = 4
  279. #endif // U_HIDE_DEPRECATED_API
  280. };
  281. /**
  282. * Gets month strings by width and context. For example: "January", "February", etc.
  283. * @param count Filled in with length of the array.
  284. * @param context The formatting context, either FORMAT or STANDALONE
  285. * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
  286. * @return the month strings. (DateFormatSymbols retains ownership.)
  287. * @stable ICU 3.4
  288. */
  289. const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const;
  290. /**
  291. * Sets month strings by width and context. For example: "January", "February", etc.
  292. *
  293. * @param months The new month strings. (not adopted; caller retains ownership)
  294. * @param count Filled in with length of the array.
  295. * @param context The formatting context, either FORMAT or STANDALONE
  296. * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
  297. * @stable ICU 3.6
  298. */
  299. void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width);
  300. /**
  301. * Gets wide weekday strings. For example: "Sunday", "Monday", etc.
  302. * @param count Filled in with length of the array.
  303. * @return the weekday strings. (DateFormatSymbols retains ownership.)
  304. * @stable ICU 2.0
  305. */
  306. const UnicodeString* getWeekdays(int32_t& count) const;
  307. /**
  308. * Sets wide weekday strings. For example: "Sunday", "Monday", etc.
  309. * @param weekdays the new weekday strings. (not adopted; caller retains ownership)
  310. * @param count Filled in with length of the array.
  311. * @stable ICU 2.0
  312. */
  313. void setWeekdays(const UnicodeString* weekdays, int32_t count);
  314. /**
  315. * Gets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is
  316. * misleading; it does not get the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.)
  317. * @param count Filled in with length of the array.
  318. * @return the abbreviated weekday strings. (DateFormatSymbols retains ownership.)
  319. * @stable ICU 2.0
  320. */
  321. const UnicodeString* getShortWeekdays(int32_t& count) const;
  322. /**
  323. * Sets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is
  324. * misleading; it does not set the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.)
  325. * @param abbrevWeekdays the new abbreviated weekday strings. (not adopted; caller retains ownership)
  326. * @param count Filled in with length of the array.
  327. * @stable ICU 2.0
  328. */
  329. void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count);
  330. /**
  331. * Gets weekday strings by width and context. For example: "Sunday", "Monday", etc.
  332. * @param count Filled in with length of the array.
  333. * @param context The formatting context, either FORMAT or STANDALONE
  334. * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW
  335. * @return the month strings. (DateFormatSymbols retains ownership.)
  336. * @stable ICU 3.4
  337. */
  338. const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const;
  339. /**
  340. * Sets weekday strings by width and context. For example: "Sunday", "Monday", etc.
  341. * @param weekdays The new weekday strings. (not adopted; caller retains ownership)
  342. * @param count Filled in with length of the array.
  343. * @param context The formatting context, either FORMAT or STANDALONE
  344. * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW
  345. * @stable ICU 3.6
  346. */
  347. void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width);
  348. /**
  349. * Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
  350. * @param count Filled in with length of the array.
  351. * @param context The formatting context, either FORMAT or STANDALONE
  352. * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
  353. * @return the quarter strings. (DateFormatSymbols retains ownership.)
  354. * @stable ICU 3.6
  355. */
  356. const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const;
  357. /**
  358. * Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
  359. *
  360. * @param quarters The new quarter strings. (not adopted; caller retains ownership)
  361. * @param count Filled in with length of the array.
  362. * @param context The formatting context, either FORMAT or STANDALONE
  363. * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
  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 char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':'
  388. /**
  389. * This alternate time separator is always recognized when parsing.
  390. * @internal
  391. */
  392. static const char16_t 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 nullptr 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 nullptr 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 method
  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 char16_t* U_EXPORT2 getPatternUChars();
  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 override;
  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. * Narrow quarters. For example: "1", "2", etc.
  691. * (In many, but not all, locales, this is the same as "Q", but there are locales for which this isn't true.)
  692. */
  693. UnicodeString *fNarrowQuarters;
  694. int32_t fNarrowQuartersCount;
  695. /**
  696. * Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc.
  697. */
  698. UnicodeString *fStandaloneQuarters;
  699. int32_t fStandaloneQuartersCount;
  700. /**
  701. * Standalone short quarter strings. For example: "Q1", "Q2", etc.
  702. */
  703. UnicodeString *fStandaloneShortQuarters;
  704. int32_t fStandaloneShortQuartersCount;
  705. /**
  706. * Standalone narrow quarter strings. For example: "1", "2", etc.
  707. * (In many, but not all, locales, this is the same as "q", but there are locales for which this isn't true.)
  708. */
  709. UnicodeString *fStandaloneNarrowQuarters;
  710. int32_t fStandaloneNarrowQuartersCount;
  711. /**
  712. * All leap month patterns, for example "{0}bis".
  713. */
  714. UnicodeString *fLeapMonthPatterns;
  715. int32_t fLeapMonthPatternsCount;
  716. /**
  717. * Cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai";
  718. * currently we only have data for format/abbreviated.
  719. * For the others, just get from format/abbreviated, ignore set.
  720. */
  721. UnicodeString *fShortYearNames;
  722. int32_t fShortYearNamesCount;
  723. /**
  724. * Cyclic zodiac names, for example "Rat", "Ox", "Tiger", etc.;
  725. * currently we only have data for format/abbreviated.
  726. * For the others, just get from format/abbreviated, ignore set.
  727. */
  728. UnicodeString *fShortZodiacNames;
  729. int32_t fShortZodiacNamesCount;
  730. /**
  731. * Localized names of time zones in this locale. This is a
  732. * two-dimensional array of strings of size n by m,
  733. * where m is at least 5 and up to 7. Each of the n rows is an
  734. * entry containing the localized names for a single TimeZone.
  735. *
  736. * Each such row contains (with i ranging from 0..n-1):
  737. *
  738. * zoneStrings[i][0] - time zone ID
  739. * example: America/Los_Angeles
  740. * zoneStrings[i][1] - long name of zone in standard time
  741. * example: Pacific Standard Time
  742. * zoneStrings[i][2] - short name of zone in standard time
  743. * example: PST
  744. * zoneStrings[i][3] - long name of zone in daylight savings time
  745. * example: Pacific Daylight Time
  746. * zoneStrings[i][4] - short name of zone in daylight savings time
  747. * example: PDT
  748. * zoneStrings[i][5] - location name of zone
  749. * example: United States (Los Angeles)
  750. * zoneStrings[i][6] - long generic name of zone
  751. * example: Pacific Time
  752. * zoneStrings[i][7] - short generic of zone
  753. * example: PT
  754. *
  755. * The zone ID is not localized; it corresponds to the ID
  756. * value associated with a system time zone object. All other entries
  757. * are localized names. If a zone does not implement daylight savings
  758. * time, the daylight savings time names are ignored.
  759. *
  760. * Note:CLDR 1.5 introduced metazone and its historical mappings.
  761. * This simple two-dimensional array is no longer sufficient to represent
  762. * localized names and its historic changes. Since ICU 3.8.1, localized
  763. * zone names extracted from ICU locale data is stored in a ZoneStringFormat
  764. * instance. But we still need to support the old way of customizing
  765. * localized zone names, so we keep this field for the purpose.
  766. */
  767. UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings
  768. UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale
  769. int32_t fZoneStringsRowCount;
  770. int32_t fZoneStringsColCount;
  771. Locale fZSFLocale; // Locale used for getting ZoneStringFormat
  772. /**
  773. * Localized date-time pattern characters. For example: use 'u' as 'y'.
  774. */
  775. UnicodeString fLocalPatternChars;
  776. /**
  777. * Capitalization transforms. For each usage type, the first array element indicates
  778. * whether to titlecase for uiListOrMenu context, the second indicates whether to
  779. * titlecase for stand-alone context.
  780. */
  781. UBool fCapitalization[kCapContextUsageTypeCount][2];
  782. /**
  783. * Abbreviated (== short) day period strings.
  784. */
  785. UnicodeString *fAbbreviatedDayPeriods;
  786. int32_t fAbbreviatedDayPeriodsCount;
  787. /**
  788. * Wide day period strings.
  789. */
  790. UnicodeString *fWideDayPeriods;
  791. int32_t fWideDayPeriodsCount;
  792. /**
  793. * Narrow day period strings.
  794. */
  795. UnicodeString *fNarrowDayPeriods;
  796. int32_t fNarrowDayPeriodsCount;
  797. /**
  798. * Stand-alone abbreviated (== short) day period strings.
  799. */
  800. UnicodeString *fStandaloneAbbreviatedDayPeriods;
  801. int32_t fStandaloneAbbreviatedDayPeriodsCount;
  802. /**
  803. * Stand-alone wide day period strings.
  804. */
  805. UnicodeString *fStandaloneWideDayPeriods;
  806. int32_t fStandaloneWideDayPeriodsCount;
  807. /**
  808. * Stand-alone narrow day period strings.
  809. */
  810. UnicodeString *fStandaloneNarrowDayPeriods;
  811. int32_t fStandaloneNarrowDayPeriodsCount;
  812. private:
  813. /** valid/actual locale information
  814. * these are always ICU locales, so the length should not be a problem
  815. */
  816. char validLocale[ULOC_FULLNAME_CAPACITY];
  817. char actualLocale[ULOC_FULLNAME_CAPACITY];
  818. DateFormatSymbols() = delete; // default constructor not implemented
  819. /**
  820. * Called by the constructors to actually load data from the resources
  821. *
  822. * @param locale The locale to get symbols for.
  823. * @param type Calendar Type (as from Calendar::getType())
  824. * @param status Input/output parameter, set to success or
  825. * failure code upon return.
  826. * @param useLastResortData determine if use last resort data
  827. */
  828. void initializeData(const Locale& locale, const char *type,
  829. UErrorCode& status, UBool useLastResortData = false);
  830. /**
  831. * Copy or alias an array in another object, as appropriate.
  832. *
  833. * @param dstArray the copy destination array.
  834. * @param dstCount fill in with the length of 'dstArray'.
  835. * @param srcArray the source array to be copied.
  836. * @param srcCount the length of items to be copied from the 'srcArray'.
  837. */
  838. static void assignArray(UnicodeString*& dstArray,
  839. int32_t& dstCount,
  840. const UnicodeString* srcArray,
  841. int32_t srcCount);
  842. /**
  843. * Return true if the given arrays' contents are equal, or if the arrays are
  844. * identical (pointers are equal).
  845. *
  846. * @param array1 one array to be compared with.
  847. * @param array2 another array to be compared with.
  848. * @param count the length of items to be copied.
  849. * @return true if the given arrays' contents are equal, or if the arrays are
  850. * identical (pointers are equal).
  851. */
  852. static UBool arrayCompare(const UnicodeString* array1,
  853. const UnicodeString* array2,
  854. int32_t count);
  855. /**
  856. * Create a copy, in fZoneStrings, of the given zone strings array. The
  857. * member variables fZoneStringsRowCount and fZoneStringsColCount should be
  858. * set already by the caller.
  859. */
  860. void createZoneStrings(const UnicodeString *const * otherStrings);
  861. /**
  862. * Delete all the storage owned by this object.
  863. */
  864. void dispose();
  865. /**
  866. * Copy all of the other's data to this.
  867. * @param other the object to be copied.
  868. */
  869. void copyData(const DateFormatSymbols& other);
  870. /**
  871. * Create zone strings array by locale if not yet available
  872. */
  873. void initZoneStringsArray();
  874. /**
  875. * Delete just the zone strings.
  876. */
  877. void disposeZoneStrings();
  878. /**
  879. * Returns the date format field index of the pattern character c,
  880. * or UDAT_FIELD_COUNT if c is not a pattern character.
  881. */
  882. static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c);
  883. /**
  884. * Returns true if f (with its pattern character repeated count times) is a numeric field.
  885. */
  886. static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count);
  887. /**
  888. * Returns true if c (repeated count times) is the pattern character for a numeric field.
  889. */
  890. static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count);
  891. public:
  892. #ifndef U_HIDE_INTERNAL_API
  893. /**
  894. * Gets a DateFormatSymbols by locale.
  895. * Unlike the constructors which always use gregorian calendar, this
  896. * method uses the calendar in the locale. If the locale contains no
  897. * explicit calendar, this method uses the default calendar for that
  898. * locale.
  899. * @param locale the locale.
  900. * @param status error returned here.
  901. * @return the new DateFormatSymbols which the caller owns.
  902. * @internal For ICU use only.
  903. */
  904. static DateFormatSymbols * U_EXPORT2 createForLocale(
  905. const Locale &locale, UErrorCode &status);
  906. #endif /* U_HIDE_INTERNAL_API */
  907. };
  908. U_NAMESPACE_END
  909. #endif /* #if !UCONFIG_NO_FORMATTING */
  910. #endif /* U_SHOW_CPLUSPLUS_API */
  911. #endif // _DTFMTSYM
  912. //eof