From c56a20e796404f01aafb6b6777b47a831ad23e72 Mon Sep 17 00:00:00 2001 From: Peter Edberg Date: Fri, 27 Feb 2015 09:01:31 +0000 Subject: [PATCH] ICU-11539 C: Delete Calendar fields TIME_SEPARATOR, RELATED_YEAR; adjust accordingly X-SVN-Rev: 37091 --- icu4c/source/i18n/calendar.cpp | 5 +-- icu4c/source/i18n/gregocal.cpp | 3 +- icu4c/source/i18n/smpdtfmt.cpp | 44 +++++++++++++----------- icu4c/source/i18n/unicode/ucal.h | 15 -------- icu4c/source/i18n/unicode/udat.h | 2 +- icu4c/source/tools/toolutil/udbgutil.cpp | 3 +- 6 files changed, 28 insertions(+), 44 deletions(-) diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index b7d2d9fe7c3..d07269d75c8 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2014, International Business Machines Corporation and * +* Copyright (C) 1997-2015, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -30,7 +30,6 @@ #if !UCONFIG_NO_FORMATTING -#include "unicode/uchar.h" #include "unicode/gregocal.h" #include "unicode/basictz.h" #include "unicode/simpletz.h" @@ -638,7 +637,6 @@ static const int32_t kCalendarLimits[UCAL_FIELD_COUNT][4] = { { -0x7F000000, -0x7F000000, 0x7F000000, 0x7F000000 }, // JULIAN_DAY { 0, 0, 24*kOneHour-1, 24*kOneHour-1 }, // MILLISECONDS_IN_DAY { 0, 0, 1, 1 }, // IS_LEAP_MONTH - { UCHAR_MIN_VALUE, UCHAR_MIN_VALUE, UCHAR_MAX_VALUE, UCHAR_MAX_VALUE }, // TIME_SEPARATOR }; // Resource bundle tags read by this class @@ -2691,7 +2689,6 @@ int32_t Calendar::getLimit(UCalendarDateFields field, ELimitType limitType) cons case UCAL_JULIAN_DAY: case UCAL_MILLISECONDS_IN_DAY: case UCAL_IS_LEAP_MONTH: - case UCAL_TIME_SEPARATOR: return kCalendarLimits[field][limitType]; case UCAL_WEEK_OF_MONTH: diff --git a/icu4c/source/i18n/gregocal.cpp b/icu4c/source/i18n/gregocal.cpp index cab04712e81..5e98605bf92 100644 --- a/icu4c/source/i18n/gregocal.cpp +++ b/icu4c/source/i18n/gregocal.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2014, International Business Machines Corporation and +* Copyright (C) 1997-2015, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* * @@ -99,7 +99,6 @@ static const int32_t kGregorianCalendarLimits[UCAL_FIELD_COUNT][4] = { {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH - {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // TIME_SEPARATOR }; /* diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index d3f53c74274..9a7c107aeeb 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -139,9 +139,8 @@ static const UDateFormatField kTimeFields[] = { UDAT_HOUR0_FIELD, UDAT_MILLISECONDS_IN_DAY_FIELD, UDAT_TIMEZONE_RFC_FIELD, - UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD, - UDAT_TIME_SEPARATOR_FIELD }; -static const int8_t kTimeFieldsCount = 11; + UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD }; +static const int8_t kTimeFieldsCount = 10; // This is a pattern-of-last-resort used when we can't load a usable pattern out @@ -1076,12 +1075,11 @@ SimpleDateFormat::fgCalendarFieldToLevel[] = /*sS*/ 70, 80, /*z?Y*/ 0, 0, 10, /*eug*/ 30, 10, 0, - /*A?.*/ 40, 0, 0, - /*:*/ 0 + /*A?.*/ 40, 0, 0 }; int32_t SimpleDateFormat::getLevelFromChar(UChar ch) { - // Map calendar field LETTER into calendar field level. + // Map date field LETTER into calendar field level. // the larger the level, the smaller the field unit. // NOTE: if new fields adds in, the table needs to update. static const int32_t mapCharToLevel[] = { @@ -1166,7 +1164,7 @@ SimpleDateFormat::fgPatternIndexToCalendarField[] = /*O*/ UCAL_ZONE_OFFSET, /*Xx*/ UCAL_ZONE_OFFSET, UCAL_ZONE_OFFSET, /*r*/ UCAL_EXTENDED_YEAR, - /*:*/ UCAL_TIME_SEPARATOR, + /*:*/ UCAL_FIELD_COUNT, /* => no useful mapping to any calendar field */ }; // Map index into pattern character string to DateFormat field number @@ -1402,7 +1400,11 @@ SimpleDateFormat::subFormat(UnicodeString &appendTo, } UCalendarDateFields field = fgPatternIndexToCalendarField[patternCharIndex]; - int32_t value = (patternCharIndex != UDAT_RELATED_YEAR_FIELD)? cal.get(field, status): cal.getRelatedYear(status); + int32_t value = 0; + // Don't get value unless it is useful + if (field < UCAL_FIELD_COUNT) { + value = (patternCharIndex != UDAT_RELATED_YEAR_FIELD)? cal.get(field, status): cal.getRelatedYear(status); + } if (U_FAILURE(status)) { return; } @@ -2525,17 +2527,19 @@ int32_t SimpleDateFormat::matchString(const UnicodeString& text, } if (bestMatch >= 0) { - // Adjustment for Hebrew Calendar month Adar II - if (!strcmp(cal.getType(),"hebrew") && field==UCAL_MONTH && bestMatch==13) { - cal.set(field,6); - } else { - if (field == UCAL_YEAR) { - bestMatch++; // only get here for cyclic year names, which match 1-based years 1-60 + if (field < UCAL_FIELD_COUNT) { + // Adjustment for Hebrew Calendar month Adar II + if (!strcmp(cal.getType(),"hebrew") && field==UCAL_MONTH && bestMatch==13) { + cal.set(field,6); + } else { + if (field == UCAL_YEAR) { + bestMatch++; // only get here for cyclic year names, which match 1-based years 1-60 + } + cal.set(field, bestMatch); + } + if (monthPattern != NULL) { + cal.set(UCAL_IS_LEAP_MONTH, isLeapMonth); } - cal.set(field, bestMatch); - } - if (monthPattern != NULL) { - cal.set(UCAL_IS_LEAP_MONTH, isLeapMonth); } return start + bestMatchLength; @@ -2607,7 +2611,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC if (currentNumberFormat == NULL) { return -start; } - UCalendarDateFields field = fgPatternIndexToCalendarField[patternCharIndex]; + UCalendarDateFields field = fgPatternIndexToCalendarField[patternCharIndex]; // UCAL_FIELD_COUNT if irrelevant UnicodeString hebr("hebr", 4, US_INV); if (numericLeapMonthFormatter != NULL) { @@ -3234,7 +3238,7 @@ int32_t SimpleDateFormat::subParse(const UnicodeString& text, int32_t& start, UC data[count++].setTo(alt_sep); } - return matchString(text, start, UCAL_TIME_SEPARATOR, data, count, NULL, cal); + return matchString(text, start, UCAL_FIELD_COUNT /* => nothing to set */, data, count, NULL, cal); } default: diff --git a/icu4c/source/i18n/unicode/ucal.h b/icu4c/source/i18n/unicode/ucal.h index 9088b08483c..36828607099 100644 --- a/icu4c/source/i18n/unicode/ucal.h +++ b/icu4c/source/i18n/unicode/ucal.h @@ -423,21 +423,6 @@ enum UCalendarDateFields { */ UCAL_IS_LEAP_MONTH, -#ifndef U_HIDE_DRAFT_API - /** - * Field number indicating the separator between - * HOUR, MINUTE and SECOND. - * E.g., at 10:04 the TIME_SEPARATOR is :. - * @see #UCAL_HOUR - * @see #UCAL_MINUTE - * @see #UCAL_SECOND - * @draft ICU 55 - */ - UCAL_TIME_SEPARATOR, -#else - UCAL_TIME_SEPARATOR_HIDE_DRAFT_API, -#endif /* U_HIDE_DRAFT_API */ - /** * Field count * @stable ICU 2.6 diff --git a/icu4c/source/i18n/unicode/udat.h b/icu4c/source/i18n/unicode/udat.h index 2c0c120a24d..5add1516841 100644 --- a/icu4c/source/i18n/unicode/udat.h +++ b/icu4c/source/i18n/unicode/udat.h @@ -763,7 +763,7 @@ typedef enum UDateFormatField { #ifndef U_HIDE_DRAFT_API /** * FieldPosition and UFieldPosition selector for ':' time separator, - * corresponding to the UCAL_TIME_SEPARATOR field. + * no corresponding UCAL_ field. * @draft ICU 55 */ UDAT_TIME_SEPARATOR_FIELD = 35, diff --git a/icu4c/source/tools/toolutil/udbgutil.cpp b/icu4c/source/tools/toolutil/udbgutil.cpp index daeb48cce85..911425c1ade 100644 --- a/icu4c/source/tools/toolutil/udbgutil.cpp +++ b/icu4c/source/tools/toolutil/udbgutil.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2007-2014, International Business Machines Corporation and + * Copyright (c) 2007-2015, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -106,7 +106,6 @@ static const Field names_UCalendarDateFields[] = FIELD_NAME_STR( LEN_UCAL, UCAL_JULIAN_DAY ), FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECONDS_IN_DAY ), FIELD_NAME_STR( LEN_UCAL, UCAL_IS_LEAP_MONTH ), - FIELD_NAME_STR( LEN_UCAL, UCAL_TIME_SEPARATOR ), }; -- 2.40.0