udatpg.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. *
  6. * Copyright (C) 2007-2015, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. * file name: udatpg.h
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 2007jul30
  16. * created by: Markus W. Scherer
  17. */
  18. #ifndef __UDATPG_H__
  19. #define __UDATPG_H__
  20. #include "unicode/utypes.h"
  21. #include "unicode/udat.h"
  22. #include "unicode/uenum.h"
  23. #include "unicode/localpointer.h"
  24. /**
  25. * \file
  26. * \brief C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
  27. *
  28. * UDateTimePatternGenerator provides flexible generation of date format patterns,
  29. * like "yy-MM-dd". The user can build up the generator by adding successive
  30. * patterns. Once that is done, a query can be made using a "skeleton", which is
  31. * a pattern which just includes the desired fields and lengths. The generator
  32. * will return the "best fit" pattern corresponding to that skeleton.
  33. * <p>The main method people will use is udatpg_getBestPattern, since normally
  34. * UDateTimePatternGenerator is pre-built with data from a particular locale.
  35. * However, generators can be built directly from other data as well.
  36. * <p><i>Issue: may be useful to also have a function that returns the list of
  37. * fields in a pattern, in order, since we have that internally.
  38. * That would be useful for getting the UI order of field elements.</i>
  39. */
  40. /**
  41. * Opaque type for a date/time pattern generator object.
  42. * @stable ICU 3.8
  43. */
  44. typedef void *UDateTimePatternGenerator;
  45. /**
  46. * Field number constants for udatpg_getAppendItemFormats() and similar functions.
  47. * These constants are separate from UDateFormatField despite semantic overlap
  48. * because some fields are merged for the date/time pattern generator.
  49. * @stable ICU 3.8
  50. */
  51. typedef enum UDateTimePatternField {
  52. /** @stable ICU 3.8 */
  53. UDATPG_ERA_FIELD,
  54. /** @stable ICU 3.8 */
  55. UDATPG_YEAR_FIELD,
  56. /** @stable ICU 3.8 */
  57. UDATPG_QUARTER_FIELD,
  58. /** @stable ICU 3.8 */
  59. UDATPG_MONTH_FIELD,
  60. /** @stable ICU 3.8 */
  61. UDATPG_WEEK_OF_YEAR_FIELD,
  62. /** @stable ICU 3.8 */
  63. UDATPG_WEEK_OF_MONTH_FIELD,
  64. /** @stable ICU 3.8 */
  65. UDATPG_WEEKDAY_FIELD,
  66. /** @stable ICU 3.8 */
  67. UDATPG_DAY_OF_YEAR_FIELD,
  68. /** @stable ICU 3.8 */
  69. UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD,
  70. /** @stable ICU 3.8 */
  71. UDATPG_DAY_FIELD,
  72. /** @stable ICU 3.8 */
  73. UDATPG_DAYPERIOD_FIELD,
  74. /** @stable ICU 3.8 */
  75. UDATPG_HOUR_FIELD,
  76. /** @stable ICU 3.8 */
  77. UDATPG_MINUTE_FIELD,
  78. /** @stable ICU 3.8 */
  79. UDATPG_SECOND_FIELD,
  80. /** @stable ICU 3.8 */
  81. UDATPG_FRACTIONAL_SECOND_FIELD,
  82. /** @stable ICU 3.8 */
  83. UDATPG_ZONE_FIELD,
  84. /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
  85. * it is needed for layout of DateTimePatternGenerator object. */
  86. #ifndef U_FORCE_HIDE_DEPRECATED_API
  87. /**
  88. * One more than the highest normal UDateTimePatternField value.
  89. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  90. */
  91. UDATPG_FIELD_COUNT
  92. #endif // U_FORCE_HIDE_DEPRECATED_API
  93. } UDateTimePatternField;
  94. /**
  95. * Field display name width constants for udatpg_getFieldDisplayName().
  96. * @stable ICU 61
  97. */
  98. typedef enum UDateTimePGDisplayWidth {
  99. /** @stable ICU 61 */
  100. UDATPG_WIDE,
  101. /** @stable ICU 61 */
  102. UDATPG_ABBREVIATED,
  103. /** @stable ICU 61 */
  104. UDATPG_NARROW
  105. } UDateTimePGDisplayWidth;
  106. /**
  107. * Masks to control forcing the length of specified fields in the returned
  108. * pattern to match those in the skeleton (when this would not happen
  109. * otherwise). These may be combined to force the length of multiple fields.
  110. * Used with udatpg_getBestPatternWithOptions, udatpg_replaceFieldTypesWithOptions.
  111. * @stable ICU 4.4
  112. */
  113. typedef enum UDateTimePatternMatchOptions {
  114. /** @stable ICU 4.4 */
  115. UDATPG_MATCH_NO_OPTIONS = 0,
  116. /** @stable ICU 4.4 */
  117. UDATPG_MATCH_HOUR_FIELD_LENGTH = 1 << UDATPG_HOUR_FIELD,
  118. #ifndef U_HIDE_INTERNAL_API
  119. /** @internal ICU 4.4 */
  120. UDATPG_MATCH_MINUTE_FIELD_LENGTH = 1 << UDATPG_MINUTE_FIELD,
  121. /** @internal ICU 4.4 */
  122. UDATPG_MATCH_SECOND_FIELD_LENGTH = 1 << UDATPG_SECOND_FIELD,
  123. #endif /* U_HIDE_INTERNAL_API */
  124. /** @stable ICU 4.4 */
  125. UDATPG_MATCH_ALL_FIELDS_LENGTH = (1 << UDATPG_FIELD_COUNT) - 1
  126. } UDateTimePatternMatchOptions;
  127. /**
  128. * Status return values from udatpg_addPattern().
  129. * @stable ICU 3.8
  130. */
  131. typedef enum UDateTimePatternConflict {
  132. /** @stable ICU 3.8 */
  133. UDATPG_NO_CONFLICT,
  134. /** @stable ICU 3.8 */
  135. UDATPG_BASE_CONFLICT,
  136. /** @stable ICU 3.8 */
  137. UDATPG_CONFLICT,
  138. #ifndef U_HIDE_DEPRECATED_API
  139. /**
  140. * One more than the highest normal UDateTimePatternConflict value.
  141. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  142. */
  143. UDATPG_CONFLICT_COUNT
  144. #endif // U_HIDE_DEPRECATED_API
  145. } UDateTimePatternConflict;
  146. /**
  147. * Open a generator according to a given locale.
  148. * @param locale
  149. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  150. * failure before the function call.
  151. * @return a pointer to UDateTimePatternGenerator.
  152. * @stable ICU 3.8
  153. */
  154. U_STABLE UDateTimePatternGenerator * U_EXPORT2
  155. udatpg_open(const char *locale, UErrorCode *pErrorCode);
  156. /**
  157. * Open an empty generator, to be constructed with udatpg_addPattern(...) etc.
  158. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  159. * failure before the function call.
  160. * @return a pointer to UDateTimePatternGenerator.
  161. * @stable ICU 3.8
  162. */
  163. U_STABLE UDateTimePatternGenerator * U_EXPORT2
  164. udatpg_openEmpty(UErrorCode *pErrorCode);
  165. /**
  166. * Close a generator.
  167. * @param dtpg a pointer to UDateTimePatternGenerator.
  168. * @stable ICU 3.8
  169. */
  170. U_STABLE void U_EXPORT2
  171. udatpg_close(UDateTimePatternGenerator *dtpg);
  172. #if U_SHOW_CPLUSPLUS_API
  173. U_NAMESPACE_BEGIN
  174. /**
  175. * \class LocalUDateTimePatternGeneratorPointer
  176. * "Smart pointer" class, closes a UDateTimePatternGenerator via udatpg_close().
  177. * For most methods see the LocalPointerBase base class.
  178. *
  179. * @see LocalPointerBase
  180. * @see LocalPointer
  181. * @stable ICU 4.4
  182. */
  183. U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateTimePatternGeneratorPointer, UDateTimePatternGenerator, udatpg_close);
  184. U_NAMESPACE_END
  185. #endif
  186. /**
  187. * Create a copy pf a generator.
  188. * @param dtpg a pointer to UDateTimePatternGenerator to be copied.
  189. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  190. * failure before the function call.
  191. * @return a pointer to a new UDateTimePatternGenerator.
  192. * @stable ICU 3.8
  193. */
  194. U_STABLE UDateTimePatternGenerator * U_EXPORT2
  195. udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
  196. /**
  197. * Get the best pattern matching the input skeleton. It is guaranteed to
  198. * have all of the fields in the skeleton.
  199. *
  200. * Note that this function uses a non-const UDateTimePatternGenerator:
  201. * It uses a stateful pattern parser which is set up for each generator object,
  202. * rather than creating one for each function call.
  203. * Consecutive calls to this function do not affect each other,
  204. * but this function cannot be used concurrently on a single generator object.
  205. *
  206. * @param dtpg a pointer to UDateTimePatternGenerator.
  207. * @param skeleton
  208. * The skeleton is a pattern containing only the variable fields.
  209. * For example, "MMMdd" and "mmhh" are skeletons.
  210. * @param length the length of skeleton
  211. * @param bestPattern
  212. * The best pattern found from the given skeleton.
  213. * @param capacity the capacity of bestPattern.
  214. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  215. * failure before the function call.
  216. * @return the length of bestPattern.
  217. * @stable ICU 3.8
  218. */
  219. U_STABLE int32_t U_EXPORT2
  220. udatpg_getBestPattern(UDateTimePatternGenerator *dtpg,
  221. const UChar *skeleton, int32_t length,
  222. UChar *bestPattern, int32_t capacity,
  223. UErrorCode *pErrorCode);
  224. /**
  225. * Get the best pattern matching the input skeleton. It is guaranteed to
  226. * have all of the fields in the skeleton.
  227. *
  228. * Note that this function uses a non-const UDateTimePatternGenerator:
  229. * It uses a stateful pattern parser which is set up for each generator object,
  230. * rather than creating one for each function call.
  231. * Consecutive calls to this function do not affect each other,
  232. * but this function cannot be used concurrently on a single generator object.
  233. *
  234. * @param dtpg a pointer to UDateTimePatternGenerator.
  235. * @param skeleton
  236. * The skeleton is a pattern containing only the variable fields.
  237. * For example, "MMMdd" and "mmhh" are skeletons.
  238. * @param length the length of skeleton
  239. * @param options
  240. * Options for forcing the length of specified fields in the
  241. * returned pattern to match those in the skeleton (when this
  242. * would not happen otherwise). For default behavior, use
  243. * UDATPG_MATCH_NO_OPTIONS.
  244. * @param bestPattern
  245. * The best pattern found from the given skeleton.
  246. * @param capacity
  247. * the capacity of bestPattern.
  248. * @param pErrorCode
  249. * a pointer to the UErrorCode which must not indicate a
  250. * failure before the function call.
  251. * @return the length of bestPattern.
  252. * @stable ICU 4.4
  253. */
  254. U_STABLE int32_t U_EXPORT2
  255. udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
  256. const UChar *skeleton, int32_t length,
  257. UDateTimePatternMatchOptions options,
  258. UChar *bestPattern, int32_t capacity,
  259. UErrorCode *pErrorCode);
  260. /**
  261. * Get a unique skeleton from a given pattern. For example,
  262. * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
  263. *
  264. * Note that this function uses a non-const UDateTimePatternGenerator:
  265. * It uses a stateful pattern parser which is set up for each generator object,
  266. * rather than creating one for each function call.
  267. * Consecutive calls to this function do not affect each other,
  268. * but this function cannot be used concurrently on a single generator object.
  269. *
  270. * @param unusedDtpg a pointer to UDateTimePatternGenerator.
  271. * This parameter is no longer used. Callers may pass NULL.
  272. * @param pattern input pattern, such as "dd/MMM".
  273. * @param length the length of pattern.
  274. * @param skeleton such as "MMMdd"
  275. * @param capacity the capacity of skeleton.
  276. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  277. * failure before the function call.
  278. * @return the length of skeleton.
  279. * @stable ICU 3.8
  280. */
  281. U_STABLE int32_t U_EXPORT2
  282. udatpg_getSkeleton(UDateTimePatternGenerator *unusedDtpg,
  283. const UChar *pattern, int32_t length,
  284. UChar *skeleton, int32_t capacity,
  285. UErrorCode *pErrorCode);
  286. /**
  287. * Get a unique base skeleton from a given pattern. This is the same
  288. * as the skeleton, except that differences in length are minimized so
  289. * as to only preserve the difference between string and numeric form. So
  290. * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
  291. * (notice the single d).
  292. *
  293. * Note that this function uses a non-const UDateTimePatternGenerator:
  294. * It uses a stateful pattern parser which is set up for each generator object,
  295. * rather than creating one for each function call.
  296. * Consecutive calls to this function do not affect each other,
  297. * but this function cannot be used concurrently on a single generator object.
  298. *
  299. * @param unusedDtpg a pointer to UDateTimePatternGenerator.
  300. * This parameter is no longer used. Callers may pass NULL.
  301. * @param pattern input pattern, such as "dd/MMM".
  302. * @param length the length of pattern.
  303. * @param baseSkeleton such as "Md"
  304. * @param capacity the capacity of base skeleton.
  305. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  306. * failure before the function call.
  307. * @return the length of baseSkeleton.
  308. * @stable ICU 3.8
  309. */
  310. U_STABLE int32_t U_EXPORT2
  311. udatpg_getBaseSkeleton(UDateTimePatternGenerator *unusedDtpg,
  312. const UChar *pattern, int32_t length,
  313. UChar *baseSkeleton, int32_t capacity,
  314. UErrorCode *pErrorCode);
  315. /**
  316. * Adds a pattern to the generator. If the pattern has the same skeleton as
  317. * an existing pattern, and the override parameter is set, then the previous
  318. * value is overriden. Otherwise, the previous value is retained. In either
  319. * case, the conflicting status is set and previous vale is stored in
  320. * conflicting pattern.
  321. * <p>
  322. * Note that single-field patterns (like "MMM") are automatically added, and
  323. * don't need to be added explicitly!
  324. *
  325. * @param dtpg a pointer to UDateTimePatternGenerator.
  326. * @param pattern input pattern, such as "dd/MMM"
  327. * @param patternLength the length of pattern.
  328. * @param override When existing values are to be overridden use true,
  329. * otherwise use false.
  330. * @param conflictingPattern Previous pattern with the same skeleton.
  331. * @param capacity the capacity of conflictingPattern.
  332. * @param pLength a pointer to the length of conflictingPattern.
  333. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  334. * failure before the function call.
  335. * @return conflicting status. The value could be UDATPG_NO_CONFLICT,
  336. * UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.
  337. * @stable ICU 3.8
  338. */
  339. U_STABLE UDateTimePatternConflict U_EXPORT2
  340. udatpg_addPattern(UDateTimePatternGenerator *dtpg,
  341. const UChar *pattern, int32_t patternLength,
  342. UBool override,
  343. UChar *conflictingPattern, int32_t capacity, int32_t *pLength,
  344. UErrorCode *pErrorCode);
  345. /**
  346. * An AppendItem format is a pattern used to append a field if there is no
  347. * good match. For example, suppose that the input skeleton is "GyyyyMMMd",
  348. * and there is no matching pattern internally, but there is a pattern
  349. * matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the
  350. * G. The way these two are conjoined is by using the AppendItemFormat for G
  351. * (era). So if that value is, say "{0}, {1}" then the final resulting
  352. * pattern is "d-MM-yyyy, G".
  353. * <p>
  354. * There are actually three available variables: {0} is the pattern so far,
  355. * {1} is the element we are adding, and {2} is the name of the element.
  356. * <p>
  357. * This reflects the way that the CLDR data is organized.
  358. *
  359. * @param dtpg a pointer to UDateTimePatternGenerator.
  360. * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
  361. * @param value pattern, such as "{0}, {1}"
  362. * @param length the length of value.
  363. * @stable ICU 3.8
  364. */
  365. U_STABLE void U_EXPORT2
  366. udatpg_setAppendItemFormat(UDateTimePatternGenerator *dtpg,
  367. UDateTimePatternField field,
  368. const UChar *value, int32_t length);
  369. /**
  370. * Getter corresponding to setAppendItemFormat. Values below 0 or at or
  371. * above UDATPG_FIELD_COUNT are illegal arguments.
  372. *
  373. * @param dtpg A pointer to UDateTimePatternGenerator.
  374. * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
  375. * @param pLength A pointer that will receive the length of appendItemFormat.
  376. * @return appendItemFormat for field.
  377. * @stable ICU 3.8
  378. */
  379. U_STABLE const UChar * U_EXPORT2
  380. udatpg_getAppendItemFormat(const UDateTimePatternGenerator *dtpg,
  381. UDateTimePatternField field,
  382. int32_t *pLength);
  383. /**
  384. * Set the name of field, eg "era" in English for ERA. These are only
  385. * used if the corresponding AppendItemFormat is used, and if it contains a
  386. * {2} variable.
  387. * <p>
  388. * This reflects the way that the CLDR data is organized.
  389. *
  390. * @param dtpg a pointer to UDateTimePatternGenerator.
  391. * @param field UDateTimePatternField
  392. * @param value name for the field.
  393. * @param length the length of value.
  394. * @stable ICU 3.8
  395. */
  396. U_STABLE void U_EXPORT2
  397. udatpg_setAppendItemName(UDateTimePatternGenerator *dtpg,
  398. UDateTimePatternField field,
  399. const UChar *value, int32_t length);
  400. /**
  401. * Getter corresponding to setAppendItemNames. Values below 0 or at or above
  402. * UDATPG_FIELD_COUNT are illegal arguments. Note: The more general function
  403. * for getting date/time field display names is udatpg_getFieldDisplayName.
  404. *
  405. * @param dtpg a pointer to UDateTimePatternGenerator.
  406. * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
  407. * @param pLength A pointer that will receive the length of the name for field.
  408. * @return name for field
  409. * @see udatpg_getFieldDisplayName
  410. * @stable ICU 3.8
  411. */
  412. U_STABLE const UChar * U_EXPORT2
  413. udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg,
  414. UDateTimePatternField field,
  415. int32_t *pLength);
  416. /**
  417. * The general interface to get a display name for a particular date/time field,
  418. * in one of several possible display widths.
  419. *
  420. * @param dtpg
  421. * A pointer to the UDateTimePatternGenerator object with the localized
  422. * display names.
  423. * @param field
  424. * The desired UDateTimePatternField, such as UDATPG_ERA_FIELD.
  425. * @param width
  426. * The desired UDateTimePGDisplayWidth, such as UDATPG_ABBREVIATED.
  427. * @param fieldName
  428. * A pointer to a buffer to receive the NULL-terminated display name. If the name
  429. * fits into fieldName but cannot be NULL-terminated (length == capacity) then
  430. * the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the name doesn't
  431. * fit into fieldName then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  432. * @param capacity
  433. * The size of fieldName (in UChars).
  434. * @param pErrorCode
  435. * A pointer to a UErrorCode to receive any errors
  436. * @return
  437. * The full length of the name; if greater than capacity, fieldName contains a
  438. * truncated result.
  439. * @stable ICU 61
  440. */
  441. U_STABLE int32_t U_EXPORT2
  442. udatpg_getFieldDisplayName(const UDateTimePatternGenerator *dtpg,
  443. UDateTimePatternField field,
  444. UDateTimePGDisplayWidth width,
  445. UChar *fieldName, int32_t capacity,
  446. UErrorCode *pErrorCode);
  447. /**
  448. * The DateTimeFormat is a message format pattern used to compose date and
  449. * time patterns. The default pattern in the root locale is "{1} {0}", where
  450. * {1} will be replaced by the date pattern and {0} will be replaced by the
  451. * time pattern; however, other locales may specify patterns such as
  452. * "{1}, {0}" or "{1} 'at' {0}", etc.
  453. * <p>
  454. * This is used when the input skeleton contains both date and time fields,
  455. * but there is not a close match among the added patterns. For example,
  456. * suppose that this object was created by adding "dd-MMM" and "hh:mm", and
  457. * its DateTimeFormat is the default "{1} {0}". Then if the input skeleton
  458. * is "MMMdhmm", there is not an exact match, so the input skeleton is
  459. * broken up into two components "MMMd" and "hmm". There are close matches
  460. * for those two skeletons, so the result is put together with this pattern,
  461. * resulting in "d-MMM h:mm".
  462. *
  463. * @param dtpg a pointer to UDateTimePatternGenerator.
  464. * @param dtFormat
  465. * message format pattern, here {1} will be replaced by the date
  466. * pattern and {0} will be replaced by the time pattern.
  467. * @param length the length of dtFormat.
  468. * @stable ICU 3.8
  469. */
  470. U_STABLE void U_EXPORT2
  471. udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg,
  472. const UChar *dtFormat, int32_t length);
  473. /**
  474. * Getter corresponding to setDateTimeFormat.
  475. * @param dtpg a pointer to UDateTimePatternGenerator.
  476. * @param pLength A pointer that will receive the length of the format
  477. * @return dateTimeFormat.
  478. * @stable ICU 3.8
  479. */
  480. U_STABLE const UChar * U_EXPORT2
  481. udatpg_getDateTimeFormat(const UDateTimePatternGenerator *dtpg,
  482. int32_t *pLength);
  483. /**
  484. * The decimal value is used in formatting fractions of seconds. If the
  485. * skeleton contains fractional seconds, then this is used with the
  486. * fractional seconds. For example, suppose that the input pattern is
  487. * "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and
  488. * the decimal string is ",". Then the resulting pattern is modified to be
  489. * "H:mm:ss,SSSS"
  490. *
  491. * @param dtpg a pointer to UDateTimePatternGenerator.
  492. * @param decimal
  493. * @param length the length of decimal.
  494. * @stable ICU 3.8
  495. */
  496. U_STABLE void U_EXPORT2
  497. udatpg_setDecimal(UDateTimePatternGenerator *dtpg,
  498. const UChar *decimal, int32_t length);
  499. /**
  500. * Getter corresponding to setDecimal.
  501. *
  502. * @param dtpg a pointer to UDateTimePatternGenerator.
  503. * @param pLength A pointer that will receive the length of the decimal string.
  504. * @return corresponding to the decimal point.
  505. * @stable ICU 3.8
  506. */
  507. U_STABLE const UChar * U_EXPORT2
  508. udatpg_getDecimal(const UDateTimePatternGenerator *dtpg,
  509. int32_t *pLength);
  510. /**
  511. * Adjusts the field types (width and subtype) of a pattern to match what is
  512. * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
  513. * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
  514. * "dd-MMMM hh:mm". This is used internally to get the best match for the
  515. * input skeleton, but can also be used externally.
  516. *
  517. * Note that this function uses a non-const UDateTimePatternGenerator:
  518. * It uses a stateful pattern parser which is set up for each generator object,
  519. * rather than creating one for each function call.
  520. * Consecutive calls to this function do not affect each other,
  521. * but this function cannot be used concurrently on a single generator object.
  522. *
  523. * @param dtpg a pointer to UDateTimePatternGenerator.
  524. * @param pattern Input pattern
  525. * @param patternLength the length of input pattern.
  526. * @param skeleton
  527. * @param skeletonLength the length of input skeleton.
  528. * @param dest pattern adjusted to match the skeleton fields widths and subtypes.
  529. * @param destCapacity the capacity of dest.
  530. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  531. * failure before the function call.
  532. * @return the length of dest.
  533. * @stable ICU 3.8
  534. */
  535. U_STABLE int32_t U_EXPORT2
  536. udatpg_replaceFieldTypes(UDateTimePatternGenerator *dtpg,
  537. const UChar *pattern, int32_t patternLength,
  538. const UChar *skeleton, int32_t skeletonLength,
  539. UChar *dest, int32_t destCapacity,
  540. UErrorCode *pErrorCode);
  541. /**
  542. * Adjusts the field types (width and subtype) of a pattern to match what is
  543. * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
  544. * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
  545. * "dd-MMMM hh:mm". This is used internally to get the best match for the
  546. * input skeleton, but can also be used externally.
  547. *
  548. * Note that this function uses a non-const UDateTimePatternGenerator:
  549. * It uses a stateful pattern parser which is set up for each generator object,
  550. * rather than creating one for each function call.
  551. * Consecutive calls to this function do not affect each other,
  552. * but this function cannot be used concurrently on a single generator object.
  553. *
  554. * @param dtpg a pointer to UDateTimePatternGenerator.
  555. * @param pattern Input pattern
  556. * @param patternLength the length of input pattern.
  557. * @param skeleton
  558. * @param skeletonLength the length of input skeleton.
  559. * @param options
  560. * Options controlling whether the length of specified fields in the
  561. * pattern are adjusted to match those in the skeleton (when this
  562. * would not happen otherwise). For default behavior, use
  563. * UDATPG_MATCH_NO_OPTIONS.
  564. * @param dest pattern adjusted to match the skeleton fields widths and subtypes.
  565. * @param destCapacity the capacity of dest.
  566. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  567. * failure before the function call.
  568. * @return the length of dest.
  569. * @stable ICU 4.4
  570. */
  571. U_STABLE int32_t U_EXPORT2
  572. udatpg_replaceFieldTypesWithOptions(UDateTimePatternGenerator *dtpg,
  573. const UChar *pattern, int32_t patternLength,
  574. const UChar *skeleton, int32_t skeletonLength,
  575. UDateTimePatternMatchOptions options,
  576. UChar *dest, int32_t destCapacity,
  577. UErrorCode *pErrorCode);
  578. /**
  579. * Return a UEnumeration list of all the skeletons in canonical form.
  580. * Call udatpg_getPatternForSkeleton() to get the corresponding pattern.
  581. *
  582. * @param dtpg a pointer to UDateTimePatternGenerator.
  583. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  584. * failure before the function call
  585. * @return a UEnumeration list of all the skeletons
  586. * The caller must close the object.
  587. * @stable ICU 3.8
  588. */
  589. U_STABLE UEnumeration * U_EXPORT2
  590. udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
  591. /**
  592. * Return a UEnumeration list of all the base skeletons in canonical form.
  593. *
  594. * @param dtpg a pointer to UDateTimePatternGenerator.
  595. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  596. * failure before the function call.
  597. * @return a UEnumeration list of all the base skeletons
  598. * The caller must close the object.
  599. * @stable ICU 3.8
  600. */
  601. U_STABLE UEnumeration * U_EXPORT2
  602. udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
  603. /**
  604. * Get the pattern corresponding to a given skeleton.
  605. *
  606. * @param dtpg a pointer to UDateTimePatternGenerator.
  607. * @param skeleton
  608. * @param skeletonLength pointer to the length of skeleton.
  609. * @param pLength pointer to the length of return pattern.
  610. * @return pattern corresponding to a given skeleton.
  611. * @stable ICU 3.8
  612. */
  613. U_STABLE const UChar * U_EXPORT2
  614. udatpg_getPatternForSkeleton(const UDateTimePatternGenerator *dtpg,
  615. const UChar *skeleton, int32_t skeletonLength,
  616. int32_t *pLength);
  617. #if !UCONFIG_NO_FORMATTING
  618. #ifndef U_HIDE_DRAFT_API
  619. /**
  620. * Return the default hour cycle for a locale. Uses the locale that the
  621. * UDateTimePatternGenerator was initially created with.
  622. *
  623. * Cannot be used on an empty UDateTimePatternGenerator instance.
  624. *
  625. * @param dtpg a pointer to UDateTimePatternGenerator.
  626. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  627. * failure before the function call. Set to U_UNSUPPORTED_ERROR
  628. * if used on an empty instance.
  629. * @return the default hour cycle.
  630. * @draft ICU 67
  631. */
  632. U_DRAFT UDateFormatHourCycle U_EXPORT2
  633. udatpg_getDefaultHourCycle(const UDateTimePatternGenerator *dtpg, UErrorCode* pErrorCode);
  634. #endif /* U_HIDE_DRAFT_API */
  635. #endif /* #if !UCONFIG_NO_FORMATTING */
  636. #endif