Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * Copyright (C) 2008-2011,2013, International Business Machines Corporation and |
michael@0 | 4 | * others. All Rights Reserved. |
michael@0 | 5 | ******************************************************************************* |
michael@0 | 6 | * |
michael@0 | 7 | * File DTITVINF.H |
michael@0 | 8 | * |
michael@0 | 9 | ******************************************************************************* |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | #ifndef __DTITVINF_H__ |
michael@0 | 13 | #define __DTITVINF_H__ |
michael@0 | 14 | |
michael@0 | 15 | #include "unicode/utypes.h" |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * \file |
michael@0 | 19 | * \brief C++ API: Date/Time interval patterns for formatting date/time interval |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 23 | |
michael@0 | 24 | #include "unicode/udat.h" |
michael@0 | 25 | #include "unicode/locid.h" |
michael@0 | 26 | #include "unicode/ucal.h" |
michael@0 | 27 | #include "unicode/dtptngen.h" |
michael@0 | 28 | |
michael@0 | 29 | U_NAMESPACE_BEGIN |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * DateIntervalInfo is a public class for encapsulating localizable |
michael@0 | 33 | * date time interval patterns. It is used by DateIntervalFormat. |
michael@0 | 34 | * |
michael@0 | 35 | * <P> |
michael@0 | 36 | * For most users, ordinary use of DateIntervalFormat does not need to create |
michael@0 | 37 | * DateIntervalInfo object directly. |
michael@0 | 38 | * DateIntervalFormat will take care of it when creating a date interval |
michael@0 | 39 | * formatter when user pass in skeleton and locale. |
michael@0 | 40 | * |
michael@0 | 41 | * <P> |
michael@0 | 42 | * For power users, who want to create their own date interval patterns, |
michael@0 | 43 | * or want to re-set date interval patterns, they could do so by |
michael@0 | 44 | * directly creating DateIntervalInfo and manupulating it. |
michael@0 | 45 | * |
michael@0 | 46 | * <P> |
michael@0 | 47 | * Logically, the interval patterns are mappings |
michael@0 | 48 | * from (skeleton, the_largest_different_calendar_field) |
michael@0 | 49 | * to (date_interval_pattern). |
michael@0 | 50 | * |
michael@0 | 51 | * <P> |
michael@0 | 52 | * A skeleton |
michael@0 | 53 | * <ol> |
michael@0 | 54 | * <li> |
michael@0 | 55 | * only keeps the field pattern letter and ignores all other parts |
michael@0 | 56 | * in a pattern, such as space, punctuations, and string literals. |
michael@0 | 57 | * <li> |
michael@0 | 58 | * hides the order of fields. |
michael@0 | 59 | * <li> |
michael@0 | 60 | * might hide a field's pattern letter length. |
michael@0 | 61 | * |
michael@0 | 62 | * For those non-digit calendar fields, the pattern letter length is |
michael@0 | 63 | * important, such as MMM, MMMM, and MMMMM; EEE and EEEE, |
michael@0 | 64 | * and the field's pattern letter length is honored. |
michael@0 | 65 | * |
michael@0 | 66 | * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy, |
michael@0 | 67 | * the field pattern length is ignored and the best match, which is defined |
michael@0 | 68 | * in date time patterns, will be returned without honor the field pattern |
michael@0 | 69 | * letter length in skeleton. |
michael@0 | 70 | * </ol> |
michael@0 | 71 | * |
michael@0 | 72 | * <P> |
michael@0 | 73 | * The calendar fields we support for interval formatting are: |
michael@0 | 74 | * year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute. |
michael@0 | 75 | * Those calendar fields can be defined in the following order: |
michael@0 | 76 | * year > month > date > am-pm > hour > minute |
michael@0 | 77 | * |
michael@0 | 78 | * The largest different calendar fields between 2 calendars is the |
michael@0 | 79 | * first different calendar field in above order. |
michael@0 | 80 | * |
michael@0 | 81 | * For example: the largest different calendar fields between "Jan 10, 2007" |
michael@0 | 82 | * and "Feb 20, 2008" is year. |
michael@0 | 83 | * |
michael@0 | 84 | * <P> |
michael@0 | 85 | * There is a set of pre-defined static skeleton strings. |
michael@0 | 86 | * There are pre-defined interval patterns for those pre-defined skeletons |
michael@0 | 87 | * in locales' resource files. |
michael@0 | 88 | * For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd", |
michael@0 | 89 | * in en_US, if the largest different calendar field between date1 and date2 |
michael@0 | 90 | * is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy", |
michael@0 | 91 | * such as "Jan 10, 2007 - Jan 10, 2008". |
michael@0 | 92 | * If the largest different calendar field between date1 and date2 is "month", |
michael@0 | 93 | * the date interval pattern is "MMM d - MMM d, yyyy", |
michael@0 | 94 | * such as "Jan 10 - Feb 10, 2007". |
michael@0 | 95 | * If the largest different calendar field between date1 and date2 is "day", |
michael@0 | 96 | * the date interval pattern is "MMM d-d, yyyy", such as "Jan 10-20, 2007". |
michael@0 | 97 | * |
michael@0 | 98 | * For date skeleton, the interval patterns when year, or month, or date is |
michael@0 | 99 | * different are defined in resource files. |
michael@0 | 100 | * For time skeleton, the interval patterns when am/pm, or hour, or minute is |
michael@0 | 101 | * different are defined in resource files. |
michael@0 | 102 | * |
michael@0 | 103 | * |
michael@0 | 104 | * <P> |
michael@0 | 105 | * There are 2 dates in interval pattern. For most locales, the first date |
michael@0 | 106 | * in an interval pattern is the earlier date. There might be a locale in which |
michael@0 | 107 | * the first date in an interval pattern is the later date. |
michael@0 | 108 | * We use fallback format for the default order for the locale. |
michael@0 | 109 | * For example, if the fallback format is "{0} - {1}", it means |
michael@0 | 110 | * the first date in the interval pattern for this locale is earlier date. |
michael@0 | 111 | * If the fallback format is "{1} - {0}", it means the first date is the |
michael@0 | 112 | * later date. |
michael@0 | 113 | * For a particular interval pattern, the default order can be overriden |
michael@0 | 114 | * by prefixing "latestFirst:" or "earliestFirst:" to the interval pattern. |
michael@0 | 115 | * For example, if the fallback format is "{0}-{1}", |
michael@0 | 116 | * but for skeleton "yMMMd", the interval pattern when day is different is |
michael@0 | 117 | * "latestFirst:d-d MMM yy", it means by default, the first date in interval |
michael@0 | 118 | * pattern is the earlier date. But for skeleton "yMMMd", when day is different, |
michael@0 | 119 | * the first date in "d-d MMM yy" is the later date. |
michael@0 | 120 | * |
michael@0 | 121 | * <P> |
michael@0 | 122 | * The recommended way to create a DateIntervalFormat object is to pass in |
michael@0 | 123 | * the locale. |
michael@0 | 124 | * By using a Locale parameter, the DateIntervalFormat object is |
michael@0 | 125 | * initialized with the pre-defined interval patterns for a given or |
michael@0 | 126 | * default locale. |
michael@0 | 127 | * <P> |
michael@0 | 128 | * Users can also create DateIntervalFormat object |
michael@0 | 129 | * by supplying their own interval patterns. |
michael@0 | 130 | * It provides flexibility for power users. |
michael@0 | 131 | * |
michael@0 | 132 | * <P> |
michael@0 | 133 | * After a DateIntervalInfo object is created, clients may modify |
michael@0 | 134 | * the interval patterns using setIntervalPattern function as so desired. |
michael@0 | 135 | * Currently, users can only set interval patterns when the following |
michael@0 | 136 | * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, |
michael@0 | 137 | * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE. |
michael@0 | 138 | * Interval patterns when other calendar fields are different is not supported. |
michael@0 | 139 | * <P> |
michael@0 | 140 | * DateIntervalInfo objects are cloneable. |
michael@0 | 141 | * When clients obtain a DateIntervalInfo object, |
michael@0 | 142 | * they can feel free to modify it as necessary. |
michael@0 | 143 | * <P> |
michael@0 | 144 | * DateIntervalInfo are not expected to be subclassed. |
michael@0 | 145 | * Data for a calendar is loaded out of resource bundles. |
michael@0 | 146 | * Through ICU 4.4, date interval patterns are only supported in the Gregorian |
michael@0 | 147 | * calendar; non-Gregorian calendars are supported from ICU 4.4.1. |
michael@0 | 148 | * @stable ICU 4.0 |
michael@0 | 149 | **/ |
michael@0 | 150 | |
michael@0 | 151 | class U_I18N_API DateIntervalInfo : public UObject { |
michael@0 | 152 | public: |
michael@0 | 153 | #ifndef U_HIDE_INTERNAL_API |
michael@0 | 154 | /** |
michael@0 | 155 | * Default constructor. |
michael@0 | 156 | * It does not initialize any interval patterns except |
michael@0 | 157 | * that it initialize default fall-back pattern as "{0} - {1}", |
michael@0 | 158 | * which can be reset by setFallbackIntervalPattern(). |
michael@0 | 159 | * It should be followed by setFallbackIntervalPattern() and |
michael@0 | 160 | * setIntervalPattern(), |
michael@0 | 161 | * and is recommended to be used only for power users who |
michael@0 | 162 | * wants to create their own interval patterns and use them to create |
michael@0 | 163 | * date interval formatter. |
michael@0 | 164 | * @param status output param set to success/failure code on exit |
michael@0 | 165 | * @internal ICU 4.0 |
michael@0 | 166 | */ |
michael@0 | 167 | DateIntervalInfo(UErrorCode& status); |
michael@0 | 168 | #endif /* U_HIDE_INTERNAL_API */ |
michael@0 | 169 | |
michael@0 | 170 | |
michael@0 | 171 | /** |
michael@0 | 172 | * Construct DateIntervalInfo for the given locale, |
michael@0 | 173 | * @param locale the interval patterns are loaded from the appropriate calendar |
michael@0 | 174 | * data (specified calendar or default calendar) in this locale. |
michael@0 | 175 | * @param status output param set to success/failure code on exit |
michael@0 | 176 | * @stable ICU 4.0 |
michael@0 | 177 | */ |
michael@0 | 178 | DateIntervalInfo(const Locale& locale, UErrorCode& status); |
michael@0 | 179 | |
michael@0 | 180 | |
michael@0 | 181 | /** |
michael@0 | 182 | * Copy constructor. |
michael@0 | 183 | * @stable ICU 4.0 |
michael@0 | 184 | */ |
michael@0 | 185 | DateIntervalInfo(const DateIntervalInfo&); |
michael@0 | 186 | |
michael@0 | 187 | /** |
michael@0 | 188 | * Assignment operator |
michael@0 | 189 | * @stable ICU 4.0 |
michael@0 | 190 | */ |
michael@0 | 191 | DateIntervalInfo& operator=(const DateIntervalInfo&); |
michael@0 | 192 | |
michael@0 | 193 | /** |
michael@0 | 194 | * Clone this object polymorphically. |
michael@0 | 195 | * The caller owns the result and should delete it when done. |
michael@0 | 196 | * @return a copy of the object |
michael@0 | 197 | * @stable ICU 4.0 |
michael@0 | 198 | */ |
michael@0 | 199 | virtual DateIntervalInfo* clone(void) const; |
michael@0 | 200 | |
michael@0 | 201 | /** |
michael@0 | 202 | * Destructor. |
michael@0 | 203 | * It is virtual to be safe, but it is not designed to be subclassed. |
michael@0 | 204 | * @stable ICU 4.0 |
michael@0 | 205 | */ |
michael@0 | 206 | virtual ~DateIntervalInfo(); |
michael@0 | 207 | |
michael@0 | 208 | |
michael@0 | 209 | /** |
michael@0 | 210 | * Return true if another object is semantically equal to this one. |
michael@0 | 211 | * |
michael@0 | 212 | * @param other the DateIntervalInfo object to be compared with. |
michael@0 | 213 | * @return true if other is semantically equal to this. |
michael@0 | 214 | * @stable ICU 4.0 |
michael@0 | 215 | */ |
michael@0 | 216 | virtual UBool operator==(const DateIntervalInfo& other) const; |
michael@0 | 217 | |
michael@0 | 218 | /** |
michael@0 | 219 | * Return true if another object is semantically unequal to this one. |
michael@0 | 220 | * |
michael@0 | 221 | * @param other the DateIntervalInfo object to be compared with. |
michael@0 | 222 | * @return true if other is semantically unequal to this. |
michael@0 | 223 | * @stable ICU 4.0 |
michael@0 | 224 | */ |
michael@0 | 225 | UBool operator!=(const DateIntervalInfo& other) const; |
michael@0 | 226 | |
michael@0 | 227 | |
michael@0 | 228 | |
michael@0 | 229 | /** |
michael@0 | 230 | * Provides a way for client to build interval patterns. |
michael@0 | 231 | * User could construct DateIntervalInfo by providing a list of skeletons |
michael@0 | 232 | * and their patterns. |
michael@0 | 233 | * <P> |
michael@0 | 234 | * For example: |
michael@0 | 235 | * <pre> |
michael@0 | 236 | * UErrorCode status = U_ZERO_ERROR; |
michael@0 | 237 | * DateIntervalInfo dIntervalInfo = new DateIntervalInfo(); |
michael@0 | 238 | * dIntervalInfo->setFallbackIntervalPattern("{0} ~ {1}"); |
michael@0 | 239 | * dIntervalInfo->setIntervalPattern("yMd", UCAL_YEAR, "'from' yyyy-M-d 'to' yyyy-M-d", status); |
michael@0 | 240 | * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_MONTH, "'from' yyyy MMM d 'to' MMM d", status); |
michael@0 | 241 | * dIntervalInfo->setIntervalPattern("yMMMd", UCAL_DAY, "yyyy MMM d-d", status, status); |
michael@0 | 242 | * </pre> |
michael@0 | 243 | * |
michael@0 | 244 | * Restriction: |
michael@0 | 245 | * Currently, users can only set interval patterns when the following |
michael@0 | 246 | * calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, |
michael@0 | 247 | * DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, and MINUTE. |
michael@0 | 248 | * Interval patterns when other calendar fields are different are |
michael@0 | 249 | * not supported. |
michael@0 | 250 | * |
michael@0 | 251 | * @param skeleton the skeleton on which interval pattern based |
michael@0 | 252 | * @param lrgDiffCalUnit the largest different calendar unit. |
michael@0 | 253 | * @param intervalPattern the interval pattern on the largest different |
michael@0 | 254 | * calendar unit. |
michael@0 | 255 | * For example, if lrgDiffCalUnit is |
michael@0 | 256 | * "year", the interval pattern for en_US when year |
michael@0 | 257 | * is different could be "'from' yyyy 'to' yyyy". |
michael@0 | 258 | * @param status output param set to success/failure code on exit |
michael@0 | 259 | * @stable ICU 4.0 |
michael@0 | 260 | */ |
michael@0 | 261 | void setIntervalPattern(const UnicodeString& skeleton, |
michael@0 | 262 | UCalendarDateFields lrgDiffCalUnit, |
michael@0 | 263 | const UnicodeString& intervalPattern, |
michael@0 | 264 | UErrorCode& status); |
michael@0 | 265 | |
michael@0 | 266 | /** |
michael@0 | 267 | * Get the interval pattern given skeleton and |
michael@0 | 268 | * the largest different calendar field. |
michael@0 | 269 | * @param skeleton the skeleton |
michael@0 | 270 | * @param field the largest different calendar field |
michael@0 | 271 | * @param result output param to receive the pattern |
michael@0 | 272 | * @param status output param set to success/failure code on exit |
michael@0 | 273 | * @return a reference to 'result' |
michael@0 | 274 | * @stable ICU 4.0 |
michael@0 | 275 | */ |
michael@0 | 276 | UnicodeString& getIntervalPattern(const UnicodeString& skeleton, |
michael@0 | 277 | UCalendarDateFields field, |
michael@0 | 278 | UnicodeString& result, |
michael@0 | 279 | UErrorCode& status) const; |
michael@0 | 280 | |
michael@0 | 281 | /** |
michael@0 | 282 | * Get the fallback interval pattern. |
michael@0 | 283 | * @param result output param to receive the pattern |
michael@0 | 284 | * @return a reference to 'result' |
michael@0 | 285 | * @stable ICU 4.0 |
michael@0 | 286 | */ |
michael@0 | 287 | UnicodeString& getFallbackIntervalPattern(UnicodeString& result) const; |
michael@0 | 288 | |
michael@0 | 289 | |
michael@0 | 290 | /** |
michael@0 | 291 | * Re-set the fallback interval pattern. |
michael@0 | 292 | * |
michael@0 | 293 | * In construction, default fallback pattern is set as "{0} - {1}". |
michael@0 | 294 | * And constructor taking locale as parameter will set the |
michael@0 | 295 | * fallback pattern as what defined in the locale resource file. |
michael@0 | 296 | * |
michael@0 | 297 | * This method provides a way for user to replace the fallback pattern. |
michael@0 | 298 | * |
michael@0 | 299 | * @param fallbackPattern fall-back interval pattern. |
michael@0 | 300 | * @param status output param set to success/failure code on exit |
michael@0 | 301 | * @stable ICU 4.0 |
michael@0 | 302 | */ |
michael@0 | 303 | void setFallbackIntervalPattern(const UnicodeString& fallbackPattern, |
michael@0 | 304 | UErrorCode& status); |
michael@0 | 305 | |
michael@0 | 306 | |
michael@0 | 307 | /** Get default order -- whether the first date in pattern is later date |
michael@0 | 308 | or not. |
michael@0 | 309 | * return default date ordering in interval pattern. TRUE if the first date |
michael@0 | 310 | * in pattern is later date, FALSE otherwise. |
michael@0 | 311 | * @stable ICU 4.0 |
michael@0 | 312 | */ |
michael@0 | 313 | UBool getDefaultOrder() const; |
michael@0 | 314 | |
michael@0 | 315 | |
michael@0 | 316 | /** |
michael@0 | 317 | * ICU "poor man's RTTI", returns a UClassID for the actual class. |
michael@0 | 318 | * |
michael@0 | 319 | * @stable ICU 4.0 |
michael@0 | 320 | */ |
michael@0 | 321 | virtual UClassID getDynamicClassID() const; |
michael@0 | 322 | |
michael@0 | 323 | /** |
michael@0 | 324 | * ICU "poor man's RTTI", returns a UClassID for this class. |
michael@0 | 325 | * |
michael@0 | 326 | * @stable ICU 4.0 |
michael@0 | 327 | */ |
michael@0 | 328 | static UClassID U_EXPORT2 getStaticClassID(); |
michael@0 | 329 | |
michael@0 | 330 | |
michael@0 | 331 | private: |
michael@0 | 332 | /** |
michael@0 | 333 | * DateIntervalFormat will need access to |
michael@0 | 334 | * getBestSkeleton(), parseSkeleton(), enum IntervalPatternIndex, |
michael@0 | 335 | * and calendarFieldToPatternIndex(). |
michael@0 | 336 | * |
michael@0 | 337 | * Instead of making above public, |
michael@0 | 338 | * make DateIntervalFormat a friend of DateIntervalInfo. |
michael@0 | 339 | */ |
michael@0 | 340 | friend class DateIntervalFormat; |
michael@0 | 341 | |
michael@0 | 342 | /** |
michael@0 | 343 | * Following is for saving the interval patterns. |
michael@0 | 344 | * We only support interval patterns on |
michael@0 | 345 | * ERA, YEAR, MONTH, DAY, AM_PM, HOUR, and MINUTE |
michael@0 | 346 | */ |
michael@0 | 347 | enum IntervalPatternIndex |
michael@0 | 348 | { |
michael@0 | 349 | kIPI_ERA, |
michael@0 | 350 | kIPI_YEAR, |
michael@0 | 351 | kIPI_MONTH, |
michael@0 | 352 | kIPI_DATE, |
michael@0 | 353 | kIPI_AM_PM, |
michael@0 | 354 | kIPI_HOUR, |
michael@0 | 355 | kIPI_MINUTE, |
michael@0 | 356 | kIPI_MAX_INDEX |
michael@0 | 357 | }; |
michael@0 | 358 | public: |
michael@0 | 359 | #ifndef U_HIDE_INTERNAL_API |
michael@0 | 360 | /** |
michael@0 | 361 | * Max index for stored interval patterns |
michael@0 | 362 | * @internal ICU 4.4 |
michael@0 | 363 | */ |
michael@0 | 364 | enum { |
michael@0 | 365 | kMaxIntervalPatternIndex = kIPI_MAX_INDEX |
michael@0 | 366 | }; |
michael@0 | 367 | #endif /* U_HIDE_INTERNAL_API */ |
michael@0 | 368 | private: |
michael@0 | 369 | |
michael@0 | 370 | |
michael@0 | 371 | /** |
michael@0 | 372 | * Initialize the DateIntervalInfo from locale |
michael@0 | 373 | * @param locale the given locale. |
michael@0 | 374 | * @param status output param set to success/failure code on exit |
michael@0 | 375 | */ |
michael@0 | 376 | void initializeData(const Locale& locale, UErrorCode& status); |
michael@0 | 377 | |
michael@0 | 378 | |
michael@0 | 379 | /* Set Interval pattern. |
michael@0 | 380 | * |
michael@0 | 381 | * It sets interval pattern into the hash map. |
michael@0 | 382 | * |
michael@0 | 383 | * @param skeleton skeleton on which the interval pattern based |
michael@0 | 384 | * @param lrgDiffCalUnit the largest different calendar unit. |
michael@0 | 385 | * @param intervalPattern the interval pattern on the largest different |
michael@0 | 386 | * calendar unit. |
michael@0 | 387 | * @param status output param set to success/failure code on exit |
michael@0 | 388 | */ |
michael@0 | 389 | void setIntervalPatternInternally(const UnicodeString& skeleton, |
michael@0 | 390 | UCalendarDateFields lrgDiffCalUnit, |
michael@0 | 391 | const UnicodeString& intervalPattern, |
michael@0 | 392 | UErrorCode& status); |
michael@0 | 393 | |
michael@0 | 394 | |
michael@0 | 395 | /**given an input skeleton, get the best match skeleton |
michael@0 | 396 | * which has pre-defined interval pattern in resource file. |
michael@0 | 397 | * Also return the difference between the input skeleton |
michael@0 | 398 | * and the best match skeleton. |
michael@0 | 399 | * |
michael@0 | 400 | * TODO (xji): set field weight or |
michael@0 | 401 | * isolate the funtionality in DateTimePatternGenerator |
michael@0 | 402 | * @param skeleton input skeleton |
michael@0 | 403 | * @param bestMatchDistanceInfo the difference between input skeleton |
michael@0 | 404 | * and best match skeleton. |
michael@0 | 405 | * 0, if there is exact match for input skeleton |
michael@0 | 406 | * 1, if there is only field width difference between |
michael@0 | 407 | * the best match and the input skeleton |
michael@0 | 408 | * 2, the only field difference is 'v' and 'z' |
michael@0 | 409 | * -1, if there is calendar field difference between |
michael@0 | 410 | * the best match and the input skeleton |
michael@0 | 411 | * @return best match skeleton |
michael@0 | 412 | */ |
michael@0 | 413 | const UnicodeString* getBestSkeleton(const UnicodeString& skeleton, |
michael@0 | 414 | int8_t& bestMatchDistanceInfo) const; |
michael@0 | 415 | |
michael@0 | 416 | |
michael@0 | 417 | /** |
michael@0 | 418 | * Parse skeleton, save each field's width. |
michael@0 | 419 | * It is used for looking for best match skeleton, |
michael@0 | 420 | * and adjust pattern field width. |
michael@0 | 421 | * @param skeleton skeleton to be parsed |
michael@0 | 422 | * @param skeletonFieldWidth parsed skeleton field width |
michael@0 | 423 | */ |
michael@0 | 424 | static void U_EXPORT2 parseSkeleton(const UnicodeString& skeleton, |
michael@0 | 425 | int32_t* skeletonFieldWidth); |
michael@0 | 426 | |
michael@0 | 427 | |
michael@0 | 428 | /** |
michael@0 | 429 | * Check whether one field width is numeric while the other is string. |
michael@0 | 430 | * |
michael@0 | 431 | * TODO (xji): make it general |
michael@0 | 432 | * |
michael@0 | 433 | * @param fieldWidth one field width |
michael@0 | 434 | * @param anotherFieldWidth another field width |
michael@0 | 435 | * @param patternLetter pattern letter char |
michael@0 | 436 | * @return true if one field width is numeric and the other is string, |
michael@0 | 437 | * false otherwise. |
michael@0 | 438 | */ |
michael@0 | 439 | static UBool U_EXPORT2 stringNumeric(int32_t fieldWidth, |
michael@0 | 440 | int32_t anotherFieldWidth, |
michael@0 | 441 | char patternLetter); |
michael@0 | 442 | |
michael@0 | 443 | |
michael@0 | 444 | /** |
michael@0 | 445 | * Convert calendar field to the interval pattern index in |
michael@0 | 446 | * hash table. |
michael@0 | 447 | * |
michael@0 | 448 | * Since we only support the following calendar fields: |
michael@0 | 449 | * ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, DAY_OF_WEEK, |
michael@0 | 450 | * AM_PM, HOUR, HOUR_OF_DAY, and MINUTE, |
michael@0 | 451 | * We reserve only 4 interval patterns for a skeleton. |
michael@0 | 452 | * |
michael@0 | 453 | * @param field calendar field |
michael@0 | 454 | * @param status output param set to success/failure code on exit |
michael@0 | 455 | * @return interval pattern index in hash table |
michael@0 | 456 | */ |
michael@0 | 457 | static IntervalPatternIndex U_EXPORT2 calendarFieldToIntervalIndex( |
michael@0 | 458 | UCalendarDateFields field, |
michael@0 | 459 | UErrorCode& status); |
michael@0 | 460 | |
michael@0 | 461 | |
michael@0 | 462 | /** |
michael@0 | 463 | * delete hash table (of type fIntervalPatterns). |
michael@0 | 464 | * |
michael@0 | 465 | * @param hTable hash table to be deleted |
michael@0 | 466 | */ |
michael@0 | 467 | void deleteHash(Hashtable* hTable); |
michael@0 | 468 | |
michael@0 | 469 | |
michael@0 | 470 | /** |
michael@0 | 471 | * initialize hash table (of type fIntervalPatterns). |
michael@0 | 472 | * |
michael@0 | 473 | * @param status output param set to success/failure code on exit |
michael@0 | 474 | * @return hash table initialized |
michael@0 | 475 | */ |
michael@0 | 476 | Hashtable* initHash(UErrorCode& status); |
michael@0 | 477 | |
michael@0 | 478 | |
michael@0 | 479 | |
michael@0 | 480 | /** |
michael@0 | 481 | * copy hash table (of type fIntervalPatterns). |
michael@0 | 482 | * |
michael@0 | 483 | * @param source the source to copy from |
michael@0 | 484 | * @param target the target to copy to |
michael@0 | 485 | * @param status output param set to success/failure code on exit |
michael@0 | 486 | */ |
michael@0 | 487 | void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); |
michael@0 | 488 | |
michael@0 | 489 | |
michael@0 | 490 | // data members |
michael@0 | 491 | // fallback interval pattern |
michael@0 | 492 | UnicodeString fFallbackIntervalPattern; |
michael@0 | 493 | // default order |
michael@0 | 494 | UBool fFirstDateInPtnIsLaterDate; |
michael@0 | 495 | |
michael@0 | 496 | // HashMap<UnicodeString, UnicodeString[kIPI_MAX_INDEX]> |
michael@0 | 497 | // HashMap( skeleton, pattern[largest_different_field] ) |
michael@0 | 498 | Hashtable* fIntervalPatterns; |
michael@0 | 499 | |
michael@0 | 500 | };// end class DateIntervalInfo |
michael@0 | 501 | |
michael@0 | 502 | |
michael@0 | 503 | inline UBool |
michael@0 | 504 | DateIntervalInfo::operator!=(const DateIntervalInfo& other) const { |
michael@0 | 505 | return !operator==(other); |
michael@0 | 506 | } |
michael@0 | 507 | |
michael@0 | 508 | |
michael@0 | 509 | U_NAMESPACE_END |
michael@0 | 510 | |
michael@0 | 511 | #endif |
michael@0 | 512 | |
michael@0 | 513 | #endif |
michael@0 | 514 |