dtfmtsym.h 37 KB

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