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