dtptngen.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. * Copyright (C) 2007-2016, International Business Machines Corporation and
  6. * others. All Rights Reserved.
  7. *******************************************************************************
  8. *
  9. * File DTPTNGEN.H
  10. *
  11. *******************************************************************************
  12. */
  13. #ifndef __DTPTNGEN_H__
  14. #define __DTPTNGEN_H__
  15. #include "unicode/utypes.h"
  16. #if U_SHOW_CPLUSPLUS_API
  17. #include "unicode/datefmt.h"
  18. #include "unicode/locid.h"
  19. #include "unicode/udat.h"
  20. #include "unicode/udatpg.h"
  21. #include "unicode/unistr.h"
  22. U_NAMESPACE_BEGIN
  23. /**
  24. * \file
  25. * \brief C++ API: Date/Time Pattern Generator
  26. */
  27. class CharString;
  28. class Hashtable;
  29. class FormatParser;
  30. class DateTimeMatcher;
  31. class DistanceInfo;
  32. class PatternMap;
  33. class PtnSkeleton;
  34. class SharedDateTimePatternGenerator;
  35. /**
  36. * This class provides flexible generation of date format patterns, like "yy-MM-dd".
  37. * The user can build up the generator by adding successive patterns. Once that
  38. * is done, a query can be made using a "skeleton", which is a pattern which just
  39. * includes the desired fields and lengths. The generator will return the "best fit"
  40. * pattern corresponding to that skeleton.
  41. * <p>The main method people will use is getBestPattern(String skeleton),
  42. * since normally this class is pre-built with data from a particular locale.
  43. * However, generators can be built directly from other data as well.
  44. * <p><i>Issue: may be useful to also have a function that returns the list of
  45. * fields in a pattern, in order, since we have that internally.
  46. * That would be useful for getting the UI order of field elements.</i>
  47. * @stable ICU 3.8
  48. **/
  49. class U_I18N_API DateTimePatternGenerator : public UObject {
  50. public:
  51. /**
  52. * Construct a flexible generator according to default locale.
  53. * @param status Output param set to success/failure code on exit,
  54. * which must not indicate a failure before the function call.
  55. * @stable ICU 3.8
  56. */
  57. static DateTimePatternGenerator* U_EXPORT2 createInstance(UErrorCode& status);
  58. /**
  59. * Construct a flexible generator according to data for a given locale.
  60. * @param uLocale
  61. * @param status Output param set to success/failure code on exit,
  62. * which must not indicate a failure before the function call.
  63. * @stable ICU 3.8
  64. */
  65. static DateTimePatternGenerator* U_EXPORT2 createInstance(const Locale& uLocale, UErrorCode& status);
  66. #ifndef U_HIDE_INTERNAL_API
  67. /**
  68. * For ICU use only. Skips loading the standard date/time patterns (which is done via DateFormat).
  69. *
  70. * @internal
  71. */
  72. static DateTimePatternGenerator* U_EXPORT2 createInstanceNoStdPat(const Locale& uLocale, UErrorCode& status);
  73. #endif /* U_HIDE_INTERNAL_API */
  74. /**
  75. * Create an empty generator, to be constructed with addPattern(...) etc.
  76. * @param status Output param set to success/failure code on exit,
  77. * which must not indicate a failure before the function call.
  78. * @stable ICU 3.8
  79. */
  80. static DateTimePatternGenerator* U_EXPORT2 createEmptyInstance(UErrorCode& status);
  81. /**
  82. * Destructor.
  83. * @stable ICU 3.8
  84. */
  85. virtual ~DateTimePatternGenerator();
  86. /**
  87. * Clone DateTimePatternGenerator object. Clients are responsible for
  88. * deleting the DateTimePatternGenerator object cloned.
  89. * @stable ICU 3.8
  90. */
  91. DateTimePatternGenerator* clone() const;
  92. /**
  93. * Return true if another object is semantically equal to this one.
  94. *
  95. * @param other the DateTimePatternGenerator object to be compared with.
  96. * @return true if other is semantically equal to this.
  97. * @stable ICU 3.8
  98. */
  99. bool operator==(const DateTimePatternGenerator& other) const;
  100. /**
  101. * Return true if another object is semantically unequal to this one.
  102. *
  103. * @param other the DateTimePatternGenerator object to be compared with.
  104. * @return true if other is semantically unequal to this.
  105. * @stable ICU 3.8
  106. */
  107. bool operator!=(const DateTimePatternGenerator& other) const;
  108. /**
  109. * Utility to return a unique skeleton from a given pattern. For example,
  110. * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
  111. *
  112. * @param pattern Input pattern, such as "dd/MMM"
  113. * @param status Output param set to success/failure code on exit,
  114. * which must not indicate a failure before the function call.
  115. * @return skeleton such as "MMMdd"
  116. * @stable ICU 56
  117. */
  118. static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
  119. /**
  120. * Utility to return a unique skeleton from a given pattern. For example,
  121. * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
  122. * getSkeleton() works exactly like staticGetSkeleton().
  123. * Use staticGetSkeleton() instead of getSkeleton().
  124. *
  125. * @param pattern Input pattern, such as "dd/MMM"
  126. * @param status Output param set to success/failure code on exit,
  127. * which must not indicate a failure before the function call.
  128. * @return skeleton such as "MMMdd"
  129. * @stable ICU 3.8
  130. */
  131. UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
  132. The function is commented out because it is a stable API calling a draft API.
  133. After staticGetSkeleton becomes stable, staticGetSkeleton can be used and
  134. these comments and the definition of getSkeleton in dtptngen.cpp should be removed.
  135. return staticGetSkeleton(pattern, status);
  136. }*/
  137. /**
  138. * Utility to return a unique base skeleton from a given pattern. This is
  139. * the same as the skeleton, except that differences in length are minimized
  140. * so as to only preserve the difference between string and numeric form. So
  141. * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
  142. * (notice the single d).
  143. *
  144. * @param pattern Input pattern, such as "dd/MMM"
  145. * @param status Output param set to success/failure code on exit,
  146. * which must not indicate a failure before the function call.
  147. * @return base skeleton, such as "MMMd"
  148. * @stable ICU 56
  149. */
  150. static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
  151. /**
  152. * Utility to return a unique base skeleton from a given pattern. This is
  153. * the same as the skeleton, except that differences in length are minimized
  154. * so as to only preserve the difference between string and numeric form. So
  155. * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
  156. * (notice the single d).
  157. * getBaseSkeleton() works exactly like staticGetBaseSkeleton().
  158. * Use staticGetBaseSkeleton() instead of getBaseSkeleton().
  159. *
  160. * @param pattern Input pattern, such as "dd/MMM"
  161. * @param status Output param set to success/failure code on exit,
  162. * which must not indicate a failure before the function call.
  163. * @return base skeleton, such as "MMMd"
  164. * @stable ICU 3.8
  165. */
  166. UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status); /* {
  167. The function is commented out because it is a stable API calling a draft API.
  168. After staticGetBaseSkeleton becomes stable, staticGetBaseSkeleton can be used and
  169. these comments and the definition of getBaseSkeleton in dtptngen.cpp should be removed.
  170. return staticGetBaseSkeleton(pattern, status);
  171. }*/
  172. /**
  173. * Adds a pattern to the generator. If the pattern has the same skeleton as
  174. * an existing pattern, and the override parameter is set, then the previous
  175. * value is overridden. Otherwise, the previous value is retained. In either
  176. * case, the conflicting status is set and previous vale is stored in
  177. * conflicting pattern.
  178. * <p>
  179. * Note that single-field patterns (like "MMM") are automatically added, and
  180. * don't need to be added explicitly!
  181. *
  182. * @param pattern Input pattern, such as "dd/MMM"
  183. * @param override When existing values are to be overridden use true,
  184. * otherwise use false.
  185. * @param conflictingPattern Previous pattern with the same skeleton.
  186. * @param status Output param set to success/failure code on exit,
  187. * which must not indicate a failure before the function call.
  188. * @return conflicting status. The value could be UDATPG_NO_CONFLICT,
  189. * UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.
  190. * @stable ICU 3.8
  191. */
  192. UDateTimePatternConflict addPattern(const UnicodeString& pattern,
  193. UBool override,
  194. UnicodeString& conflictingPattern,
  195. UErrorCode& status);
  196. /**
  197. * An AppendItem format is a pattern used to append a field if there is no
  198. * good match. For example, suppose that the input skeleton is "GyyyyMMMd",
  199. * and there is no matching pattern internally, but there is a pattern
  200. * matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the
  201. * G. The way these two are conjoined is by using the AppendItemFormat for G
  202. * (era). So if that value is, say "{0}, {1}" then the final resulting
  203. * pattern is "d-MM-yyyy, G".
  204. * <p>
  205. * There are actually three available variables: {0} is the pattern so far,
  206. * {1} is the element we are adding, and {2} is the name of the element.
  207. * <p>
  208. * This reflects the way that the CLDR data is organized.
  209. *
  210. * @param field such as UDATPG_ERA_FIELD.
  211. * @param value pattern, such as "{0}, {1}"
  212. * @stable ICU 3.8
  213. */
  214. void setAppendItemFormat(UDateTimePatternField field, const UnicodeString& value);
  215. /**
  216. * Getter corresponding to setAppendItemFormat. Values below 0 or at or
  217. * above UDATPG_FIELD_COUNT are illegal arguments.
  218. *
  219. * @param field such as UDATPG_ERA_FIELD.
  220. * @return append pattern for field
  221. * @stable ICU 3.8
  222. */
  223. const UnicodeString& getAppendItemFormat(UDateTimePatternField field) const;
  224. /**
  225. * Sets the names of field, eg "era" in English for ERA. These are only
  226. * used if the corresponding AppendItemFormat is used, and if it contains a
  227. * {2} variable.
  228. * <p>
  229. * This reflects the way that the CLDR data is organized.
  230. *
  231. * @param field such as UDATPG_ERA_FIELD.
  232. * @param value name of the field
  233. * @stable ICU 3.8
  234. */
  235. void setAppendItemName(UDateTimePatternField field, const UnicodeString& value);
  236. /**
  237. * Getter corresponding to setAppendItemNames. Values below 0 or at or above
  238. * UDATPG_FIELD_COUNT are illegal arguments. Note: The more general method
  239. * for getting date/time field display names is getFieldDisplayName.
  240. *
  241. * @param field such as UDATPG_ERA_FIELD.
  242. * @return name for field
  243. * @see getFieldDisplayName
  244. * @stable ICU 3.8
  245. */
  246. const UnicodeString& getAppendItemName(UDateTimePatternField field) const;
  247. /**
  248. * The general interface to get a display name for a particular date/time field,
  249. * in one of several possible display widths.
  250. *
  251. * @param field The desired UDateTimePatternField, such as UDATPG_ERA_FIELD.
  252. * @param width The desired UDateTimePGDisplayWidth, such as UDATPG_ABBREVIATED.
  253. * @return The display name for field
  254. * @stable ICU 61
  255. */
  256. UnicodeString getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const;
  257. /**
  258. * The DateTimeFormat is a message format pattern used to compose date and
  259. * time patterns. The default pattern in the root locale is "{1} {0}", where
  260. * {1} will be replaced by the date pattern and {0} will be replaced by the
  261. * time pattern; however, other locales may specify patterns such as
  262. * "{1}, {0}" or "{1} 'at' {0}", etc.
  263. * <p>
  264. * This is used when the input skeleton contains both date and time fields,
  265. * but there is not a close match among the added patterns. For example,
  266. * suppose that this object was created by adding "dd-MMM" and "hh:mm", and
  267. * its datetimeFormat is the default "{1} {0}". Then if the input skeleton
  268. * is "MMMdhmm", there is not an exact match, so the input skeleton is
  269. * broken up into two components "MMMd" and "hmm". There are close matches
  270. * for those two skeletons, so the result is put together with this pattern,
  271. * resulting in "d-MMM h:mm".
  272. *
  273. * There are four DateTimeFormats in a DateTimePatternGenerator object,
  274. * corresponding to date styles UDAT_FULL..UDAT_SHORT. This method sets
  275. * all of them to the specified pattern. To set them individually, see
  276. * setDateTimeFormat(UDateFormatStyle style, ...).
  277. *
  278. * @param dateTimeFormat
  279. * message format pattern, here {1} will be replaced by the date
  280. * pattern and {0} will be replaced by the time pattern.
  281. * @stable ICU 3.8
  282. */
  283. void setDateTimeFormat(const UnicodeString& dateTimeFormat);
  284. /**
  285. * Getter corresponding to setDateTimeFormat.
  286. *
  287. * There are four DateTimeFormats in a DateTimePatternGenerator object,
  288. * corresponding to date styles UDAT_FULL..UDAT_SHORT. This method gets
  289. * the style for UDAT_MEDIUM (the default). To get them individually, see
  290. * getDateTimeFormat(UDateFormatStyle style).
  291. *
  292. * @return DateTimeFormat.
  293. * @stable ICU 3.8
  294. */
  295. const UnicodeString& getDateTimeFormat() const;
  296. #if !UCONFIG_NO_FORMATTING
  297. /**
  298. * dateTimeFormats are message patterns used to compose combinations of date
  299. * and time patterns. There are four length styles, corresponding to the
  300. * inferred style of the date pattern; these are UDateFormatStyle values:
  301. * - UDAT_FULL (for date pattern with weekday and long month), else
  302. * - UDAT_LONG (for a date pattern with long month), else
  303. * - UDAT_MEDIUM (for a date pattern with abbreviated month), else
  304. * - UDAT_SHORT (for any other date pattern).
  305. * For details on dateTimeFormats, see
  306. * https://www.unicode.org/reports/tr35/tr35-dates.html#dateTimeFormats.
  307. * The default pattern in the root locale for all styles is "{1} {0}".
  308. *
  309. * @param style
  310. * one of DateFormat.FULL..DateFormat.SHORT. Error if out of range.
  311. * @param dateTimeFormat
  312. * the new dateTimeFormat to set for the the specified style
  313. * @param status
  314. * in/out parameter; if no failure status is already set,
  315. * it will be set according to result of the function (e.g.
  316. * U_ILLEGAL_ARGUMENT_ERROR for style out of range).
  317. * @stable ICU 71
  318. */
  319. void setDateTimeFormat(UDateFormatStyle style, const UnicodeString& dateTimeFormat,
  320. UErrorCode& status);
  321. /**
  322. * Getter corresponding to setDateTimeFormat.
  323. *
  324. * @param style
  325. * one of UDAT_FULL..UDAT_SHORT. Error if out of range.
  326. * @param status
  327. * in/out parameter; if no failure status is already set,
  328. * it will be set according to result of the function (e.g.
  329. * U_ILLEGAL_ARGUMENT_ERROR for style out of range).
  330. * @return
  331. * the current dateTimeFormat for the the specified style, or
  332. * empty string in case of error. The UnicodeString reference,
  333. * or the contents of the string, may no longer be valid if
  334. * setDateTimeFormat is called, or the DateTimePatternGenerator
  335. * object is deleted.
  336. * @stable ICU 71
  337. */
  338. const UnicodeString& getDateTimeFormat(UDateFormatStyle style,
  339. UErrorCode& status) const;
  340. #endif /* #if !UCONFIG_NO_FORMATTING */
  341. /**
  342. * Return the best pattern matching the input skeleton. It is guaranteed to
  343. * have all of the fields in the skeleton.
  344. *
  345. * @param skeleton
  346. * The skeleton is a pattern containing only the variable fields.
  347. * For example, "MMMdd" and "mmhh" are skeletons.
  348. * @param status Output param set to success/failure code on exit,
  349. * which must not indicate a failure before the function call.
  350. * @return bestPattern
  351. * The best pattern found from the given skeleton.
  352. * @stable ICU 3.8
  353. */
  354. UnicodeString getBestPattern(const UnicodeString& skeleton, UErrorCode& status);
  355. /**
  356. * Return the best pattern matching the input skeleton. It is guaranteed to
  357. * have all of the fields in the skeleton.
  358. *
  359. * @param skeleton
  360. * The skeleton is a pattern containing only the variable fields.
  361. * For example, "MMMdd" and "mmhh" are skeletons.
  362. * @param options
  363. * Options for forcing the length of specified fields in the
  364. * returned pattern to match those in the skeleton (when this
  365. * would not happen otherwise). For default behavior, use
  366. * UDATPG_MATCH_NO_OPTIONS.
  367. * @param status
  368. * Output param set to success/failure code on exit,
  369. * which must not indicate a failure before the function call.
  370. * @return bestPattern
  371. * The best pattern found from the given skeleton.
  372. * @stable ICU 4.4
  373. */
  374. UnicodeString getBestPattern(const UnicodeString& skeleton,
  375. UDateTimePatternMatchOptions options,
  376. UErrorCode& status);
  377. /**
  378. * Adjusts the field types (width and subtype) of a pattern to match what is
  379. * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
  380. * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
  381. * "dd-MMMM hh:mm". This is used internally to get the best match for the
  382. * input skeleton, but can also be used externally.
  383. *
  384. * @param pattern Input pattern
  385. * @param skeleton
  386. * The skeleton is a pattern containing only the variable fields.
  387. * For example, "MMMdd" and "mmhh" are skeletons.
  388. * @param status Output param set to success/failure code on exit,
  389. * which must not indicate a failure before the function call.
  390. * @return pattern adjusted to match the skeleton fields widths and subtypes.
  391. * @stable ICU 3.8
  392. */
  393. UnicodeString replaceFieldTypes(const UnicodeString& pattern,
  394. const UnicodeString& skeleton,
  395. UErrorCode& status);
  396. /**
  397. * Adjusts the field types (width and subtype) of a pattern to match what is
  398. * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
  399. * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
  400. * "dd-MMMM hh:mm". This is used internally to get the best match for the
  401. * input skeleton, but can also be used externally.
  402. *
  403. * @param pattern Input pattern
  404. * @param skeleton
  405. * The skeleton is a pattern containing only the variable fields.
  406. * For example, "MMMdd" and "mmhh" are skeletons.
  407. * @param options
  408. * Options controlling whether the length of specified fields in the
  409. * pattern are adjusted to match those in the skeleton (when this
  410. * would not happen otherwise). For default behavior, use
  411. * UDATPG_MATCH_NO_OPTIONS.
  412. * @param status
  413. * Output param set to success/failure code on exit,
  414. * which must not indicate a failure before the function call.
  415. * @return pattern adjusted to match the skeleton fields widths and subtypes.
  416. * @stable ICU 4.4
  417. */
  418. UnicodeString replaceFieldTypes(const UnicodeString& pattern,
  419. const UnicodeString& skeleton,
  420. UDateTimePatternMatchOptions options,
  421. UErrorCode& status);
  422. /**
  423. * Return a list of all the skeletons (in canonical form) from this class.
  424. *
  425. * Call getPatternForSkeleton() to get the corresponding pattern.
  426. *
  427. * @param status Output param set to success/failure code on exit,
  428. * which must not indicate a failure before the function call.
  429. * @return StringEnumeration with the skeletons.
  430. * The caller must delete the object.
  431. * @stable ICU 3.8
  432. */
  433. StringEnumeration* getSkeletons(UErrorCode& status) const;
  434. /**
  435. * Get the pattern corresponding to a given skeleton.
  436. * @param skeleton
  437. * @return pattern corresponding to a given skeleton.
  438. * @stable ICU 3.8
  439. */
  440. const UnicodeString& getPatternForSkeleton(const UnicodeString& skeleton) const;
  441. /**
  442. * Return a list of all the base skeletons (in canonical form) from this class.
  443. *
  444. * @param status Output param set to success/failure code on exit,
  445. * which must not indicate a failure before the function call.
  446. * @return a StringEnumeration with the base skeletons.
  447. * The caller must delete the object.
  448. * @stable ICU 3.8
  449. */
  450. StringEnumeration* getBaseSkeletons(UErrorCode& status) const;
  451. #ifndef U_HIDE_INTERNAL_API
  452. /**
  453. * Return a list of redundant patterns are those which if removed, make no
  454. * difference in the resulting getBestPattern values. This method returns a
  455. * list of them, to help check the consistency of the patterns used to build
  456. * this generator.
  457. *
  458. * @param status Output param set to success/failure code on exit,
  459. * which must not indicate a failure before the function call.
  460. * @return a StringEnumeration with the redundant pattern.
  461. * The caller must delete the object.
  462. * @internal ICU 3.8
  463. */
  464. StringEnumeration* getRedundants(UErrorCode& status);
  465. #endif /* U_HIDE_INTERNAL_API */
  466. /**
  467. * The decimal value is used in formatting fractions of seconds. If the
  468. * skeleton contains fractional seconds, then this is used with the
  469. * fractional seconds. For example, suppose that the input pattern is
  470. * "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and
  471. * the decimal string is ",". Then the resulting pattern is modified to be
  472. * "H:mm:ss,SSSS"
  473. *
  474. * @param decimal
  475. * @stable ICU 3.8
  476. */
  477. void setDecimal(const UnicodeString& decimal);
  478. /**
  479. * Getter corresponding to setDecimal.
  480. * @return UnicodeString corresponding to the decimal point
  481. * @stable ICU 3.8
  482. */
  483. const UnicodeString& getDecimal() const;
  484. #if !UCONFIG_NO_FORMATTING
  485. /**
  486. * Get the default hour cycle for a locale. Uses the locale that the
  487. * DateTimePatternGenerator was initially created with.
  488. *
  489. * Cannot be used on an empty DateTimePatternGenerator instance.
  490. *
  491. * @param status Output param set to success/failure code on exit, which
  492. * which must not indicate a failure before the function call.
  493. * Set to U_UNSUPPORTED_ERROR if used on an empty instance.
  494. * @return the default hour cycle.
  495. * @stable ICU 67
  496. */
  497. UDateFormatHourCycle getDefaultHourCycle(UErrorCode& status) const;
  498. #endif /* #if !UCONFIG_NO_FORMATTING */
  499. /**
  500. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  501. *
  502. * @stable ICU 3.8
  503. */
  504. virtual UClassID getDynamicClassID() const override;
  505. /**
  506. * ICU "poor man's RTTI", returns a UClassID for this class.
  507. *
  508. * @stable ICU 3.8
  509. */
  510. static UClassID U_EXPORT2 getStaticClassID();
  511. private:
  512. /**
  513. * Constructor.
  514. */
  515. DateTimePatternGenerator(UErrorCode & status);
  516. /**
  517. * Constructor.
  518. */
  519. DateTimePatternGenerator(const Locale& locale, UErrorCode & status, UBool skipStdPatterns = false);
  520. /**
  521. * Copy constructor.
  522. * @param other DateTimePatternGenerator to copy
  523. */
  524. DateTimePatternGenerator(const DateTimePatternGenerator& other);
  525. /**
  526. * Default assignment operator.
  527. * @param other DateTimePatternGenerator to copy
  528. */
  529. DateTimePatternGenerator& operator=(const DateTimePatternGenerator& other);
  530. static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
  531. Locale pLocale; // pattern locale
  532. FormatParser *fp;
  533. DateTimeMatcher* dtMatcher;
  534. DistanceInfo *distanceInfo;
  535. PatternMap *patternMap;
  536. UnicodeString appendItemFormats[UDATPG_FIELD_COUNT];
  537. UnicodeString fieldDisplayNames[UDATPG_FIELD_COUNT][UDATPG_WIDTH_COUNT];
  538. UnicodeString dateTimeFormat[4];
  539. UnicodeString decimal;
  540. DateTimeMatcher *skipMatcher;
  541. Hashtable *fAvailableFormatKeyHash;
  542. UnicodeString emptyString;
  543. char16_t fDefaultHourFormatChar;
  544. int32_t fAllowedHourFormats[7]; // Actually an array of AllowedHourFormat enum type, ending with UNKNOWN.
  545. // Internal error code used for recording/reporting errors that occur during methods that do not
  546. // have a UErrorCode parameter. For example: the Copy Constructor, or the ::clone() method.
  547. // When this is set to an error the object is in an invalid state.
  548. UErrorCode internalErrorCode;
  549. /* internal flags masks for adjustFieldTypes etc. */
  550. enum {
  551. kDTPGNoFlags = 0,
  552. kDTPGFixFractionalSeconds = 1,
  553. kDTPGSkeletonUsesCapJ = 2
  554. // with #13183, no longer need flags for b, B
  555. };
  556. void initData(const Locale &locale, UErrorCode &status, UBool skipStdPatterns = false);
  557. void addCanonicalItems(UErrorCode &status);
  558. void addICUPatterns(const Locale& locale, UErrorCode& status);
  559. void hackTimes(const UnicodeString& hackPattern, UErrorCode& status);
  560. void getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err);
  561. void consumeShortTimePattern(const UnicodeString& shortTimePattern, UErrorCode& status);
  562. void addCLDRData(const Locale& locale, UErrorCode& status);
  563. UDateTimePatternConflict addPatternWithSkeleton(const UnicodeString& pattern, const UnicodeString * skeletonToUse, UBool override, UnicodeString& conflictingPattern, UErrorCode& status);
  564. void initHashtable(UErrorCode& status);
  565. void setDateTimeFromCalendar(const Locale& locale, UErrorCode& status);
  566. void setDecimalSymbols(const Locale& locale, UErrorCode& status);
  567. UDateTimePatternField getAppendFormatNumber(const char* field) const;
  568. // Note for the next 3: UDateTimePGDisplayWidth is now stable ICU 61
  569. UDateTimePatternField getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const;
  570. void setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value);
  571. UnicodeString& getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width);
  572. void getAppendName(UDateTimePatternField field, UnicodeString& value);
  573. UnicodeString mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status);
  574. const UnicodeString* getBestRaw(DateTimeMatcher& source, int32_t includeMask, DistanceInfo* missingFields, UErrorCode& status, const PtnSkeleton** specifiedSkeletonPtr = nullptr);
  575. UnicodeString adjustFieldTypes(const UnicodeString& pattern, const PtnSkeleton* specifiedSkeleton, int32_t flags, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
  576. UnicodeString getBestAppending(int32_t missingFields, int32_t flags, UErrorCode& status, UDateTimePatternMatchOptions options = UDATPG_MATCH_NO_OPTIONS);
  577. int32_t getTopBitNumber(int32_t foundMask) const;
  578. void setAvailableFormat(const UnicodeString &key, UErrorCode& status);
  579. UBool isAvailableFormatSet(const UnicodeString &key) const;
  580. void copyHashtable(Hashtable *other, UErrorCode &status);
  581. UBool isCanonicalItem(const UnicodeString& item) const;
  582. static void U_CALLCONV loadAllowedHourFormatsData(UErrorCode &status);
  583. void getAllowedHourFormats(const Locale &locale, UErrorCode &status);
  584. struct U_HIDDEN AppendItemFormatsSink;
  585. struct U_HIDDEN AppendItemNamesSink;
  586. struct U_HIDDEN AvailableFormatsSink;
  587. } ;// end class DateTimePatternGenerator
  588. U_NAMESPACE_END
  589. #endif /* U_SHOW_CPLUSPLUS_API */
  590. #endif