intl/icu/source/i18n/unicode/tznames.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 * Copyright (C) 2011-2013, International Business Machines Corporation and *
michael@0 4 * others. All Rights Reserved. *
michael@0 5 *******************************************************************************
michael@0 6 */
michael@0 7 #ifndef __TZNAMES_H
michael@0 8 #define __TZNAMES_H
michael@0 9
michael@0 10 /**
michael@0 11 * \file
michael@0 12 * \brief C++ API: TimeZoneNames
michael@0 13 */
michael@0 14 #include "unicode/utypes.h"
michael@0 15
michael@0 16 #if !UCONFIG_NO_FORMATTING
michael@0 17
michael@0 18 #include "unicode/uloc.h"
michael@0 19 #include "unicode/unistr.h"
michael@0 20
michael@0 21 U_CDECL_BEGIN
michael@0 22
michael@0 23 /**
michael@0 24 * Constants for time zone display name types.
michael@0 25 * @stable ICU 50
michael@0 26 */
michael@0 27 typedef enum UTimeZoneNameType {
michael@0 28 /**
michael@0 29 * Unknown display name type.
michael@0 30 * @stable ICU 50
michael@0 31 */
michael@0 32 UTZNM_UNKNOWN = 0x00,
michael@0 33 /**
michael@0 34 * Long display name, such as "Eastern Time".
michael@0 35 * @stable ICU 50
michael@0 36 */
michael@0 37 UTZNM_LONG_GENERIC = 0x01,
michael@0 38 /**
michael@0 39 * Long display name for standard time, such as "Eastern Standard Time".
michael@0 40 * @stable ICU 50
michael@0 41 */
michael@0 42 UTZNM_LONG_STANDARD = 0x02,
michael@0 43 /**
michael@0 44 * Long display name for daylight saving time, such as "Eastern Daylight Time".
michael@0 45 * @stable ICU 50
michael@0 46 */
michael@0 47 UTZNM_LONG_DAYLIGHT = 0x04,
michael@0 48 /**
michael@0 49 * Short display name, such as "ET".
michael@0 50 * @stable ICU 50
michael@0 51 */
michael@0 52 UTZNM_SHORT_GENERIC = 0x08,
michael@0 53 /**
michael@0 54 * Short display name for standard time, such as "EST".
michael@0 55 * @stable ICU 50
michael@0 56 */
michael@0 57 UTZNM_SHORT_STANDARD = 0x10,
michael@0 58 /**
michael@0 59 * Short display name for daylight saving time, such as "EDT".
michael@0 60 * @stable ICU 50
michael@0 61 */
michael@0 62 UTZNM_SHORT_DAYLIGHT = 0x20,
michael@0 63 #ifndef U_HIDE_DRAFT_API
michael@0 64 /**
michael@0 65 * Exemplar location name, such as "Los Angeles".
michael@0 66 * @draft ICU 51
michael@0 67 */
michael@0 68 UTZNM_EXEMPLAR_LOCATION = 0x40
michael@0 69 #endif /* U_HIDE_DRAFT_API */
michael@0 70 } UTimeZoneNameType;
michael@0 71
michael@0 72 U_CDECL_END
michael@0 73
michael@0 74 U_NAMESPACE_BEGIN
michael@0 75
michael@0 76 class UVector;
michael@0 77 struct MatchInfo;
michael@0 78
michael@0 79 /**
michael@0 80 * <code>TimeZoneNames</code> is an abstract class representing the time zone display name data model defined
michael@0 81 * by <a href="http://www.unicode.org/reports/tr35/">UTS#35 Unicode Locale Data Markup Language (LDML)</a>.
michael@0 82 * The model defines meta zone, which is used for storing a set of display names. A meta zone can be shared
michael@0 83 * by multiple time zones. Also a time zone may have multiple meta zone historic mappings.
michael@0 84 * <p>
michael@0 85 * For example, people in the United States refer the zone used by the east part of North America as "Eastern Time".
michael@0 86 * The tz database contains multiple time zones "America/New_York", "America/Detroit", "America/Montreal" and some
michael@0 87 * others that belong to "Eastern Time". However, assigning different display names to these time zones does not make
michael@0 88 * much sense for most of people.
michael@0 89 * <p>
michael@0 90 * In <a href="http://cldr.unicode.org/">CLDR</a> (which uses LDML for representing locale data), the display name
michael@0 91 * "Eastern Time" is stored as long generic display name of a meta zone identified by the ID "America_Eastern".
michael@0 92 * Then, there is another table maintaining the historic mapping to meta zones for each time zone. The time zones in
michael@0 93 * the above example ("America/New_York", "America/Detroit"...) are mapped to the meta zone "America_Eastern".
michael@0 94 * <p>
michael@0 95 * Sometimes, a time zone is mapped to a different time zone in the past. For example, "America/Indiana/Knox"
michael@0 96 * had been moving "Eastern Time" and "Central Time" back and forth. Therefore, it is necessary that time zone
michael@0 97 * to meta zones mapping data are stored by date range.
michael@0 98 *
michael@0 99 * <p><b>Note:</b>
michael@0 100 * The methods in this class assume that time zone IDs are already canonicalized. For example, you may not get proper
michael@0 101 * result returned by a method with time zone ID "America/Indiana/Indianapolis", because it's not a canonical time zone
michael@0 102 * ID (the canonical time zone ID for the time zone is "America/Indianapolis". See
michael@0 103 * {@link TimeZone#getCanonicalID(const UnicodeString& id, UnicodeString& canonicalID, UErrorCode& status)} about ICU
michael@0 104 * canonical time zone IDs.
michael@0 105 *
michael@0 106 * <p>
michael@0 107 * In CLDR, most of time zone display names except location names are provided through meta zones. But a time zone may
michael@0 108 * have a specific name that is not shared with other time zones.
michael@0 109 *
michael@0 110 * For example, time zone "Europe/London" has English long name for standard time "Greenwich Mean Time", which is also
michael@0 111 * shared with other time zones. However, the long name for daylight saving time is "British Summer Time", which is only
michael@0 112 * used for "Europe/London".
michael@0 113 *
michael@0 114 * <p>
michael@0 115 * {@link #getTimeZoneDisplayName} is designed for accessing a name only used by a single time zone.
michael@0 116 * But is not necessarily mean that a subclass implementation use the same model with CLDR. A subclass implementation
michael@0 117 * may provide time zone names only through {@link #getTimeZoneDisplayName}, or only through {@link #getMetaZoneDisplayName},
michael@0 118 * or both.
michael@0 119 *
michael@0 120 * <p>
michael@0 121 * The default <code>TimeZoneNames</code> implementation returned by {@link #createInstance}
michael@0 122 * uses the locale data imported from CLDR. In CLDR, set of meta zone IDs and mappings between zone IDs and meta zone
michael@0 123 * IDs are shared by all locales. Therefore, the behavior of {@link #getAvailableMetaZoneIDs},
michael@0 124 * {@link #getMetaZoneID}, and {@link #getReferenceZoneID} won't be changed no matter
michael@0 125 * what locale is used for getting an instance of <code>TimeZoneNames</code>.
michael@0 126 *
michael@0 127 * @stable ICU 50
michael@0 128 */
michael@0 129 class U_I18N_API TimeZoneNames : public UObject {
michael@0 130 public:
michael@0 131 /**
michael@0 132 * Destructor.
michael@0 133 * @stable ICU 50
michael@0 134 */
michael@0 135 virtual ~TimeZoneNames();
michael@0 136
michael@0 137 /**
michael@0 138 * Return true if the given TimeZoneNames objects are emantically equal.
michael@0 139 * @param other the object to be compared with.
michael@0 140 * @return Return TRUE if the given Format objects are semantically equal.
michael@0 141 * @stable ICU 50
michael@0 142 */
michael@0 143 virtual UBool operator==(const TimeZoneNames& other) const = 0;
michael@0 144
michael@0 145 /**
michael@0 146 * Return true if the given TimeZoneNames objects are not semantically
michael@0 147 * equal.
michael@0 148 * @param other the object to be compared with.
michael@0 149 * @return Return TRUE if the given Format objects are not semantically equal.
michael@0 150 * @stable ICU 50
michael@0 151 */
michael@0 152 UBool operator!=(const TimeZoneNames& other) const { return !operator==(other); }
michael@0 153
michael@0 154 /**
michael@0 155 * Clone this object polymorphically. The caller is responsible
michael@0 156 * for deleting the result when done.
michael@0 157 * @return A copy of the object
michael@0 158 * @stable ICU 50
michael@0 159 */
michael@0 160 virtual TimeZoneNames* clone() const = 0;
michael@0 161
michael@0 162 /**
michael@0 163 * Returns an instance of <code>TimeZoneDisplayNames</code> for the specified locale.
michael@0 164 *
michael@0 165 * @param locale The locale.
michael@0 166 * @param status Recevies the status.
michael@0 167 * @return An instance of <code>TimeZoneDisplayNames</code>
michael@0 168 * @stable ICU 50
michael@0 169 */
michael@0 170 static TimeZoneNames* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
michael@0 171
michael@0 172 /**
michael@0 173 * Returns an enumeration of all available meta zone IDs.
michael@0 174 * @param status Recevies the status.
michael@0 175 * @return an enumeration object, owned by the caller.
michael@0 176 * @stable ICU 50
michael@0 177 */
michael@0 178 virtual StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const = 0;
michael@0 179
michael@0 180 /**
michael@0 181 * Returns an enumeration of all available meta zone IDs used by the given time zone.
michael@0 182 * @param tzID The canoical tiem zone ID.
michael@0 183 * @param status Recevies the status.
michael@0 184 * @return an enumeration object, owned by the caller.
michael@0 185 * @stable ICU 50
michael@0 186 */
michael@0 187 virtual StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const = 0;
michael@0 188
michael@0 189 /**
michael@0 190 * Returns the meta zone ID for the given canonical time zone ID at the given date.
michael@0 191 * @param tzID The canonical time zone ID.
michael@0 192 * @param date The date.
michael@0 193 * @param mzID Receives the meta zone ID for the given time zone ID at the given date. If the time zone does not have a
michael@0 194 * corresponding meta zone at the given date or the implementation does not support meta zones, "bogus" state
michael@0 195 * is set.
michael@0 196 * @return A reference to the result.
michael@0 197 * @stable ICU 50
michael@0 198 */
michael@0 199 virtual UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const = 0;
michael@0 200
michael@0 201 /**
michael@0 202 * Returns the reference zone ID for the given meta zone ID for the region.
michael@0 203 *
michael@0 204 * Note: Each meta zone must have a reference zone associated with a special region "001" (world).
michael@0 205 * Some meta zones may have region specific reference zone IDs other than the special region
michael@0 206 * "001". When a meta zone does not have any region specific reference zone IDs, this method
michael@0 207 * return the reference zone ID for the special region "001" (world).
michael@0 208 *
michael@0 209 * @param mzID The meta zone ID.
michael@0 210 * @param region The region.
michael@0 211 * @param tzID Receives the reference zone ID ("golden zone" in the LDML specification) for the given time zone ID for the
michael@0 212 * region. If the meta zone is unknown or the implementation does not support meta zones, "bogus" state
michael@0 213 * is set.
michael@0 214 * @return A reference to the result.
michael@0 215 * @stable ICU 50
michael@0 216 */
michael@0 217 virtual UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const = 0;
michael@0 218
michael@0 219 /**
michael@0 220 * Returns the display name of the meta zone.
michael@0 221 * @param mzID The meta zone ID.
michael@0 222 * @param type The display name type. See {@link #UTimeZoneNameType}.
michael@0 223 * @param name Receives the display name of the meta zone. When this object does not have a localized display name for the given
michael@0 224 * meta zone with the specified type or the implementation does not provide any display names associated
michael@0 225 * with meta zones, "bogus" state is set.
michael@0 226 * @return A reference to the result.
michael@0 227 * @stable ICU 50
michael@0 228 */
michael@0 229 virtual UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
michael@0 230
michael@0 231 /**
michael@0 232 * Returns the display name of the time zone. Unlike {@link #getDisplayName},
michael@0 233 * this method does not get a name from a meta zone used by the time zone.
michael@0 234 * @param tzID The canonical time zone ID.
michael@0 235 * @param type The display name type. See {@link #UTimeZoneNameType}.
michael@0 236 * @param name Receives the display name for the time zone. When this object does not have a localized display name for the given
michael@0 237 * time zone with the specified type, "bogus" state is set.
michael@0 238 * @return A reference to the result.
michael@0 239 * @stable ICU 50
michael@0 240 */
michael@0 241 virtual UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
michael@0 242
michael@0 243 /**
michael@0 244 * Returns the exemplar location name for the given time zone. When this object does not have a localized location
michael@0 245 * name, the default implementation may still returns a programmatically generated name with the logic described
michael@0 246 * below.
michael@0 247 * <ol>
michael@0 248 * <li>Check if the ID contains "/". If not, return null.
michael@0 249 * <li>Check if the ID does not start with "Etc/" or "SystemV/". If it does, return null.
michael@0 250 * <li>Extract a substring after the last occurrence of "/".
michael@0 251 * <li>Replace "_" with " ".
michael@0 252 * </ol>
michael@0 253 * For example, "New York" is returned for the time zone ID "America/New_York" when this object does not have the
michael@0 254 * localized location name.
michael@0 255 *
michael@0 256 * @param tzID The canonical time zone ID
michael@0 257 * @param name Receives the exemplar location name for the given time zone, or "bogus" state is set when a localized
michael@0 258 * location name is not available and the fallback logic described above cannot extract location from the ID.
michael@0 259 * @return A reference to the result.
michael@0 260 * @stable ICU 50
michael@0 261 */
michael@0 262 virtual UnicodeString& getExemplarLocationName(const UnicodeString& tzID, UnicodeString& name) const;
michael@0 263
michael@0 264 /**
michael@0 265 * Returns the display name of the time zone at the given date.
michael@0 266 * <p>
michael@0 267 * <b>Note:</b> This method calls the subclass's {@link #getTimeZoneDisplayName} first. When the
michael@0 268 * result is bogus, this method calls {@link #getMetaZoneID} to get the meta zone ID mapped from the
michael@0 269 * time zone, then calls {@link #getMetaZoneDisplayName}.
michael@0 270 *
michael@0 271 * @param tzID The canonical time zone ID.
michael@0 272 * @param type The display name type. See {@link #UTimeZoneNameType}.
michael@0 273 * @param date The date.
michael@0 274 * @param name Receives the display name for the time zone at the given date. When this object does not have a localized display
michael@0 275 * name for the time zone with the specified type and date, "bogus" state is set.
michael@0 276 * @return A reference to the result.
michael@0 277 * @stable ICU 50
michael@0 278 */
michael@0 279 virtual UnicodeString& getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UDate date, UnicodeString& name) const;
michael@0 280
michael@0 281 /**
michael@0 282 * <code>MatchInfoCollection</code> represents a collection of time zone name matches used by
michael@0 283 * {@link TimeZoneNames#find}.
michael@0 284 * @internal
michael@0 285 */
michael@0 286 class U_I18N_API MatchInfoCollection : public UMemory {
michael@0 287 public:
michael@0 288 /**
michael@0 289 * Constructor.
michael@0 290 * @internal
michael@0 291 */
michael@0 292 MatchInfoCollection();
michael@0 293 /**
michael@0 294 * Destructor.
michael@0 295 * @internal
michael@0 296 */
michael@0 297 virtual ~MatchInfoCollection();
michael@0 298
michael@0 299 #ifndef U_HIDE_INTERNAL_API
michael@0 300 /**
michael@0 301 * Adds a zone match.
michael@0 302 * @param nameType The name type.
michael@0 303 * @param matchLength The match length.
michael@0 304 * @param tzID The time zone ID.
michael@0 305 * @param status Receives the status
michael@0 306 * @internal
michael@0 307 */
michael@0 308 void addZone(UTimeZoneNameType nameType, int32_t matchLength,
michael@0 309 const UnicodeString& tzID, UErrorCode& status);
michael@0 310
michael@0 311 /**
michael@0 312 * Adds a meata zone match.
michael@0 313 * @param nameType The name type.
michael@0 314 * @param matchLength The match length.
michael@0 315 * @param mzID The metazone ID.
michael@0 316 * @param status Receives the status
michael@0 317 * @internal
michael@0 318 */
michael@0 319 void addMetaZone(UTimeZoneNameType nameType, int32_t matchLength,
michael@0 320 const UnicodeString& mzID, UErrorCode& status);
michael@0 321
michael@0 322 /**
michael@0 323 * Returns the number of entries available in this object.
michael@0 324 * @return The number of entries.
michael@0 325 * @internal
michael@0 326 */
michael@0 327 int32_t size() const;
michael@0 328
michael@0 329 /**
michael@0 330 * Returns the time zone name type of a match at the specified index.
michael@0 331 * @param idx The index
michael@0 332 * @return The time zone name type. If the specified idx is out of range,
michael@0 333 * it returns UTZNM_UNKNOWN.
michael@0 334 * @see UTimeZoneNameType
michael@0 335 * @internal
michael@0 336 */
michael@0 337 UTimeZoneNameType getNameTypeAt(int32_t idx) const;
michael@0 338
michael@0 339 /**
michael@0 340 * Returns the match length of a match at the specified index.
michael@0 341 * @param idx The index
michael@0 342 * @return The match length. If the specified idx is out of range,
michael@0 343 * it returns 0.
michael@0 344 * @internal
michael@0 345 */
michael@0 346 int32_t getMatchLengthAt(int32_t idx) const;
michael@0 347
michael@0 348 /**
michael@0 349 * Gets the zone ID of a match at the specified index.
michael@0 350 * @param idx The index
michael@0 351 * @param tzID Receives the zone ID.
michael@0 352 * @return TRUE if the zone ID was set to tzID.
michael@0 353 * @internal
michael@0 354 */
michael@0 355 UBool getTimeZoneIDAt(int32_t idx, UnicodeString& tzID) const;
michael@0 356
michael@0 357 /**
michael@0 358 * Gets the metazone ID of a match at the specified index.
michael@0 359 * @param idx The index
michael@0 360 * @param mzID Receives the metazone ID
michael@0 361 * @return TRUE if the meta zone ID was set to mzID.
michael@0 362 * @internal
michael@0 363 */
michael@0 364 UBool getMetaZoneIDAt(int32_t idx, UnicodeString& mzID) const;
michael@0 365 #endif /* U_HIDE_INTERNAL_API */
michael@0 366
michael@0 367 private:
michael@0 368 UVector* fMatches; // vector of MatchEntry
michael@0 369
michael@0 370 UVector* matches(UErrorCode& status);
michael@0 371 };
michael@0 372
michael@0 373 /**
michael@0 374 * Finds time zone name prefix matches for the input text at the
michael@0 375 * given offset and returns a collection of the matches.
michael@0 376 * @param text The text.
michael@0 377 * @param start The starting offset within the text.
michael@0 378 * @param types The set of name types represented by bitwise flags of UTimeZoneNameType enums,
michael@0 379 * or UTZNM_UNKNOWN for all name types.
michael@0 380 * @param status Receives the status.
michael@0 381 * @return A collection of matches (owned by the caller), or NULL if no matches are found.
michael@0 382 * @see UTimeZoneNameType
michael@0 383 * @see MatchInfoCollection
michael@0 384 * @internal
michael@0 385 */
michael@0 386 virtual MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const = 0;
michael@0 387 };
michael@0 388
michael@0 389 U_NAMESPACE_END
michael@0 390
michael@0 391 #endif
michael@0 392 #endif

mercurial