dtfmtsym.h 38 KB

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