dtfmtsym.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. /*
  2. ********************************************************************************
  3. * Copyright (C) 1997-2015, 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. #endif /* U_HIDE_INTERNAL_API */
  382. #ifndef U_HIDE_DRAFT_API
  383. /**
  384. * Gets the time separator string. For example: ":".
  385. * @param result Output param which will receive the time separator string.
  386. * @return A reference to 'result'.
  387. * @draft ICU 55
  388. */
  389. UnicodeString& getTimeSeparatorString(UnicodeString& result) const;
  390. /**
  391. * Sets the time separator string. For example: ":".
  392. * @param newTimeSeparator the new time separator string.
  393. * @draft ICU 55
  394. */
  395. void setTimeSeparatorString(const UnicodeString& newTimeSeparator);
  396. #endif /* U_HIDE_DRAFT_API */
  397. #ifndef U_HIDE_DRAFT_API
  398. /**
  399. * Gets cyclic year name strings if the calendar has them, by width and context.
  400. * For example: "jia-zi", "yi-chou", etc.
  401. * @param count Filled in with length of the array.
  402. * @param context The usage context: FORMAT, STANDALONE.
  403. * @param width The requested name width: WIDE, ABBREVIATED, NARROW.
  404. * @return The year name strings (DateFormatSymbols retains ownership),
  405. * or null if they are not available for this calendar.
  406. * @draft ICU 54
  407. */
  408. const UnicodeString* getYearNames(int32_t& count,
  409. DtContextType context, DtWidthType width) const;
  410. /**
  411. * Sets cyclic year name strings by width and context. For example: "jia-zi", "yi-chou", etc.
  412. *
  413. * @param yearNames The new cyclic year name strings (not adopted; caller retains ownership).
  414. * @param count The length of the array.
  415. * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported).
  416. * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported).
  417. * @draft ICU 54
  418. */
  419. void setYearNames(const UnicodeString* yearNames, int32_t count,
  420. DtContextType context, DtWidthType width);
  421. /**
  422. * Gets calendar zodiac name strings if the calendar has them, by width and context.
  423. * For example: "Rat", "Ox", "Tiger", etc.
  424. * @param count Filled in with length of the array.
  425. * @param context The usage context: FORMAT, STANDALONE.
  426. * @param width The requested name width: WIDE, ABBREVIATED, NARROW.
  427. * @return The zodiac name strings (DateFormatSymbols retains ownership),
  428. * or null if they are not available for this calendar.
  429. * @draft ICU 54
  430. */
  431. const UnicodeString* getZodiacNames(int32_t& count,
  432. DtContextType context, DtWidthType width) const;
  433. /**
  434. * Sets calendar zodiac name strings by width and context. For example: "Rat", "Ox", "Tiger", etc.
  435. *
  436. * @param zodiacNames The new zodiac name strings (not adopted; caller retains ownership).
  437. * @param count The length of the array.
  438. * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported).
  439. * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported).
  440. * @draft ICU 54
  441. */
  442. void setZodiacNames(const UnicodeString* zodiacNames, int32_t count,
  443. DtContextType context, DtWidthType width);
  444. #endif /* U_HIDE_DRAFT_API */
  445. #ifndef U_HIDE_INTERNAL_API
  446. /**
  447. * Somewhat temporary constants for leap month pattern types, adequate for supporting
  448. * just leap month patterns as needed for Chinese lunar calendar.
  449. * Eventually we will add full support for different month pattern types (needed for
  450. * other calendars such as Hindu) at which point this approach will be replaced by a
  451. * more complete approach.
  452. * @internal
  453. */
  454. enum EMonthPatternType
  455. {
  456. kLeapMonthPatternFormatWide,
  457. kLeapMonthPatternFormatAbbrev,
  458. kLeapMonthPatternFormatNarrow,
  459. kLeapMonthPatternStandaloneWide,
  460. kLeapMonthPatternStandaloneAbbrev,
  461. kLeapMonthPatternStandaloneNarrow,
  462. kLeapMonthPatternNumeric,
  463. kMonthPatternsCount
  464. };
  465. /**
  466. * Somewhat temporary function for getting complete set of leap month patterns for all
  467. * contexts & widths, indexed by EMonthPatternType values. Returns NULL if calendar
  468. * does not have leap month patterns. Note, there is currently no setter for this.
  469. * Eventually we will add full support for different month pattern types (needed for
  470. * other calendars such as Hindu) at which point this approach will be replaced by a
  471. * more complete approach.
  472. * @param count Filled in with length of the array (may be 0).
  473. * @return The leap month patterns (DateFormatSymbols retains ownership).
  474. * May be NULL if there are no leap month patterns for this calendar.
  475. * @internal
  476. */
  477. const UnicodeString* getLeapMonthPatterns(int32_t& count) const;
  478. #endif /* U_HIDE_INTERNAL_API */
  479. #ifndef U_HIDE_DEPRECATED_API
  480. /**
  481. * Gets timezone strings. These strings are stored in a 2-dimensional array.
  482. * @param rowCount Output param to receive number of rows.
  483. * @param columnCount Output param to receive number of columns.
  484. * @return The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.)
  485. * @deprecated ICU 3.6
  486. */
  487. const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const;
  488. #endif /* U_HIDE_DEPRECATED_API */
  489. /**
  490. * Sets timezone strings. These strings are stored in a 2-dimensional array.
  491. * <p><b>Note:</b> SimpleDateFormat no longer use the zone strings stored in
  492. * a DateFormatSymbols. Therefore, the time zone strings set by this mthod
  493. * have no effects in an instance of SimpleDateFormat for formatting time
  494. * zones.
  495. * @param strings The timezone strings as a 2-d array to be copied. (not adopted; caller retains ownership)
  496. * @param rowCount The number of rows (count of first index).
  497. * @param columnCount The number of columns (count of second index).
  498. * @stable ICU 2.0
  499. */
  500. void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount);
  501. /**
  502. * Get the non-localized date-time pattern characters.
  503. * @return the non-localized date-time pattern characters
  504. * @stable ICU 2.0
  505. */
  506. static const UChar * U_EXPORT2 getPatternUChars(void);
  507. /**
  508. * Gets localized date-time pattern characters. For example: 'u', 't', etc.
  509. * <p>
  510. * Note: ICU no longer provides localized date-time pattern characters for a locale
  511. * starting ICU 3.8. This method returns the non-localized date-time pattern
  512. * characters unless user defined localized data is set by setLocalPatternChars.
  513. * @param result Output param which will receive the localized date-time pattern characters.
  514. * @return A reference to 'result'.
  515. * @stable ICU 2.0
  516. */
  517. UnicodeString& getLocalPatternChars(UnicodeString& result) const;
  518. /**
  519. * Sets localized date-time pattern characters. For example: 'u', 't', etc.
  520. * @param newLocalPatternChars the new localized date-time
  521. * pattern characters.
  522. * @stable ICU 2.0
  523. */
  524. void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
  525. /**
  526. * Returns the locale for this object. Two flavors are available:
  527. * valid and actual locale.
  528. * @stable ICU 2.8
  529. */
  530. Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
  531. /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API,
  532. they are needed for .h file declarations. */
  533. /**
  534. * Constants for capitalization context usage types.
  535. * @internal
  536. */
  537. enum ECapitalizationContextUsageType
  538. {
  539. #ifndef U_HIDE_INTERNAL_API
  540. kCapContextUsageOther = 0,
  541. kCapContextUsageMonthFormat, /* except narrow */
  542. kCapContextUsageMonthStandalone, /* except narrow */
  543. kCapContextUsageMonthNarrow,
  544. kCapContextUsageDayFormat, /* except narrow */
  545. kCapContextUsageDayStandalone, /* except narrow */
  546. kCapContextUsageDayNarrow,
  547. kCapContextUsageEraWide,
  548. kCapContextUsageEraAbbrev,
  549. kCapContextUsageEraNarrow,
  550. kCapContextUsageZoneLong,
  551. kCapContextUsageZoneShort,
  552. kCapContextUsageMetazoneLong,
  553. kCapContextUsageMetazoneShort,
  554. #endif /* U_HIDE_INTERNAL_API */
  555. kCapContextUsageTypeCount = 14
  556. };
  557. /**
  558. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  559. *
  560. * @stable ICU 2.2
  561. */
  562. virtual UClassID getDynamicClassID() const;
  563. /**
  564. * ICU "poor man's RTTI", returns a UClassID for this class.
  565. *
  566. * @stable ICU 2.2
  567. */
  568. static UClassID U_EXPORT2 getStaticClassID();
  569. private:
  570. friend class SimpleDateFormat;
  571. friend class DateFormatSymbolsSingleSetter; // see udat.cpp
  572. /**
  573. * Abbreviated era strings. For example: "AD" and "BC".
  574. */
  575. UnicodeString* fEras;
  576. int32_t fErasCount;
  577. /**
  578. * Era name strings. For example: "Anno Domini" and "Before Christ".
  579. */
  580. UnicodeString* fEraNames;
  581. int32_t fEraNamesCount;
  582. /**
  583. * Narrow era strings. For example: "A" and "B".
  584. */
  585. UnicodeString* fNarrowEras;
  586. int32_t fNarrowErasCount;
  587. /**
  588. * Month strings. For example: "January", "February", etc.
  589. */
  590. UnicodeString* fMonths;
  591. int32_t fMonthsCount;
  592. /**
  593. * Short month strings. For example: "Jan", "Feb", etc.
  594. */
  595. UnicodeString* fShortMonths;
  596. int32_t fShortMonthsCount;
  597. /**
  598. * Narrow month strings. For example: "J", "F", etc.
  599. */
  600. UnicodeString* fNarrowMonths;
  601. int32_t fNarrowMonthsCount;
  602. /**
  603. * Standalone Month strings. For example: "January", "February", etc.
  604. */
  605. UnicodeString* fStandaloneMonths;
  606. int32_t fStandaloneMonthsCount;
  607. /**
  608. * Standalone Short month strings. For example: "Jan", "Feb", etc.
  609. */
  610. UnicodeString* fStandaloneShortMonths;
  611. int32_t fStandaloneShortMonthsCount;
  612. /**
  613. * Standalone Narrow month strings. For example: "J", "F", etc.
  614. */
  615. UnicodeString* fStandaloneNarrowMonths;
  616. int32_t fStandaloneNarrowMonthsCount;
  617. /**
  618. * CLDR-style format wide weekday strings. For example: "Sunday", "Monday", etc.
  619. */
  620. UnicodeString* fWeekdays;
  621. int32_t fWeekdaysCount;
  622. /**
  623. * CLDR-style format abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc.
  624. */
  625. UnicodeString* fShortWeekdays;
  626. int32_t fShortWeekdaysCount;
  627. /**
  628. * CLDR-style format short weekday strings. For example: "Su", "Mo", etc.
  629. */
  630. UnicodeString* fShorterWeekdays;
  631. int32_t fShorterWeekdaysCount;
  632. /**
  633. * CLDR-style format narrow weekday strings. For example: "S", "M", etc.
  634. */
  635. UnicodeString* fNarrowWeekdays;
  636. int32_t fNarrowWeekdaysCount;
  637. /**
  638. * CLDR-style standalone wide weekday strings. For example: "Sunday", "Monday", etc.
  639. */
  640. UnicodeString* fStandaloneWeekdays;
  641. int32_t fStandaloneWeekdaysCount;
  642. /**
  643. * CLDR-style standalone abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc.
  644. */
  645. UnicodeString* fStandaloneShortWeekdays;
  646. int32_t fStandaloneShortWeekdaysCount;
  647. /**
  648. * CLDR-style standalone short weekday strings. For example: "Su", "Mo", etc.
  649. */
  650. UnicodeString* fStandaloneShorterWeekdays;
  651. int32_t fStandaloneShorterWeekdaysCount;
  652. /**
  653. * Standalone Narrow weekday strings. For example: "Sun", "Mon", etc.
  654. */
  655. UnicodeString* fStandaloneNarrowWeekdays;
  656. int32_t fStandaloneNarrowWeekdaysCount;
  657. /**
  658. * Ampm strings. For example: "AM" and "PM".
  659. */
  660. UnicodeString* fAmPms;
  661. int32_t fAmPmsCount;
  662. /**
  663. * Narrow Ampm strings. For example: "a" and "p".
  664. */
  665. UnicodeString* fNarrowAmPms;
  666. int32_t fNarrowAmPmsCount;
  667. /**
  668. * Time separator string. For example: ":".
  669. */
  670. UnicodeString fTimeSeparator;
  671. /**
  672. * Quarter strings. For example: "1st quarter", "2nd quarter", etc.
  673. */
  674. UnicodeString *fQuarters;
  675. int32_t fQuartersCount;
  676. /**
  677. * Short quarters. For example: "Q1", "Q2", etc.
  678. */
  679. UnicodeString *fShortQuarters;
  680. int32_t fShortQuartersCount;
  681. /**
  682. * Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc.
  683. */
  684. UnicodeString *fStandaloneQuarters;
  685. int32_t fStandaloneQuartersCount;
  686. /**
  687. * Standalone short quarter strings. For example: "Q1", "Q2", etc.
  688. */
  689. UnicodeString *fStandaloneShortQuarters;
  690. int32_t fStandaloneShortQuartersCount;
  691. /**
  692. * All leap month patterns, for example "{0}bis".
  693. */
  694. UnicodeString *fLeapMonthPatterns;
  695. int32_t fLeapMonthPatternsCount;
  696. /**
  697. * Cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai";
  698. * currently we only have data for format/abbreviated.
  699. * For the others, just get from format/abbreviated, ignore set.
  700. */
  701. UnicodeString *fShortYearNames;
  702. int32_t fShortYearNamesCount;
  703. /**
  704. * Cyclic zodiac names, for example "Rat", "Ox", "Tiger", etc.;
  705. * currently we only have data for format/abbreviated.
  706. * For the others, just get from format/abbreviated, ignore set.
  707. */
  708. UnicodeString *fShortZodiacNames;
  709. int32_t fShortZodiacNamesCount;
  710. /**
  711. * Localized names of time zones in this locale. This is a
  712. * two-dimensional array of strings of size n by m,
  713. * where m is at least 5 and up to 7. Each of the n rows is an
  714. * entry containing the localized names for a single TimeZone.
  715. *
  716. * Each such row contains (with i ranging from 0..n-1):
  717. *
  718. * zoneStrings[i][0] - time zone ID
  719. * example: America/Los_Angeles
  720. * zoneStrings[i][1] - long name of zone in standard time
  721. * example: Pacific Standard Time
  722. * zoneStrings[i][2] - short name of zone in standard time
  723. * example: PST
  724. * zoneStrings[i][3] - long name of zone in daylight savings time
  725. * example: Pacific Daylight Time
  726. * zoneStrings[i][4] - short name of zone in daylight savings time
  727. * example: PDT
  728. * zoneStrings[i][5] - location name of zone
  729. * example: United States (Los Angeles)
  730. * zoneStrings[i][6] - long generic name of zone
  731. * example: Pacific Time
  732. * zoneStrings[i][7] - short generic of zone
  733. * example: PT
  734. *
  735. * The zone ID is not localized; it corresponds to the ID
  736. * value associated with a system time zone object. All other entries
  737. * are localized names. If a zone does not implement daylight savings
  738. * time, the daylight savings time names are ignored.
  739. *
  740. * Note:CLDR 1.5 introduced metazone and its historical mappings.
  741. * This simple two-dimensional array is no longer sufficient to represent
  742. * localized names and its historic changes. Since ICU 3.8.1, localized
  743. * zone names extracted from ICU locale data is stored in a ZoneStringFormat
  744. * instance. But we still need to support the old way of customizing
  745. * localized zone names, so we keep this field for the purpose.
  746. */
  747. UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings
  748. UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale
  749. int32_t fZoneStringsRowCount;
  750. int32_t fZoneStringsColCount;
  751. Locale fZSFLocale; // Locale used for getting ZoneStringFormat
  752. /**
  753. * Localized date-time pattern characters. For example: use 'u' as 'y'.
  754. */
  755. UnicodeString fLocalPatternChars;
  756. /**
  757. * Capitalization transforms. For each usage type, the first array element indicates
  758. * whether to titlecase for uiListOrMenu context, the second indicates whether to
  759. * titlecase for stand-alone context.
  760. */
  761. UBool fCapitalization[kCapContextUsageTypeCount][2];
  762. private:
  763. /** valid/actual locale information
  764. * these are always ICU locales, so the length should not be a problem
  765. */
  766. char validLocale[ULOC_FULLNAME_CAPACITY];
  767. char actualLocale[ULOC_FULLNAME_CAPACITY];
  768. DateFormatSymbols(); // default constructor not implemented
  769. /**
  770. * Called by the constructors to actually load data from the resources
  771. *
  772. * @param locale The locale to get symbols for.
  773. * @param type Calendar Type (as from Calendar::getType())
  774. * @param status Input/output parameter, set to success or
  775. * failure code upon return.
  776. * @param useLastResortData determine if use last resort data
  777. */
  778. void initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData = FALSE);
  779. /**
  780. * Copy or alias an array in another object, as appropriate.
  781. *
  782. * @param dstArray the copy destination array.
  783. * @param dstCount fill in with the lenth of 'dstArray'.
  784. * @param srcArray the source array to be copied.
  785. * @param srcCount the length of items to be copied from the 'srcArray'.
  786. */
  787. static void assignArray(UnicodeString*& dstArray,
  788. int32_t& dstCount,
  789. const UnicodeString* srcArray,
  790. int32_t srcCount);
  791. /**
  792. * Return true if the given arrays' contents are equal, or if the arrays are
  793. * identical (pointers are equal).
  794. *
  795. * @param array1 one array to be compared with.
  796. * @param array2 another array to be compared with.
  797. * @param count the length of items to be copied.
  798. * @return true if the given arrays' contents are equal, or if the arrays are
  799. * identical (pointers are equal).
  800. */
  801. static UBool arrayCompare(const UnicodeString* array1,
  802. const UnicodeString* array2,
  803. int32_t count);
  804. /**
  805. * Create a copy, in fZoneStrings, of the given zone strings array. The
  806. * member variables fZoneStringsRowCount and fZoneStringsColCount should be
  807. * set already by the caller.
  808. */
  809. void createZoneStrings(const UnicodeString *const * otherStrings);
  810. /**
  811. * Delete all the storage owned by this object.
  812. */
  813. void dispose(void);
  814. /**
  815. * Copy all of the other's data to this.
  816. * @param other the object to be copied.
  817. */
  818. void copyData(const DateFormatSymbols& other);
  819. /**
  820. * Create zone strings array by locale if not yet available
  821. */
  822. void initZoneStringsArray(void);
  823. /**
  824. * Delete just the zone strings.
  825. */
  826. void disposeZoneStrings(void);
  827. /**
  828. * Returns the date format field index of the pattern character c,
  829. * or UDAT_FIELD_COUNT if c is not a pattern character.
  830. */
  831. static UDateFormatField U_EXPORT2 getPatternCharIndex(UChar c);
  832. /**
  833. * Returns TRUE if f (with its pattern character repeated count times) is a numeric field.
  834. */
  835. static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count);
  836. /**
  837. * Returns TRUE if c (repeated count times) is the pattern character for a numeric field.
  838. */
  839. static UBool U_EXPORT2 isNumericPatternChar(UChar c, int32_t count);
  840. public:
  841. #ifndef U_HIDE_INTERNAL_API
  842. /**
  843. * Gets a DateFormatSymbols by locale.
  844. * Unlike the constructors which always use gregorian calendar, this
  845. * method uses the calendar in the locale. If the locale contains no
  846. * explicit calendar, this method uses the default calendar for that
  847. * locale.
  848. * @param locale the locale.
  849. * @param status error returned here.
  850. * @return the new DateFormatSymbols which the caller owns.
  851. * @internal For ICU use only.
  852. */
  853. static DateFormatSymbols * U_EXPORT2 createForLocale(
  854. const Locale &locale, UErrorCode &status);
  855. #endif /* U_HIDE_INTERNAL_API */
  856. };
  857. U_NAMESPACE_END
  858. #endif /* #if !UCONFIG_NO_FORMATTING */
  859. #endif // _DTFMTSYM
  860. //eof