annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/dtptngen.h @ 69:33d812a61356

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