OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * Copyright (C) 2011-2014, International Business Machines Corporation and | 3 * Copyright (C) 2011-2015, International Business Machines Corporation and |
4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
5 ******************************************************************************* | 5 ******************************************************************************* |
6 */ | 6 */ |
7 | 7 |
8 #include "unicode/utypes.h" | 8 #include "unicode/utypes.h" |
9 | 9 |
10 #if !UCONFIG_NO_FORMATTING | 10 #if !UCONFIG_NO_FORMATTING |
11 | 11 |
12 #include "unicode/calendar.h" | 12 #include "unicode/calendar.h" |
13 #include "unicode/tzfmt.h" | 13 #include "unicode/tzfmt.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 if (len > 0) { | 359 if (len > 0) { |
360 hourFormats = resStr; | 360 hourFormats = resStr; |
361 } | 361 } |
362 ures_close(zoneStringsArray); | 362 ures_close(zoneStringsArray); |
363 ures_close(zoneBundle); | 363 ures_close(zoneBundle); |
364 } | 364 } |
365 | 365 |
366 if (gmtPattern == NULL) { | 366 if (gmtPattern == NULL) { |
367 gmtPattern = DEFAULT_GMT_PATTERN; | 367 gmtPattern = DEFAULT_GMT_PATTERN; |
368 } | 368 } |
369 initGMTPattern(UnicodeString(gmtPattern, -1), status); | 369 initGMTPattern(UnicodeString(TRUE, gmtPattern, -1), status); |
370 | 370 |
371 UBool useDefaultOffsetPatterns = TRUE; | 371 UBool useDefaultOffsetPatterns = TRUE; |
372 if (hourFormats) { | 372 if (hourFormats) { |
373 UChar *sep = u_strchr(hourFormats, (UChar)0x003B /* ';' */); | 373 UChar *sep = u_strchr(hourFormats, (UChar)0x003B /* ';' */); |
374 if (sep != NULL) { | 374 if (sep != NULL) { |
375 UErrorCode tmpStatus = U_ZERO_ERROR; | 375 UErrorCode tmpStatus = U_ZERO_ERROR; |
376 fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM].setTo(FALSE, hourFormats,
(int32_t)(sep - hourFormats)); | 376 fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM].setTo(FALSE, hourFormats,
(int32_t)(sep - hourFormats)); |
377 fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM].setTo(TRUE, sep + 1, -1); | 377 fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM].setTo(TRUE, sep + 1, -1); |
378 expandOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM], fGMT
OffsetPatterns[UTZFMT_PAT_POSITIVE_HMS], tmpStatus); | 378 expandOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_POSITIVE_HM], fGMT
OffsetPatterns[UTZFMT_PAT_POSITIVE_HMS], tmpStatus); |
379 expandOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM], fGMT
OffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS], tmpStatus); | 379 expandOffsetPattern(fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HM], fGMT
OffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS], tmpStatus); |
(...skipping 20 matching lines...) Expand all Loading... |
400 UnicodeString digits = ns->getDescription(); | 400 UnicodeString digits = ns->getDescription(); |
401 useDefDigits = !toCodePoints(digits, fGMTOffsetDigits, 10); | 401 useDefDigits = !toCodePoints(digits, fGMTOffsetDigits, 10); |
402 } | 402 } |
403 if (useDefDigits) { | 403 if (useDefDigits) { |
404 uprv_memcpy(fGMTOffsetDigits, DEFAULT_GMT_DIGITS, sizeof(UChar32) * 10); | 404 uprv_memcpy(fGMTOffsetDigits, DEFAULT_GMT_DIGITS, sizeof(UChar32) * 10); |
405 } | 405 } |
406 delete ns; | 406 delete ns; |
407 } | 407 } |
408 | 408 |
409 TimeZoneFormat::TimeZoneFormat(const TimeZoneFormat& other) | 409 TimeZoneFormat::TimeZoneFormat(const TimeZoneFormat& other) |
410 : Format(other), fTimeZoneNames(NULL), fTimeZoneGenericNames(NULL) { | 410 : Format(other), fTimeZoneNames(NULL), fTimeZoneGenericNames(NULL), |
| 411 fTZDBTimeZoneNames(NULL) { |
411 | 412 |
412 for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) { | 413 for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) { |
413 fGMTOffsetPatternItems[i] = NULL; | 414 fGMTOffsetPatternItems[i] = NULL; |
414 } | 415 } |
415 *this = other; | 416 *this = other; |
416 } | 417 } |
417 | 418 |
418 | 419 |
419 TimeZoneFormat::~TimeZoneFormat() { | 420 TimeZoneFormat::~TimeZoneFormat() { |
420 delete fTimeZoneNames; | 421 delete fTimeZoneNames; |
421 delete fTimeZoneGenericNames; | 422 delete fTimeZoneGenericNames; |
422 delete fTZDBTimeZoneNames; | 423 delete fTZDBTimeZoneNames; |
423 for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) { | 424 for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) { |
424 delete fGMTOffsetPatternItems[i]; | 425 delete fGMTOffsetPatternItems[i]; |
425 } | 426 } |
426 } | 427 } |
427 | 428 |
428 TimeZoneFormat& | 429 TimeZoneFormat& |
429 TimeZoneFormat::operator=(const TimeZoneFormat& other) { | 430 TimeZoneFormat::operator=(const TimeZoneFormat& other) { |
430 if (this == &other) { | 431 if (this == &other) { |
431 return *this; | 432 return *this; |
432 } | 433 } |
433 | 434 |
434 delete fTimeZoneNames; | 435 delete fTimeZoneNames; |
435 delete fTimeZoneGenericNames; | 436 delete fTimeZoneGenericNames; |
436 fTimeZoneGenericNames = NULL; | 437 fTimeZoneGenericNames = NULL; |
| 438 delete fTZDBTimeZoneNames; |
| 439 fTZDBTimeZoneNames = NULL; |
437 | 440 |
438 fLocale = other.fLocale; | 441 fLocale = other.fLocale; |
439 uprv_memcpy(fTargetRegion, other.fTargetRegion, sizeof(fTargetRegion)); | 442 uprv_memcpy(fTargetRegion, other.fTargetRegion, sizeof(fTargetRegion)); |
440 | 443 |
441 fTimeZoneNames = other.fTimeZoneNames->clone(); | 444 fTimeZoneNames = other.fTimeZoneNames->clone(); |
442 if (other.fTimeZoneGenericNames) { | 445 if (other.fTimeZoneGenericNames) { |
443 // TODO: this test has dubious thread safety. | 446 // TODO: this test has dubious thread safety. |
444 fTimeZoneGenericNames = other.fTimeZoneGenericNames->clone(); | 447 fTimeZoneGenericNames = other.fTimeZoneGenericNames->clone(); |
445 } | 448 } |
446 | 449 |
447 fGMTPattern = other.fGMTPattern; | 450 fGMTPattern = other.fGMTPattern; |
448 fGMTPatternPrefix = other.fGMTPatternPrefix; | 451 fGMTPatternPrefix = other.fGMTPatternPrefix; |
449 fGMTPatternSuffix = other.fGMTPatternSuffix; | 452 fGMTPatternSuffix = other.fGMTPatternSuffix; |
450 | 453 |
451 UErrorCode status = U_ZERO_ERROR; | 454 UErrorCode status = U_ZERO_ERROR; |
452 for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) { | 455 for (int32_t i = 0; i < UTZFMT_PAT_COUNT; i++) { |
453 fGMTOffsetPatterns[i] = other.fGMTOffsetPatterns[i]; | 456 fGMTOffsetPatterns[i] = other.fGMTOffsetPatterns[i]; |
454 delete fGMTOffsetPatternItems[i]; | 457 delete fGMTOffsetPatternItems[i]; |
| 458 fGMTOffsetPatternItems[i] = NULL; |
455 } | 459 } |
456 initGMTOffsetPatterns(status); | 460 initGMTOffsetPatterns(status); |
457 U_ASSERT(U_SUCCESS(status)); | 461 U_ASSERT(U_SUCCESS(status)); |
458 | 462 |
459 fGMTZeroFormat = other.fGMTZeroFormat; | 463 fGMTZeroFormat = other.fGMTZeroFormat; |
460 | 464 |
461 uprv_memcpy(fGMTOffsetDigits, other.fGMTOffsetDigits, sizeof(fGMTOffsetDigit
s)); | 465 uprv_memcpy(fGMTOffsetDigits, other.fGMTOffsetDigits, sizeof(fGMTOffsetDigit
s)); |
462 | 466 |
463 fDefParseOptionFlags = other.fDefParseOptionFlags; | 467 fDefParseOptionFlags = other.fDefParseOptionFlags; |
464 | 468 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 if (tz == NULL) { | 777 if (tz == NULL) { |
774 const Calendar* cal = dynamic_cast<const Calendar*>(formatObj); | 778 const Calendar* cal = dynamic_cast<const Calendar*>(formatObj); |
775 if (cal != NULL) { | 779 if (cal != NULL) { |
776 tz = &cal->getTimeZone(); | 780 tz = &cal->getTimeZone(); |
777 date = cal->getTime(status); | 781 date = cal->getTime(status); |
778 } | 782 } |
779 } | 783 } |
780 if (tz != NULL) { | 784 if (tz != NULL) { |
781 int32_t rawOffset, dstOffset; | 785 int32_t rawOffset, dstOffset; |
782 tz->getOffset(date, FALSE, rawOffset, dstOffset, status); | 786 tz->getOffset(date, FALSE, rawOffset, dstOffset, status); |
783 UnicodeString result; | 787 UChar buf[32]; |
| 788 UnicodeString result(buf, 0, UPRV_LENGTHOF(buf)); |
784 formatOffsetLocalizedGMT(rawOffset + dstOffset, result, status); | 789 formatOffsetLocalizedGMT(rawOffset + dstOffset, result, status); |
785 if (U_SUCCESS(status)) { | 790 if (U_SUCCESS(status)) { |
786 appendTo.append(result); | 791 appendTo.append(result); |
787 if (pos.getField() == UDAT_TIMEZONE_FIELD) { | 792 if (pos.getField() == UDAT_TIMEZONE_FIELD) { |
788 pos.setBeginIndex(0); | 793 pos.setBeginIndex(0); |
789 pos.setEndIndex(result.length()); | 794 pos.setEndIndex(result.length()); |
790 } | 795 } |
791 } | 796 } |
792 } | 797 } |
793 } | 798 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 parsedOffset = offset; | 844 parsedOffset = offset; |
840 parsedPos = tmpPos.getIndex(); | 845 parsedPos = tmpPos.getIndex(); |
841 } | 846 } |
842 // Note: For now, no distinction between long/short localized GMT format
in the parser. | 847 // Note: For now, no distinction between long/short localized GMT format
in the parser. |
843 // This might be changed in future. | 848 // This might be changed in future. |
844 // evaluated |= (fallbackLocalizedGMT ? STYLE_PARSE_FLAGS[UTZFMT_STYLE_L
OCALIZED_GMT] : STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT]); | 849 // evaluated |= (fallbackLocalizedGMT ? STYLE_PARSE_FLAGS[UTZFMT_STYLE_L
OCALIZED_GMT] : STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT]); |
845 evaluated |= STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT] | STYLE_PARSE
_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT]; | 850 evaluated |= STYLE_PARSE_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT] | STYLE_PARSE
_FLAGS[UTZFMT_STYLE_LOCALIZED_GMT_SHORT]; |
846 } | 851 } |
847 | 852 |
848 UErrorCode status = U_ZERO_ERROR; | 853 UErrorCode status = U_ZERO_ERROR; |
849 UnicodeString tzID; | 854 UChar tzIDBuf[32]; |
| 855 UnicodeString tzID(tzIDBuf, 0, UPRV_LENGTHOF(tzIDBuf)); |
850 | 856 |
851 UBool parseTZDBAbbrev = ((parseOptions & UTZFMT_PARSE_OPTION_TZ_DATABASE_ABB
REVIATIONS) != 0); | 857 UBool parseTZDBAbbrev = ((parseOptions & UTZFMT_PARSE_OPTION_TZ_DATABASE_ABB
REVIATIONS) != 0); |
852 | 858 |
853 // Try the specified style | 859 // Try the specified style |
854 switch (style) { | 860 switch (style) { |
855 case UTZFMT_STYLE_LOCALIZED_GMT: | 861 case UTZFMT_STYLE_LOCALIZED_GMT: |
856 { | 862 { |
857 tmpPos.setIndex(startIdx); | 863 tmpPos.setIndex(startIdx); |
858 tmpPos.setErrorIndex(-1); | 864 tmpPos.setErrorIndex(-1); |
859 | 865 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 // zero format). Then, it tried to find a match within the set of displa
y names, but could not | 1094 // zero format). Then, it tried to find a match within the set of displa
y names, but could not |
1089 // find a match. At this point, we can safely assume the input text cont
ains the localized | 1095 // find a match. At this point, we can safely assume the input text cont
ains the localized |
1090 // GMT format. | 1096 // GMT format. |
1091 U_ASSERT(parsedOffset != UNKNOWN_OFFSET); | 1097 U_ASSERT(parsedOffset != UNKNOWN_OFFSET); |
1092 pos.setIndex(parsedPos); | 1098 pos.setIndex(parsedPos); |
1093 return createTimeZoneForOffset(parsedOffset); | 1099 return createTimeZoneForOffset(parsedOffset); |
1094 } | 1100 } |
1095 | 1101 |
1096 // Failed to parse the input text as the time zone format in the specified s
tyle. | 1102 // Failed to parse the input text as the time zone format in the specified s
tyle. |
1097 // Check the longest match among other styles below. | 1103 // Check the longest match among other styles below. |
1098 UnicodeString parsedID; | 1104 UChar parsedIDBuf[32]; |
| 1105 UnicodeString parsedID(parsedIDBuf, 0, UPRV_LENGTHOF(parsedIDBuf)); |
1099 UTimeZoneFormatTimeType parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN; | 1106 UTimeZoneFormatTimeType parsedTimeType = UTZFMT_TIME_TYPE_UNKNOWN; |
1100 | 1107 |
1101 U_ASSERT(parsedPos < 0); | 1108 U_ASSERT(parsedPos < 0); |
1102 U_ASSERT(parsedOffset == UNKNOWN_OFFSET); | 1109 U_ASSERT(parsedOffset == UNKNOWN_OFFSET); |
1103 | 1110 |
1104 // ISO 8601 | 1111 // ISO 8601 |
1105 if (parsedPos < maxPos && | 1112 if (parsedPos < maxPos && |
1106 ((evaluated & ISO_Z_STYLE_FLAG) == 0 || (evaluated & ISO_LOCAL_STYLE_FLA
G) == 0)) { | 1113 ((evaluated & ISO_Z_STYLE_FLAG) == 0 || (evaluated & ISO_LOCAL_STYLE_FLA
G) == 0)) { |
1107 tmpPos.setIndex(startIdx); | 1114 tmpPos.setIndex(startIdx); |
1108 tmpPos.setErrorIndex(-1); | 1115 tmpPos.setErrorIndex(-1); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 name.setToBogus(); | 1330 name.setToBogus(); |
1324 return name; | 1331 return name; |
1325 } | 1332 } |
1326 | 1333 |
1327 if (genType == UTZGNM_LOCATION) { | 1334 if (genType == UTZGNM_LOCATION) { |
1328 const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz); | 1335 const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz); |
1329 if (canonicalID == NULL) { | 1336 if (canonicalID == NULL) { |
1330 name.setToBogus(); | 1337 name.setToBogus(); |
1331 return name; | 1338 return name; |
1332 } | 1339 } |
1333 return gnames->getGenericLocationName(UnicodeString(canonicalID), name); | 1340 return gnames->getGenericLocationName(UnicodeString(TRUE, canonicalID, -
1), name); |
1334 } | 1341 } |
1335 return gnames->getDisplayName(tz, (UTimeZoneGenericNameType)genType, date, n
ame); | 1342 return gnames->getDisplayName(tz, (UTimeZoneGenericNameType)genType, date, n
ame); |
1336 } | 1343 } |
1337 | 1344 |
1338 UnicodeString& | 1345 UnicodeString& |
1339 TimeZoneFormat::formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UT
imeZoneNameType dstType, | 1346 TimeZoneFormat::formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UT
imeZoneNameType dstType, |
1340 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) cons
t { | 1347 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) cons
t { |
1341 if (fTimeZoneNames == NULL) { | 1348 if (fTimeZoneNames == NULL) { |
1342 name.setToBogus(); | 1349 name.setToBogus(); |
1343 return name; | 1350 return name; |
1344 } | 1351 } |
1345 | 1352 |
1346 UErrorCode status = U_ZERO_ERROR; | 1353 UErrorCode status = U_ZERO_ERROR; |
1347 UBool isDaylight = tz.inDaylightTime(date, status); | 1354 UBool isDaylight = tz.inDaylightTime(date, status); |
1348 const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz); | 1355 const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz); |
1349 | 1356 |
1350 if (U_FAILURE(status) || canonicalID == NULL) { | 1357 if (U_FAILURE(status) || canonicalID == NULL) { |
1351 name.setToBogus(); | 1358 name.setToBogus(); |
1352 return name; | 1359 return name; |
1353 } | 1360 } |
1354 | 1361 |
1355 if (isDaylight) { | 1362 if (isDaylight) { |
1356 fTimeZoneNames->getDisplayName(UnicodeString(canonicalID), dstType, date
, name); | 1363 fTimeZoneNames->getDisplayName(UnicodeString(TRUE, canonicalID, -1), dst
Type, date, name); |
1357 } else { | 1364 } else { |
1358 fTimeZoneNames->getDisplayName(UnicodeString(canonicalID), stdType, date
, name); | 1365 fTimeZoneNames->getDisplayName(UnicodeString(TRUE, canonicalID, -1), std
Type, date, name); |
1359 } | 1366 } |
1360 | 1367 |
1361 if (timeType && !name.isEmpty()) { | 1368 if (timeType && !name.isEmpty()) { |
1362 *timeType = isDaylight ? UTZFMT_TIME_TYPE_DAYLIGHT : UTZFMT_TIME_TYPE_ST
ANDARD; | 1369 *timeType = isDaylight ? UTZFMT_TIME_TYPE_DAYLIGHT : UTZFMT_TIME_TYPE_ST
ANDARD; |
1363 } | 1370 } |
1364 return name; | 1371 return name; |
1365 } | 1372 } |
1366 | 1373 |
1367 const TimeZoneGenericNames* | 1374 const TimeZoneGenericNames* |
1368 TimeZoneFormat::getTimeZoneGenericNames(UErrorCode& status) const { | 1375 TimeZoneFormat::getTimeZoneGenericNames(UErrorCode& status) const { |
(...skipping 27 matching lines...) Expand all Loading... |
1396 nonConstThis->fTZDBTimeZoneNames = tzdbNames; | 1403 nonConstThis->fTZDBTimeZoneNames = tzdbNames; |
1397 } | 1404 } |
1398 } | 1405 } |
1399 umtx_unlock(&gLock); | 1406 umtx_unlock(&gLock); |
1400 | 1407 |
1401 return fTZDBTimeZoneNames; | 1408 return fTZDBTimeZoneNames; |
1402 } | 1409 } |
1403 | 1410 |
1404 UnicodeString& | 1411 UnicodeString& |
1405 TimeZoneFormat::formatExemplarLocation(const TimeZone& tz, UnicodeString& name)
const { | 1412 TimeZoneFormat::formatExemplarLocation(const TimeZone& tz, UnicodeString& name)
const { |
1406 UnicodeString location; | 1413 UChar locationBuf[64]; |
| 1414 UnicodeString location(locationBuf, 0, UPRV_LENGTHOF(locationBuf)); |
1407 const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz); | 1415 const UChar* canonicalID = ZoneMeta::getCanonicalCLDRID(tz); |
1408 | 1416 |
1409 if (canonicalID) { | 1417 if (canonicalID) { |
1410 fTimeZoneNames->getExemplarLocationName(UnicodeString(canonicalID), loca
tion); | 1418 fTimeZoneNames->getExemplarLocationName(UnicodeString(TRUE, canonicalID,
-1), location); |
1411 } | 1419 } |
1412 if (location.length() > 0) { | 1420 if (location.length() > 0) { |
1413 name.setTo(location); | 1421 name.setTo(location); |
1414 } else { | 1422 } else { |
1415 // Use "unknown" location | 1423 // Use "unknown" location |
1416 fTimeZoneNames->getExemplarLocationName(UnicodeString(UNKNOWN_ZONE_ID),
location); | 1424 fTimeZoneNames->getExemplarLocationName(UnicodeString(TRUE, UNKNOWN_ZONE
_ID, -1), location); |
1417 if (location.length() > 0) { | 1425 if (location.length() > 0) { |
1418 name.setTo(location); | 1426 name.setTo(location); |
1419 } else { | 1427 } else { |
1420 // last resort | 1428 // last resort |
1421 name.setTo(UNKNOWN_LOCATION, -1); | 1429 name.setTo(UNKNOWN_LOCATION, -1); |
1422 } | 1430 } |
1423 } | 1431 } |
1424 return name; | 1432 return name; |
1425 } | 1433 } |
1426 | 1434 |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 } | 2402 } |
2395 UVector* result = new UVector(deleteGMTOffsetField, NULL, status); | 2403 UVector* result = new UVector(deleteGMTOffsetField, NULL, status); |
2396 if (result == NULL) { | 2404 if (result == NULL) { |
2397 status = U_MEMORY_ALLOCATION_ERROR; | 2405 status = U_MEMORY_ALLOCATION_ERROR; |
2398 return NULL; | 2406 return NULL; |
2399 } | 2407 } |
2400 | 2408 |
2401 int32_t checkBits = 0; | 2409 int32_t checkBits = 0; |
2402 UBool isPrevQuote = FALSE; | 2410 UBool isPrevQuote = FALSE; |
2403 UBool inQuote = FALSE; | 2411 UBool inQuote = FALSE; |
2404 UnicodeString text; | 2412 UChar textBuf[32]; |
| 2413 UnicodeString text(textBuf, 0, UPRV_LENGTHOF(textBuf)); |
2405 GMTOffsetField::FieldType itemType = GMTOffsetField::TEXT; | 2414 GMTOffsetField::FieldType itemType = GMTOffsetField::TEXT; |
2406 int32_t itemLength = 1; | 2415 int32_t itemLength = 1; |
2407 | 2416 |
2408 for (int32_t i = 0; i < pattern.length(); i++) { | 2417 for (int32_t i = 0; i < pattern.length(); i++) { |
2409 UChar ch = pattern.charAt(i); | 2418 UChar ch = pattern.charAt(i); |
2410 if (ch == SINGLEQUOTE) { | 2419 if (ch == SINGLEQUOTE) { |
2411 if (isPrevQuote) { | 2420 if (isPrevQuote) { |
2412 text.append(SINGLEQUOTE); | 2421 text.append(SINGLEQUOTE); |
2413 isPrevQuote = FALSE; | 2422 isPrevQuote = FALSE; |
2414 } else { | 2423 } else { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 start = str.moveIndex32(start, 1); | 2649 start = str.moveIndex32(start, 1); |
2641 } | 2650 } |
2642 | 2651 |
2643 return TRUE; | 2652 return TRUE; |
2644 } | 2653 } |
2645 | 2654 |
2646 TimeZone* | 2655 TimeZone* |
2647 TimeZoneFormat::createTimeZoneForOffset(int32_t offset) const { | 2656 TimeZoneFormat::createTimeZoneForOffset(int32_t offset) const { |
2648 if (offset == 0) { | 2657 if (offset == 0) { |
2649 // when offset is 0, we should use "Etc/GMT" | 2658 // when offset is 0, we should use "Etc/GMT" |
2650 return TimeZone::createTimeZone(UnicodeString(TZID_GMT)); | 2659 return TimeZone::createTimeZone(UnicodeString(TRUE, TZID_GMT, -1)); |
2651 } | 2660 } |
2652 return ZoneMeta::createCustomTimeZone(offset); | 2661 return ZoneMeta::createCustomTimeZone(offset); |
2653 } | 2662 } |
2654 | 2663 |
2655 UTimeZoneFormatTimeType | 2664 UTimeZoneFormatTimeType |
2656 TimeZoneFormat::getTimeType(UTimeZoneNameType nameType) { | 2665 TimeZoneFormat::getTimeType(UTimeZoneNameType nameType) { |
2657 switch (nameType) { | 2666 switch (nameType) { |
2658 case UTZNM_LONG_STANDARD: | 2667 case UTZNM_LONG_STANDARD: |
2659 case UTZNM_SHORT_STANDARD: | 2668 case UTZNM_SHORT_STANDARD: |
2660 return UTZFMT_TIME_TYPE_STANDARD; | 2669 return UTZFMT_TIME_TYPE_STANDARD; |
2661 | 2670 |
2662 case UTZNM_LONG_DAYLIGHT: | 2671 case UTZNM_LONG_DAYLIGHT: |
2663 case UTZNM_SHORT_DAYLIGHT: | 2672 case UTZNM_SHORT_DAYLIGHT: |
2664 return UTZFMT_TIME_TYPE_DAYLIGHT; | 2673 return UTZFMT_TIME_TYPE_DAYLIGHT; |
2665 | 2674 |
2666 default: | 2675 default: |
2667 return UTZFMT_TIME_TYPE_UNKNOWN; | 2676 return UTZFMT_TIME_TYPE_UNKNOWN; |
2668 } | 2677 } |
2669 } | 2678 } |
2670 | 2679 |
2671 UnicodeString& | 2680 UnicodeString& |
2672 TimeZoneFormat::getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches,
int32_t idx, UnicodeString& tzID) const { | 2681 TimeZoneFormat::getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches,
int32_t idx, UnicodeString& tzID) const { |
2673 if (!matches->getTimeZoneIDAt(idx, tzID)) { | 2682 if (!matches->getTimeZoneIDAt(idx, tzID)) { |
2674 UnicodeString mzID; | 2683 UChar mzIDBuf[32]; |
| 2684 UnicodeString mzID(mzIDBuf, 0, UPRV_LENGTHOF(mzIDBuf)); |
2675 if (matches->getMetaZoneIDAt(idx, mzID)) { | 2685 if (matches->getMetaZoneIDAt(idx, mzID)) { |
2676 fTimeZoneNames->getReferenceZoneID(mzID, fTargetRegion, tzID); | 2686 fTimeZoneNames->getReferenceZoneID(mzID, fTargetRegion, tzID); |
2677 } | 2687 } |
2678 } | 2688 } |
2679 return tzID; | 2689 return tzID; |
2680 } | 2690 } |
2681 | 2691 |
2682 | 2692 |
2683 class ZoneIdMatchHandler : public TextTrieMapSearchResultHandler { | 2693 class ZoneIdMatchHandler : public TextTrieMapSearchResultHandler { |
2684 public: | 2694 public: |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2855 if (tzID.length() == 0) { | 2865 if (tzID.length() == 0) { |
2856 pos.setErrorIndex(startIdx); | 2866 pos.setErrorIndex(startIdx); |
2857 } | 2867 } |
2858 | 2868 |
2859 return tzID; | 2869 return tzID; |
2860 } | 2870 } |
2861 | 2871 |
2862 U_NAMESPACE_END | 2872 U_NAMESPACE_END |
2863 | 2873 |
2864 #endif | 2874 #endif |
OLD | NEW |