aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/i18n/dtptngen.cpp
diff options
context:
space:
mode:
authormcheshkov <mcheshkov@yandex-team.ru>2022-02-10 16:46:16 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:16 +0300
commit1312621288956f199a5bd5342b0133d4395fa725 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/libs/icu/i18n/dtptngen.cpp
parente9d19cec64684c9c1e6b0c98297e5b895cf904fe (diff)
downloadydb-1312621288956f199a5bd5342b0133d4395fa725.tar.gz
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/icu/i18n/dtptngen.cpp')
-rw-r--r--contrib/libs/icu/i18n/dtptngen.cpp1786
1 files changed, 893 insertions, 893 deletions
diff --git a/contrib/libs/icu/i18n/dtptngen.cpp b/contrib/libs/icu/i18n/dtptngen.cpp
index 992b0a869b..02be4f054b 100644
--- a/contrib/libs/icu/i18n/dtptngen.cpp
+++ b/contrib/libs/icu/i18n/dtptngen.cpp
@@ -1,4 +1,4 @@
-// © 2016 and later: Unicode, Inc. and others.
+// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
@@ -18,7 +18,7 @@
#include "unicode/decimfmt.h"
#include "unicode/dtfmtsym.h"
#include "unicode/dtptngen.h"
-#include "unicode/localpointer.h"
+#include "unicode/localpointer.h"
#include "unicode/simpleformatter.h"
#include "unicode/smpdtfmt.h"
#include "unicode/udat.h"
@@ -28,7 +28,7 @@
#include "unicode/ures.h"
#include "unicode/ustring.h"
#include "unicode/rep.h"
-#include "unicode/region.h"
+#include "unicode/region.h"
#include "cpputils.h"
#include "mutex.h"
#include "umutex.h"
@@ -90,17 +90,17 @@ static void ures_a_open(UResourceBundleAIterator *aiter, UResourceBundle *bund,
aiter->num = ures_getSize(aiter->bund);
aiter->cursor = 0;
#if !defined(U_SORT_ASCII_BUNDLE_ITERATOR)
- aiter->entries = nullptr;
+ aiter->entries = nullptr;
#else
aiter->entries = (UResAEntry*)uprv_malloc(sizeof(UResAEntry)*aiter->num);
for(int i=0;i<aiter->num;i++) {
- aiter->entries[i].item = ures_getByIndex(aiter->bund, i, nullptr, status);
+ aiter->entries[i].item = ures_getByIndex(aiter->bund, i, nullptr, status);
const char *akey = ures_getKey(aiter->entries[i].item);
int32_t len = uprv_strlen(akey)+1;
aiter->entries[i].key = (UChar*)uprv_malloc(len*sizeof(UChar));
u_charsToUChars(akey, aiter->entries[i].key, len);
}
- uprv_sortArray(aiter->entries, aiter->num, sizeof(UResAEntry), ures_a_codepointSort, nullptr, TRUE, status);
+ uprv_sortArray(aiter->entries, aiter->num, sizeof(UResAEntry), ures_a_codepointSort, nullptr, TRUE, status);
#endif
}
@@ -117,7 +117,7 @@ static const UChar *ures_a_getNextString(UResourceBundleAIterator *aiter, int32_
#if !defined(U_SORT_ASCII_BUNDLE_ITERATOR)
return ures_getNextString(aiter->bund, len, key, err);
#else
- if(U_FAILURE(*err)) return nullptr;
+ if(U_FAILURE(*err)) return nullptr;
UResourceBundle *item = aiter->entries[aiter->cursor].item;
const UChar* ret = ures_getString(item, len, err);
*key = ures_getKey(item);
@@ -136,18 +136,18 @@ U_NAMESPACE_BEGIN
// class DateTimePatternGenerator
// *****************************************************************************
static const UChar Canonical_Items[] = {
- // GyQMwWEDFdaHmsSv
- CAP_G, LOW_Y, CAP_Q, CAP_M, LOW_W, CAP_W, CAP_E,
- CAP_D, CAP_F, LOW_D, LOW_A, // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
+ // GyQMwWEDFdaHmsSv
+ CAP_G, LOW_Y, CAP_Q, CAP_M, LOW_W, CAP_W, CAP_E,
+ CAP_D, CAP_F, LOW_D, LOW_A, // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
CAP_H, LOW_M, LOW_S, CAP_S, LOW_V, 0
};
static const dtTypeElem dtTypes[] = {
// patternChar, field, type, minLen, weight
{CAP_G, UDATPG_ERA_FIELD, DT_SHORT, 1, 3,},
- {CAP_G, UDATPG_ERA_FIELD, DT_LONG, 4, 0},
- {CAP_G, UDATPG_ERA_FIELD, DT_NARROW, 5, 0},
-
+ {CAP_G, UDATPG_ERA_FIELD, DT_LONG, 4, 0},
+ {CAP_G, UDATPG_ERA_FIELD, DT_NARROW, 5, 0},
+
{LOW_Y, UDATPG_YEAR_FIELD, DT_NUMERIC, 1, 20},
{CAP_Y, UDATPG_YEAR_FIELD, DT_NUMERIC + DT_DELTA, 1, 20},
{LOW_U, UDATPG_YEAR_FIELD, DT_NUMERIC + 2*DT_DELTA, 1, 20},
@@ -155,16 +155,16 @@ static const dtTypeElem dtTypes[] = {
{CAP_U, UDATPG_YEAR_FIELD, DT_SHORT, 1, 3},
{CAP_U, UDATPG_YEAR_FIELD, DT_LONG, 4, 0},
{CAP_U, UDATPG_YEAR_FIELD, DT_NARROW, 5, 0},
-
+
{CAP_Q, UDATPG_QUARTER_FIELD, DT_NUMERIC, 1, 2},
{CAP_Q, UDATPG_QUARTER_FIELD, DT_SHORT, 3, 0},
{CAP_Q, UDATPG_QUARTER_FIELD, DT_LONG, 4, 0},
- {CAP_Q, UDATPG_QUARTER_FIELD, DT_NARROW, 5, 0},
+ {CAP_Q, UDATPG_QUARTER_FIELD, DT_NARROW, 5, 0},
{LOW_Q, UDATPG_QUARTER_FIELD, DT_NUMERIC + DT_DELTA, 1, 2},
- {LOW_Q, UDATPG_QUARTER_FIELD, DT_SHORT - DT_DELTA, 3, 0},
- {LOW_Q, UDATPG_QUARTER_FIELD, DT_LONG - DT_DELTA, 4, 0},
- {LOW_Q, UDATPG_QUARTER_FIELD, DT_NARROW - DT_DELTA, 5, 0},
-
+ {LOW_Q, UDATPG_QUARTER_FIELD, DT_SHORT - DT_DELTA, 3, 0},
+ {LOW_Q, UDATPG_QUARTER_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {LOW_Q, UDATPG_QUARTER_FIELD, DT_NARROW - DT_DELTA, 5, 0},
+
{CAP_M, UDATPG_MONTH_FIELD, DT_NUMERIC, 1, 2},
{CAP_M, UDATPG_MONTH_FIELD, DT_SHORT, 3, 0},
{CAP_M, UDATPG_MONTH_FIELD, DT_LONG, 4, 0},
@@ -174,66 +174,66 @@ static const dtTypeElem dtTypes[] = {
{CAP_L, UDATPG_MONTH_FIELD, DT_LONG - DT_DELTA, 4, 0},
{CAP_L, UDATPG_MONTH_FIELD, DT_NARROW - DT_DELTA, 5, 0},
{LOW_L, UDATPG_MONTH_FIELD, DT_NUMERIC + DT_DELTA, 1, 1},
-
+
{LOW_W, UDATPG_WEEK_OF_YEAR_FIELD, DT_NUMERIC, 1, 2},
-
- {CAP_W, UDATPG_WEEK_OF_MONTH_FIELD, DT_NUMERIC, 1, 0},
-
+
+ {CAP_W, UDATPG_WEEK_OF_MONTH_FIELD, DT_NUMERIC, 1, 0},
+
{CAP_E, UDATPG_WEEKDAY_FIELD, DT_SHORT, 1, 3},
{CAP_E, UDATPG_WEEKDAY_FIELD, DT_LONG, 4, 0},
{CAP_E, UDATPG_WEEKDAY_FIELD, DT_NARROW, 5, 0},
- {CAP_E, UDATPG_WEEKDAY_FIELD, DT_SHORTER, 6, 0},
+ {CAP_E, UDATPG_WEEKDAY_FIELD, DT_SHORTER, 6, 0},
{LOW_C, UDATPG_WEEKDAY_FIELD, DT_NUMERIC + 2*DT_DELTA, 1, 2},
{LOW_C, UDATPG_WEEKDAY_FIELD, DT_SHORT - 2*DT_DELTA, 3, 0},
{LOW_C, UDATPG_WEEKDAY_FIELD, DT_LONG - 2*DT_DELTA, 4, 0},
{LOW_C, UDATPG_WEEKDAY_FIELD, DT_NARROW - 2*DT_DELTA, 5, 0},
- {LOW_C, UDATPG_WEEKDAY_FIELD, DT_SHORTER - 2*DT_DELTA, 6, 0},
+ {LOW_C, UDATPG_WEEKDAY_FIELD, DT_SHORTER - 2*DT_DELTA, 6, 0},
{LOW_E, UDATPG_WEEKDAY_FIELD, DT_NUMERIC + DT_DELTA, 1, 2}, // LOW_E is currently not used in CLDR data, should not be canonical
{LOW_E, UDATPG_WEEKDAY_FIELD, DT_SHORT - DT_DELTA, 3, 0},
{LOW_E, UDATPG_WEEKDAY_FIELD, DT_LONG - DT_DELTA, 4, 0},
{LOW_E, UDATPG_WEEKDAY_FIELD, DT_NARROW - DT_DELTA, 5, 0},
- {LOW_E, UDATPG_WEEKDAY_FIELD, DT_SHORTER - DT_DELTA, 6, 0},
-
+ {LOW_E, UDATPG_WEEKDAY_FIELD, DT_SHORTER - DT_DELTA, 6, 0},
+
{LOW_D, UDATPG_DAY_FIELD, DT_NUMERIC, 1, 2},
- {LOW_G, UDATPG_DAY_FIELD, DT_NUMERIC + DT_DELTA, 1, 20}, // really internal use, so we don't care
-
- {CAP_D, UDATPG_DAY_OF_YEAR_FIELD, DT_NUMERIC, 1, 3},
-
- {CAP_F, UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, DT_NUMERIC, 1, 0},
-
- {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_SHORT, 1, 3},
- {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_LONG, 4, 0},
- {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_NARROW, 5, 0},
- {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_SHORT - DT_DELTA, 1, 3},
- {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_LONG - DT_DELTA, 4, 0},
- {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_NARROW - DT_DELTA, 5, 0},
- // b needs to be closer to a than to B, so we make this 3*DT_DELTA
- {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_SHORT - 3*DT_DELTA, 1, 3},
- {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_LONG - 3*DT_DELTA, 4, 0},
- {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_NARROW - 3*DT_DELTA, 5, 0},
-
+ {LOW_G, UDATPG_DAY_FIELD, DT_NUMERIC + DT_DELTA, 1, 20}, // really internal use, so we don't care
+
+ {CAP_D, UDATPG_DAY_OF_YEAR_FIELD, DT_NUMERIC, 1, 3},
+
+ {CAP_F, UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD, DT_NUMERIC, 1, 0},
+
+ {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_SHORT, 1, 3},
+ {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_LONG, 4, 0},
+ {LOW_A, UDATPG_DAYPERIOD_FIELD, DT_NARROW, 5, 0},
+ {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_SHORT - DT_DELTA, 1, 3},
+ {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_LONG - DT_DELTA, 4, 0},
+ {LOW_B, UDATPG_DAYPERIOD_FIELD, DT_NARROW - DT_DELTA, 5, 0},
+ // b needs to be closer to a than to B, so we make this 3*DT_DELTA
+ {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_SHORT - 3*DT_DELTA, 1, 3},
+ {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_LONG - 3*DT_DELTA, 4, 0},
+ {CAP_B, UDATPG_DAYPERIOD_FIELD, DT_NARROW - 3*DT_DELTA, 5, 0},
+
{CAP_H, UDATPG_HOUR_FIELD, DT_NUMERIC + 10*DT_DELTA, 1, 2}, // 24 hour
{LOW_K, UDATPG_HOUR_FIELD, DT_NUMERIC + 11*DT_DELTA, 1, 2}, // 24 hour
{LOW_H, UDATPG_HOUR_FIELD, DT_NUMERIC, 1, 2}, // 12 hour
{CAP_K, UDATPG_HOUR_FIELD, DT_NUMERIC + DT_DELTA, 1, 2}, // 12 hour
- // The C code has had versions of the following 3, keep & update. Should not need these, but...
- // Without these, certain tests using e.g. staticGetSkeleton fail because j/J in patterns
- // get skipped instead of mapped to the right hour chars, for example in
- // DateFormatTest::TestPatternFromSkeleton
- // IntlTestDateTimePatternGeneratorAPI:: testStaticGetSkeleton
- // DateIntervalFormatTest::testTicket11985
- // Need to investigate better handling of jJC replacement e.g. in staticGetSkeleton.
- {CAP_J, UDATPG_HOUR_FIELD, DT_NUMERIC + 5*DT_DELTA, 1, 2}, // 12/24 hour no AM/PM
- {LOW_J, UDATPG_HOUR_FIELD, DT_NUMERIC + 6*DT_DELTA, 1, 6}, // 12/24 hour
- {CAP_C, UDATPG_HOUR_FIELD, DT_NUMERIC + 7*DT_DELTA, 1, 6}, // 12/24 hour with preferred dayPeriods for 12
-
+ // The C code has had versions of the following 3, keep & update. Should not need these, but...
+ // Without these, certain tests using e.g. staticGetSkeleton fail because j/J in patterns
+ // get skipped instead of mapped to the right hour chars, for example in
+ // DateFormatTest::TestPatternFromSkeleton
+ // IntlTestDateTimePatternGeneratorAPI:: testStaticGetSkeleton
+ // DateIntervalFormatTest::testTicket11985
+ // Need to investigate better handling of jJC replacement e.g. in staticGetSkeleton.
+ {CAP_J, UDATPG_HOUR_FIELD, DT_NUMERIC + 5*DT_DELTA, 1, 2}, // 12/24 hour no AM/PM
+ {LOW_J, UDATPG_HOUR_FIELD, DT_NUMERIC + 6*DT_DELTA, 1, 6}, // 12/24 hour
+ {CAP_C, UDATPG_HOUR_FIELD, DT_NUMERIC + 7*DT_DELTA, 1, 6}, // 12/24 hour with preferred dayPeriods for 12
+
{LOW_M, UDATPG_MINUTE_FIELD, DT_NUMERIC, 1, 2},
-
+
{LOW_S, UDATPG_SECOND_FIELD, DT_NUMERIC, 1, 2},
- {CAP_A, UDATPG_SECOND_FIELD, DT_NUMERIC + DT_DELTA, 1, 1000},
-
- {CAP_S, UDATPG_FRACTIONAL_SECOND_FIELD, DT_NUMERIC, 1, 1000},
-
+ {CAP_A, UDATPG_SECOND_FIELD, DT_NUMERIC + DT_DELTA, 1, 1000},
+
+ {CAP_S, UDATPG_FRACTIONAL_SECOND_FIELD, DT_NUMERIC, 1, 1000},
+
{LOW_V, UDATPG_ZONE_FIELD, DT_SHORT - 2*DT_DELTA, 1, 0},
{LOW_V, UDATPG_ZONE_FIELD, DT_LONG - 2*DT_DELTA, 4, 0},
{LOW_Z, UDATPG_ZONE_FIELD, DT_SHORT, 1, 3},
@@ -245,39 +245,39 @@ static const dtTypeElem dtTypes[] = {
{CAP_O, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 4, 0},
{CAP_V, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 1, 0},
{CAP_V, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 2, 0},
- {CAP_V, UDATPG_ZONE_FIELD, DT_LONG-1 - DT_DELTA, 3, 0},
- {CAP_V, UDATPG_ZONE_FIELD, DT_LONG-2 - DT_DELTA, 4, 0},
+ {CAP_V, UDATPG_ZONE_FIELD, DT_LONG-1 - DT_DELTA, 3, 0},
+ {CAP_V, UDATPG_ZONE_FIELD, DT_LONG-2 - DT_DELTA, 4, 0},
{CAP_X, UDATPG_ZONE_FIELD, DT_NARROW - DT_DELTA, 1, 0},
{CAP_X, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 2, 0},
{CAP_X, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 4, 0},
{LOW_X, UDATPG_ZONE_FIELD, DT_NARROW - DT_DELTA, 1, 0},
{LOW_X, UDATPG_ZONE_FIELD, DT_SHORT - DT_DELTA, 2, 0},
{LOW_X, UDATPG_ZONE_FIELD, DT_LONG - DT_DELTA, 4, 0},
-
+
{0, UDATPG_FIELD_COUNT, 0, 0, 0} , // last row of dtTypes[]
};
static const char* const CLDR_FIELD_APPEND[] = {
- "Era", "Year", "Quarter", "Month", "Week", "*", "Day-Of-Week",
- "*", "*", "Day", "*", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
+ "Era", "Year", "Quarter", "Month", "Week", "*", "Day-Of-Week",
+ "*", "*", "Day", "*", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
"Hour", "Minute", "Second", "*", "Timezone"
};
-static const char* const CLDR_FIELD_NAME[UDATPG_FIELD_COUNT] = {
- "era", "year", "quarter", "month", "week", "weekOfMonth", "weekday",
- "dayOfYear", "weekdayOfMonth", "day", "dayperiod", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
+static const char* const CLDR_FIELD_NAME[UDATPG_FIELD_COUNT] = {
+ "era", "year", "quarter", "month", "week", "weekOfMonth", "weekday",
+ "dayOfYear", "weekdayOfMonth", "day", "dayperiod", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
"hour", "minute", "second", "*", "zone"
};
-static const char* const CLDR_FIELD_WIDTH[] = { // [UDATPG_WIDTH_COUNT]
- "", "-short", "-narrow"
-};
-
-// TODO(ticket:13619): remove when definition uncommented in dtptngen.h.
-static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
-static constexpr UDateTimePGDisplayWidth UDATPG_WIDTH_APPENDITEM = UDATPG_WIDE;
-static constexpr int32_t UDATPG_FIELD_KEY_MAX = 24; // max length of CLDR field tag (type + width)
-
+static const char* const CLDR_FIELD_WIDTH[] = { // [UDATPG_WIDTH_COUNT]
+ "", "-short", "-narrow"
+};
+
+// TODO(ticket:13619): remove when definition uncommented in dtptngen.h.
+static const int32_t UDATPG_WIDTH_COUNT = UDATPG_NARROW + 1;
+static constexpr UDateTimePGDisplayWidth UDATPG_WIDTH_APPENDITEM = UDATPG_WIDE;
+static constexpr int32_t UDATPG_FIELD_KEY_MAX = 24; // max length of CLDR field tag (type + width)
+
// For appendItems
static const UChar UDATPG_ItemFormat[]= {0x7B, 0x30, 0x7D, 0x20, 0x251C, 0x7B, 0x32, 0x7D, 0x3A,
0x20, 0x7B, 0x31, 0x7D, 0x2524, 0}; // {0} \u251C{2}: {1}\u2524
@@ -304,50 +304,50 @@ DateTimePatternGenerator::createInstance(UErrorCode& status) {
DateTimePatternGenerator* U_EXPORT2
DateTimePatternGenerator::createInstance(const Locale& locale, UErrorCode& status) {
if (U_FAILURE(status)) {
- return nullptr;
+ return nullptr;
}
LocalPointer<DateTimePatternGenerator> result(
new DateTimePatternGenerator(locale, status), status);
- return U_SUCCESS(status) ? result.orphan() : nullptr;
+ return U_SUCCESS(status) ? result.orphan() : nullptr;
}
DateTimePatternGenerator* U_EXPORT2
DateTimePatternGenerator::createEmptyInstance(UErrorCode& status) {
if (U_FAILURE(status)) {
- return nullptr;
+ return nullptr;
}
- LocalPointer<DateTimePatternGenerator> result(
- new DateTimePatternGenerator(status), status);
- return U_SUCCESS(status) ? result.orphan() : nullptr;
+ LocalPointer<DateTimePatternGenerator> result(
+ new DateTimePatternGenerator(status), status);
+ return U_SUCCESS(status) ? result.orphan() : nullptr;
}
DateTimePatternGenerator::DateTimePatternGenerator(UErrorCode &status) :
- skipMatcher(nullptr),
- fAvailableFormatKeyHash(nullptr),
- fDefaultHourFormatChar(0),
- internalErrorCode(U_ZERO_ERROR)
+ skipMatcher(nullptr),
+ fAvailableFormatKeyHash(nullptr),
+ fDefaultHourFormatChar(0),
+ internalErrorCode(U_ZERO_ERROR)
{
fp = new FormatParser();
dtMatcher = new DateTimeMatcher();
distanceInfo = new DistanceInfo();
patternMap = new PatternMap();
- if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
- internalErrorCode = status = U_MEMORY_ALLOCATION_ERROR;
+ if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
+ internalErrorCode = status = U_MEMORY_ALLOCATION_ERROR;
}
}
DateTimePatternGenerator::DateTimePatternGenerator(const Locale& locale, UErrorCode &status) :
- skipMatcher(nullptr),
- fAvailableFormatKeyHash(nullptr),
- fDefaultHourFormatChar(0),
- internalErrorCode(U_ZERO_ERROR)
+ skipMatcher(nullptr),
+ fAvailableFormatKeyHash(nullptr),
+ fDefaultHourFormatChar(0),
+ internalErrorCode(U_ZERO_ERROR)
{
fp = new FormatParser();
dtMatcher = new DateTimeMatcher();
distanceInfo = new DistanceInfo();
patternMap = new PatternMap();
- if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
- internalErrorCode = status = U_MEMORY_ALLOCATION_ERROR;
+ if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
+ internalErrorCode = status = U_MEMORY_ALLOCATION_ERROR;
}
else {
initData(locale, status);
@@ -356,18 +356,18 @@ DateTimePatternGenerator::DateTimePatternGenerator(const Locale& locale, UErrorC
DateTimePatternGenerator::DateTimePatternGenerator(const DateTimePatternGenerator& other) :
UObject(),
- skipMatcher(nullptr),
- fAvailableFormatKeyHash(nullptr),
- fDefaultHourFormatChar(0),
- internalErrorCode(U_ZERO_ERROR)
+ skipMatcher(nullptr),
+ fAvailableFormatKeyHash(nullptr),
+ fDefaultHourFormatChar(0),
+ internalErrorCode(U_ZERO_ERROR)
{
fp = new FormatParser();
dtMatcher = new DateTimeMatcher();
distanceInfo = new DistanceInfo();
patternMap = new PatternMap();
- if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
- internalErrorCode = U_MEMORY_ALLOCATION_ERROR;
- }
+ if (fp == nullptr || dtMatcher == nullptr || distanceInfo == nullptr || patternMap == nullptr) {
+ internalErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ }
*this=other;
}
@@ -377,7 +377,7 @@ DateTimePatternGenerator::operator=(const DateTimePatternGenerator& other) {
if (&other == this) {
return *this;
}
- internalErrorCode = other.internalErrorCode;
+ internalErrorCode = other.internalErrorCode;
pLocale = other.pLocale;
fDefaultHourFormatChar = other.fDefaultHourFormatChar;
*fp = *(other.fp);
@@ -389,27 +389,27 @@ DateTimePatternGenerator::operator=(const DateTimePatternGenerator& other) {
dateTimeFormat.getTerminatedBuffer();
decimal.getTerminatedBuffer();
delete skipMatcher;
- if ( other.skipMatcher == nullptr ) {
- skipMatcher = nullptr;
+ if ( other.skipMatcher == nullptr ) {
+ skipMatcher = nullptr;
}
else {
skipMatcher = new DateTimeMatcher(*other.skipMatcher);
- if (skipMatcher == nullptr)
- {
- internalErrorCode = U_MEMORY_ALLOCATION_ERROR;
- return *this;
- }
+ if (skipMatcher == nullptr)
+ {
+ internalErrorCode = U_MEMORY_ALLOCATION_ERROR;
+ return *this;
+ }
}
for (int32_t i=0; i< UDATPG_FIELD_COUNT; ++i ) {
appendItemFormats[i] = other.appendItemFormats[i];
- appendItemFormats[i].getTerminatedBuffer(); // NUL-terminate for the C API.
- for (int32_t j=0; j< UDATPG_WIDTH_COUNT; ++j ) {
- fieldDisplayNames[i][j] = other.fieldDisplayNames[i][j];
- fieldDisplayNames[i][j].getTerminatedBuffer(); // NUL-terminate for the C API.
- }
- }
- patternMap->copyFrom(*other.patternMap, internalErrorCode);
- copyHashtable(other.fAvailableFormatKeyHash, internalErrorCode);
+ appendItemFormats[i].getTerminatedBuffer(); // NUL-terminate for the C API.
+ for (int32_t j=0; j< UDATPG_WIDTH_COUNT; ++j ) {
+ fieldDisplayNames[i][j] = other.fieldDisplayNames[i][j];
+ fieldDisplayNames[i][j].getTerminatedBuffer(); // NUL-terminate for the C API.
+ }
+ }
+ patternMap->copyFrom(*other.patternMap, internalErrorCode);
+ copyHashtable(other.fAvailableFormatKeyHash, internalErrorCode);
return *this;
}
@@ -422,14 +422,14 @@ DateTimePatternGenerator::operator==(const DateTimePatternGenerator& other) cons
if ((pLocale==other.pLocale) && (patternMap->equals(*other.patternMap)) &&
(dateTimeFormat==other.dateTimeFormat) && (decimal==other.decimal)) {
for ( int32_t i=0 ; i<UDATPG_FIELD_COUNT; ++i ) {
- if (appendItemFormats[i] != other.appendItemFormats[i]) {
- return FALSE;
- }
- for (int32_t j=0; j< UDATPG_WIDTH_COUNT; ++j ) {
- if (fieldDisplayNames[i][j] != other.fieldDisplayNames[i][j]) {
- return FALSE;
- }
- }
+ if (appendItemFormats[i] != other.appendItemFormats[i]) {
+ return FALSE;
+ }
+ for (int32_t j=0; j< UDATPG_WIDTH_COUNT; ++j ) {
+ if (fieldDisplayNames[i][j] != other.fieldDisplayNames[i][j]) {
+ return FALSE;
+ }
+ }
}
return TRUE;
}
@@ -444,21 +444,21 @@ DateTimePatternGenerator::operator!=(const DateTimePatternGenerator& other) cons
}
DateTimePatternGenerator::~DateTimePatternGenerator() {
- if (fAvailableFormatKeyHash!=nullptr) {
+ if (fAvailableFormatKeyHash!=nullptr) {
delete fAvailableFormatKeyHash;
}
- if (fp != nullptr) delete fp;
- if (dtMatcher != nullptr) delete dtMatcher;
- if (distanceInfo != nullptr) delete distanceInfo;
- if (patternMap != nullptr) delete patternMap;
- if (skipMatcher != nullptr) delete skipMatcher;
+ if (fp != nullptr) delete fp;
+ if (dtMatcher != nullptr) delete dtMatcher;
+ if (distanceInfo != nullptr) delete distanceInfo;
+ if (patternMap != nullptr) delete patternMap;
+ if (skipMatcher != nullptr) delete skipMatcher;
}
namespace {
UInitOnce initOnce = U_INITONCE_INITIALIZER;
-UHashtable *localeToAllowedHourFormatsMap = nullptr;
+UHashtable *localeToAllowedHourFormatsMap = nullptr;
// Value deleter for hashmap.
U_CFUNC void U_CALLCONV deleteAllowedHourFormats(void *ptr) {
@@ -475,13 +475,13 @@ enum AllowedHourFormat{
ALLOWED_HOUR_FORMAT_UNKNOWN = -1,
ALLOWED_HOUR_FORMAT_h,
ALLOWED_HOUR_FORMAT_H,
- ALLOWED_HOUR_FORMAT_K, // Added ICU-20383, used by JP
- ALLOWED_HOUR_FORMAT_k, // Added ICU-20383, not currently used
+ ALLOWED_HOUR_FORMAT_K, // Added ICU-20383, used by JP
+ ALLOWED_HOUR_FORMAT_k, // Added ICU-20383, not currently used
ALLOWED_HOUR_FORMAT_hb,
- ALLOWED_HOUR_FORMAT_hB,
- ALLOWED_HOUR_FORMAT_Kb, // Added ICU-20383, not currently used
- ALLOWED_HOUR_FORMAT_KB, // Added ICU-20383, not currently used
- // ICU-20383 The following are unlikely and not currently used
+ ALLOWED_HOUR_FORMAT_hB,
+ ALLOWED_HOUR_FORMAT_Kb, // Added ICU-20383, not currently used
+ ALLOWED_HOUR_FORMAT_KB, // Added ICU-20383, not currently used
+ // ICU-20383 The following are unlikely and not currently used
ALLOWED_HOUR_FORMAT_Hb,
ALLOWED_HOUR_FORMAT_HB
};
@@ -492,8 +492,8 @@ void
DateTimePatternGenerator::initData(const Locale& locale, UErrorCode &status) {
//const char *baseLangName = locale.getBaseName(); // unused
- skipMatcher = nullptr;
- fAvailableFormatKeyHash=nullptr;
+ skipMatcher = nullptr;
+ fAvailableFormatKeyHash=nullptr;
addCanonicalItems(status);
addICUPatterns(locale, status);
addCLDRData(locale, status);
@@ -501,8 +501,8 @@ DateTimePatternGenerator::initData(const Locale& locale, UErrorCode &status) {
setDecimalSymbols(locale, status);
umtx_initOnce(initOnce, loadAllowedHourFormatsData, status);
getAllowedHourFormats(locale, status);
- // If any of the above methods failed then the object is in an invalid state.
- internalErrorCode = status;
+ // If any of the above methods failed then the object is in an invalid state.
+ internalErrorCode = status;
} // DateTimePatternGenerator::initData
namespace {
@@ -520,69 +520,69 @@ struct AllowedHourFormatsSink : public ResourceSink {
const char *regionOrLocale = key;
ResourceTable formatList = value.getTable(errorCode);
if (U_FAILURE(errorCode)) { return; }
- // below we construct a list[] that has an entry for the "preferred" value at [0],
- // followed by 1 or more entries for the "allowed" values, terminated with an
- // entry for ALLOWED_HOUR_FORMAT_UNKNOWN (not included in length below)
- LocalMemory<int32_t> list;
- int32_t length = 0;
- int32_t preferredFormat = ALLOWED_HOUR_FORMAT_UNKNOWN;
+ // below we construct a list[] that has an entry for the "preferred" value at [0],
+ // followed by 1 or more entries for the "allowed" values, terminated with an
+ // entry for ALLOWED_HOUR_FORMAT_UNKNOWN (not included in length below)
+ LocalMemory<int32_t> list;
+ int32_t length = 0;
+ int32_t preferredFormat = ALLOWED_HOUR_FORMAT_UNKNOWN;
for (int32_t j = 0; formatList.getKeyAndValue(j, key, value); ++j) {
- if (uprv_strcmp(key, "allowed") == 0) {
+ if (uprv_strcmp(key, "allowed") == 0) {
if (value.getType() == URES_STRING) {
- length = 2; // 1 preferred to add later, 1 allowed to add now
- if (list.allocateInsteadAndReset(length + 1) == nullptr) {
+ length = 2; // 1 preferred to add later, 1 allowed to add now
+ if (list.allocateInsteadAndReset(length + 1) == nullptr) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
- list[1] = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
+ list[1] = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
}
else {
ResourceArray allowedFormats = value.getArray(errorCode);
- length = allowedFormats.getSize() + 1; // 1 preferred, getSize allowed
- if (list.allocateInsteadAndReset(length + 1) == nullptr) {
+ length = allowedFormats.getSize() + 1; // 1 preferred, getSize allowed
+ if (list.allocateInsteadAndReset(length + 1) == nullptr) {
errorCode = U_MEMORY_ALLOCATION_ERROR;
return;
}
- for (int32_t k = 1; k < length; ++k) {
- allowedFormats.getValue(k-1, value);
+ for (int32_t k = 1; k < length; ++k) {
+ allowedFormats.getValue(k-1, value);
list[k] = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
}
}
- } else if (uprv_strcmp(key, "preferred") == 0) {
- preferredFormat = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
+ } else if (uprv_strcmp(key, "preferred") == 0) {
+ preferredFormat = getHourFormatFromUnicodeString(value.getUnicodeString(errorCode));
}
}
- if (length > 1) {
- list[0] = (preferredFormat!=ALLOWED_HOUR_FORMAT_UNKNOWN)? preferredFormat: list[1];
- } else {
- // fallback handling for missing data
- length = 2; // 1 preferred, 1 allowed
- if (list.allocateInsteadAndReset(length + 1) == nullptr) {
- errorCode = U_MEMORY_ALLOCATION_ERROR;
- return;
- }
- list[0] = (preferredFormat!=ALLOWED_HOUR_FORMAT_UNKNOWN)? preferredFormat: ALLOWED_HOUR_FORMAT_H;
- list[1] = list[0];
- }
- list[length] = ALLOWED_HOUR_FORMAT_UNKNOWN;
- // At this point list[] will have at least two non-ALLOWED_HOUR_FORMAT_UNKNOWN entries,
- // followed by ALLOWED_HOUR_FORMAT_UNKNOWN.
- uhash_put(localeToAllowedHourFormatsMap, const_cast<char *>(regionOrLocale), list.orphan(), &errorCode);
- if (U_FAILURE(errorCode)) { return; }
- }
- }
-
- AllowedHourFormat getHourFormatFromUnicodeString(const UnicodeString &s) {
+ if (length > 1) {
+ list[0] = (preferredFormat!=ALLOWED_HOUR_FORMAT_UNKNOWN)? preferredFormat: list[1];
+ } else {
+ // fallback handling for missing data
+ length = 2; // 1 preferred, 1 allowed
+ if (list.allocateInsteadAndReset(length + 1) == nullptr) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ list[0] = (preferredFormat!=ALLOWED_HOUR_FORMAT_UNKNOWN)? preferredFormat: ALLOWED_HOUR_FORMAT_H;
+ list[1] = list[0];
+ }
+ list[length] = ALLOWED_HOUR_FORMAT_UNKNOWN;
+ // At this point list[] will have at least two non-ALLOWED_HOUR_FORMAT_UNKNOWN entries,
+ // followed by ALLOWED_HOUR_FORMAT_UNKNOWN.
+ uhash_put(localeToAllowedHourFormatsMap, const_cast<char *>(regionOrLocale), list.orphan(), &errorCode);
+ if (U_FAILURE(errorCode)) { return; }
+ }
+ }
+
+ AllowedHourFormat getHourFormatFromUnicodeString(const UnicodeString &s) {
if (s.length() == 1) {
if (s[0] == LOW_H) { return ALLOWED_HOUR_FORMAT_h; }
if (s[0] == CAP_H) { return ALLOWED_HOUR_FORMAT_H; }
- if (s[0] == CAP_K) { return ALLOWED_HOUR_FORMAT_K; }
- if (s[0] == LOW_K) { return ALLOWED_HOUR_FORMAT_k; }
+ if (s[0] == CAP_K) { return ALLOWED_HOUR_FORMAT_K; }
+ if (s[0] == LOW_K) { return ALLOWED_HOUR_FORMAT_k; }
} else if (s.length() == 2) {
if (s[0] == LOW_H && s[1] == LOW_B) { return ALLOWED_HOUR_FORMAT_hb; }
- if (s[0] == LOW_H && s[1] == CAP_B) { return ALLOWED_HOUR_FORMAT_hB; }
- if (s[0] == CAP_K && s[1] == LOW_B) { return ALLOWED_HOUR_FORMAT_Kb; }
- if (s[0] == CAP_K && s[1] == CAP_B) { return ALLOWED_HOUR_FORMAT_KB; }
+ if (s[0] == LOW_H && s[1] == CAP_B) { return ALLOWED_HOUR_FORMAT_hB; }
+ if (s[0] == CAP_K && s[1] == LOW_B) { return ALLOWED_HOUR_FORMAT_Kb; }
+ if (s[0] == CAP_K && s[1] == CAP_B) { return ALLOWED_HOUR_FORMAT_KB; }
if (s[0] == CAP_H && s[1] == LOW_B) { return ALLOWED_HOUR_FORMAT_Hb; }
if (s[0] == CAP_H && s[1] == CAP_B) { return ALLOWED_HOUR_FORMAT_HB; }
}
@@ -598,15 +598,15 @@ AllowedHourFormatsSink::~AllowedHourFormatsSink() {}
U_CFUNC void U_CALLCONV DateTimePatternGenerator::loadAllowedHourFormatsData(UErrorCode &status) {
if (U_FAILURE(status)) { return; }
localeToAllowedHourFormatsMap = uhash_open(
- uhash_hashChars, uhash_compareChars, nullptr, &status);
- if (U_FAILURE(status)) { return; }
-
+ uhash_hashChars, uhash_compareChars, nullptr, &status);
+ if (U_FAILURE(status)) { return; }
+
uhash_setValueDeleter(localeToAllowedHourFormatsMap, deleteAllowedHourFormats);
- ucln_i18n_registerCleanup(UCLN_I18N_ALLOWED_HOUR_FORMATS, allowedHourFormatsCleanup);
+ ucln_i18n_registerCleanup(UCLN_I18N_ALLOWED_HOUR_FORMATS, allowedHourFormatsCleanup);
+
+ LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "supplementalData", &status));
+ if (U_FAILURE(status)) { return; }
- LocalUResourceBundlePointer rb(ures_openDirect(nullptr, "supplementalData", &status));
- if (U_FAILURE(status)) { return; }
-
AllowedHourFormatsSink sink;
// TODO: Currently in the enumeration each table allocates a new array.
// Try to reduce the number of memory allocations. Consider storing a
@@ -614,136 +614,136 @@ U_CFUNC void U_CALLCONV DateTimePatternGenerator::loadAllowedHourFormatsData(UEr
// into the hashmap, store 6 single-value sub-arrays right at the beginning of the
// vector (at index enum*2) for easy data sharing, copy sub-arrays into runtime
// object. Remember to clean up the vector, too.
- ures_getAllItemsWithFallback(rb.getAlias(), "timeData", sink, status);
-}
-
-static int32_t* getAllowedHourFormatsLangCountry(const char* language, const char* country, UErrorCode& status) {
- CharString langCountry;
- langCountry.append(language, status);
- langCountry.append('_', status);
- langCountry.append(country, status);
-
- int32_t* allowedFormats;
- allowedFormats = (int32_t *)uhash_get(localeToAllowedHourFormatsMap, langCountry.data());
- if (allowedFormats == nullptr) {
- allowedFormats = (int32_t *)uhash_get(localeToAllowedHourFormatsMap, const_cast<char *>(country));
- }
-
- return allowedFormats;
+ ures_getAllItemsWithFallback(rb.getAlias(), "timeData", sink, status);
+}
+
+static int32_t* getAllowedHourFormatsLangCountry(const char* language, const char* country, UErrorCode& status) {
+ CharString langCountry;
+ langCountry.append(language, status);
+ langCountry.append('_', status);
+ langCountry.append(country, status);
+
+ int32_t* allowedFormats;
+ allowedFormats = (int32_t *)uhash_get(localeToAllowedHourFormatsMap, langCountry.data());
+ if (allowedFormats == nullptr) {
+ allowedFormats = (int32_t *)uhash_get(localeToAllowedHourFormatsMap, const_cast<char *>(country));
+ }
+
+ return allowedFormats;
}
void DateTimePatternGenerator::getAllowedHourFormats(const Locale &locale, UErrorCode &status) {
if (U_FAILURE(status)) { return; }
-
- const char *language = locale.getLanguage();
- const char *country = locale.getCountry();
- Locale maxLocale; // must be here for correct lifetime
- if (*language == '\0' || *country == '\0') {
- maxLocale = locale;
- UErrorCode localStatus = U_ZERO_ERROR;
- maxLocale.addLikelySubtags(localStatus);
- if (U_SUCCESS(localStatus)) {
- language = maxLocale.getLanguage();
- country = maxLocale.getCountry();
- }
- }
- if (*language == '\0') {
- // Unexpected, but fail gracefully
- language = "und";
- }
- if (*country == '\0') {
- country = "001";
- }
-
- int32_t* allowedFormats = getAllowedHourFormatsLangCountry(language, country, status);
-
- // We need to check if there is an hour cycle on locale
- char buffer[8];
- int32_t count = locale.getKeywordValue("hours", buffer, sizeof(buffer), status);
-
- fDefaultHourFormatChar = 0;
- if (U_SUCCESS(status) && count > 0) {
- if(uprv_strcmp(buffer, "h24") == 0) {
- fDefaultHourFormatChar = LOW_K;
- } else if(uprv_strcmp(buffer, "h23") == 0) {
- fDefaultHourFormatChar = CAP_H;
- } else if(uprv_strcmp(buffer, "h12") == 0) {
- fDefaultHourFormatChar = LOW_H;
- } else if(uprv_strcmp(buffer, "h11") == 0) {
- fDefaultHourFormatChar = CAP_K;
- }
- }
-
- // Check if the region has an alias
- if (allowedFormats == nullptr) {
- UErrorCode localStatus = U_ZERO_ERROR;
- const Region* region = Region::getInstance(country, localStatus);
- if (U_SUCCESS(localStatus)) {
- country = region->getRegionCode(); // the real region code
- allowedFormats = getAllowedHourFormatsLangCountry(language, country, status);
- }
- }
-
- if (allowedFormats != nullptr) { // Lookup is successful
- // Here allowedFormats points to a list consisting of key for preferredFormat,
- // followed by one or more keys for allowedFormats, then followed by ALLOWED_HOUR_FORMAT_UNKNOWN.
- if (!fDefaultHourFormatChar) {
- switch (allowedFormats[0]) {
- case ALLOWED_HOUR_FORMAT_h: fDefaultHourFormatChar = LOW_H; break;
- case ALLOWED_HOUR_FORMAT_H: fDefaultHourFormatChar = CAP_H; break;
- case ALLOWED_HOUR_FORMAT_K: fDefaultHourFormatChar = CAP_K; break;
- case ALLOWED_HOUR_FORMAT_k: fDefaultHourFormatChar = LOW_K; break;
- default: fDefaultHourFormatChar = CAP_H; break;
- }
- }
-
+
+ const char *language = locale.getLanguage();
+ const char *country = locale.getCountry();
+ Locale maxLocale; // must be here for correct lifetime
+ if (*language == '\0' || *country == '\0') {
+ maxLocale = locale;
+ UErrorCode localStatus = U_ZERO_ERROR;
+ maxLocale.addLikelySubtags(localStatus);
+ if (U_SUCCESS(localStatus)) {
+ language = maxLocale.getLanguage();
+ country = maxLocale.getCountry();
+ }
+ }
+ if (*language == '\0') {
+ // Unexpected, but fail gracefully
+ language = "und";
+ }
+ if (*country == '\0') {
+ country = "001";
+ }
+
+ int32_t* allowedFormats = getAllowedHourFormatsLangCountry(language, country, status);
+
+ // We need to check if there is an hour cycle on locale
+ char buffer[8];
+ int32_t count = locale.getKeywordValue("hours", buffer, sizeof(buffer), status);
+
+ fDefaultHourFormatChar = 0;
+ if (U_SUCCESS(status) && count > 0) {
+ if(uprv_strcmp(buffer, "h24") == 0) {
+ fDefaultHourFormatChar = LOW_K;
+ } else if(uprv_strcmp(buffer, "h23") == 0) {
+ fDefaultHourFormatChar = CAP_H;
+ } else if(uprv_strcmp(buffer, "h12") == 0) {
+ fDefaultHourFormatChar = LOW_H;
+ } else if(uprv_strcmp(buffer, "h11") == 0) {
+ fDefaultHourFormatChar = CAP_K;
+ }
+ }
+
+ // Check if the region has an alias
+ if (allowedFormats == nullptr) {
+ UErrorCode localStatus = U_ZERO_ERROR;
+ const Region* region = Region::getInstance(country, localStatus);
+ if (U_SUCCESS(localStatus)) {
+ country = region->getRegionCode(); // the real region code
+ allowedFormats = getAllowedHourFormatsLangCountry(language, country, status);
+ }
+ }
+
+ if (allowedFormats != nullptr) { // Lookup is successful
+ // Here allowedFormats points to a list consisting of key for preferredFormat,
+ // followed by one or more keys for allowedFormats, then followed by ALLOWED_HOUR_FORMAT_UNKNOWN.
+ if (!fDefaultHourFormatChar) {
+ switch (allowedFormats[0]) {
+ case ALLOWED_HOUR_FORMAT_h: fDefaultHourFormatChar = LOW_H; break;
+ case ALLOWED_HOUR_FORMAT_H: fDefaultHourFormatChar = CAP_H; break;
+ case ALLOWED_HOUR_FORMAT_K: fDefaultHourFormatChar = CAP_K; break;
+ case ALLOWED_HOUR_FORMAT_k: fDefaultHourFormatChar = LOW_K; break;
+ default: fDefaultHourFormatChar = CAP_H; break;
+ }
+ }
+
for (int32_t i = 0; i < UPRV_LENGTHOF(fAllowedHourFormats); ++i) {
- fAllowedHourFormats[i] = allowedFormats[i + 1];
- if (fAllowedHourFormats[i] == ALLOWED_HOUR_FORMAT_UNKNOWN) {
+ fAllowedHourFormats[i] = allowedFormats[i + 1];
+ if (fAllowedHourFormats[i] == ALLOWED_HOUR_FORMAT_UNKNOWN) {
break;
}
}
} else { // Lookup failed, twice
- if (!fDefaultHourFormatChar) {
- fDefaultHourFormatChar = CAP_H;
- }
+ if (!fDefaultHourFormatChar) {
+ fDefaultHourFormatChar = CAP_H;
+ }
fAllowedHourFormats[0] = ALLOWED_HOUR_FORMAT_H;
fAllowedHourFormats[1] = ALLOWED_HOUR_FORMAT_UNKNOWN;
}
}
-UDateFormatHourCycle
-DateTimePatternGenerator::getDefaultHourCycle(UErrorCode& status) const {
- if (U_FAILURE(status)) {
- return UDAT_HOUR_CYCLE_23;
- }
- if (fDefaultHourFormatChar == 0) {
- // We need to return something, but the caller should ignore it
- // anyways since the returned status is a failure.
- status = U_UNSUPPORTED_ERROR;
- return UDAT_HOUR_CYCLE_23;
- }
- switch (fDefaultHourFormatChar) {
- case CAP_K:
- return UDAT_HOUR_CYCLE_11;
- case LOW_H:
- return UDAT_HOUR_CYCLE_12;
- case CAP_H:
- return UDAT_HOUR_CYCLE_23;
- case LOW_K:
- return UDAT_HOUR_CYCLE_24;
- default:
- UPRV_UNREACHABLE;
- }
-}
-
+UDateFormatHourCycle
+DateTimePatternGenerator::getDefaultHourCycle(UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return UDAT_HOUR_CYCLE_23;
+ }
+ if (fDefaultHourFormatChar == 0) {
+ // We need to return something, but the caller should ignore it
+ // anyways since the returned status is a failure.
+ status = U_UNSUPPORTED_ERROR;
+ return UDAT_HOUR_CYCLE_23;
+ }
+ switch (fDefaultHourFormatChar) {
+ case CAP_K:
+ return UDAT_HOUR_CYCLE_11;
+ case LOW_H:
+ return UDAT_HOUR_CYCLE_12;
+ case CAP_H:
+ return UDAT_HOUR_CYCLE_23;
+ case LOW_K:
+ return UDAT_HOUR_CYCLE_24;
+ default:
+ UPRV_UNREACHABLE;
+ }
+}
+
UnicodeString
DateTimePatternGenerator::getSkeleton(const UnicodeString& pattern, UErrorCode&
/*status*/) {
- FormatParser fp2;
+ FormatParser fp2;
DateTimeMatcher matcher;
PtnSkeleton localSkeleton;
- matcher.set(pattern, &fp2, localSkeleton);
+ matcher.set(pattern, &fp2, localSkeleton);
return localSkeleton.getSkeleton();
}
@@ -759,10 +759,10 @@ DateTimePatternGenerator::staticGetSkeleton(
UnicodeString
DateTimePatternGenerator::getBaseSkeleton(const UnicodeString& pattern, UErrorCode& /*status*/) {
- FormatParser fp2;
+ FormatParser fp2;
DateTimeMatcher matcher;
PtnSkeleton localSkeleton;
- matcher.set(pattern, &fp2, localSkeleton);
+ matcher.set(pattern, &fp2, localSkeleton);
return localSkeleton.getBaseSkeleton();
}
@@ -788,7 +788,7 @@ DateTimePatternGenerator::addICUPatterns(const Locale& locale, UErrorCode& statu
DateFormat::EStyle style = (DateFormat::EStyle)i;
df = DateFormat::createDateInstance(style, locale);
SimpleDateFormat* sdf;
- if (df != nullptr && (sdf = dynamic_cast<SimpleDateFormat*>(df)) != nullptr) {
+ if (df != nullptr && (sdf = dynamic_cast<SimpleDateFormat*>(df)) != nullptr) {
sdf->toPattern(dfPattern);
addPattern(dfPattern, FALSE, conflictingString, status);
}
@@ -797,7 +797,7 @@ DateTimePatternGenerator::addICUPatterns(const Locale& locale, UErrorCode& statu
if (U_FAILURE(status)) { return; }
df = DateFormat::createTimeInstance(style, locale);
- if (df != nullptr && (sdf = dynamic_cast<SimpleDateFormat*>(df)) != nullptr) {
+ if (df != nullptr && (sdf = dynamic_cast<SimpleDateFormat*>(df)) != nullptr) {
sdf->toPattern(dfPattern);
addPattern(dfPattern, FALSE, conflictingString, status);
@@ -865,19 +865,19 @@ void
DateTimePatternGenerator::getCalendarTypeToUse(const Locale& locale, CharString& destination, UErrorCode& err) {
destination.clear().append(DT_DateTimeGregorianTag, -1, err); // initial default
if ( U_SUCCESS(err) ) {
- UErrorCode localStatus = U_ZERO_ERROR;
+ UErrorCode localStatus = U_ZERO_ERROR;
char localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY];
// obtain a locale that always has the calendar key value that should be used
ures_getFunctionalEquivalent(
localeWithCalendarKey,
ULOC_LOCALE_IDENTIFIER_CAPACITY,
- nullptr,
+ nullptr,
"calendar",
"calendar",
locale.getName(),
- nullptr,
+ nullptr,
FALSE,
- &localStatus);
+ &localStatus);
localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY-1] = 0; // ensure null termination
// now get the calendar key value from that locale
char calendarType[ULOC_KEYWORDS_CAPACITY];
@@ -886,14 +886,14 @@ DateTimePatternGenerator::getCalendarTypeToUse(const Locale& locale, CharString&
"calendar",
calendarType,
ULOC_KEYWORDS_CAPACITY,
- &localStatus);
- // If the input locale was invalid, don't fail with missing resource error, instead
- // continue with default of Gregorian.
- if (U_FAILURE(localStatus) && localStatus != U_MISSING_RESOURCE_ERROR) {
- err = localStatus;
- return;
- }
- if (calendarTypeLen < ULOC_KEYWORDS_CAPACITY) {
+ &localStatus);
+ // If the input locale was invalid, don't fail with missing resource error, instead
+ // continue with default of Gregorian.
+ if (U_FAILURE(localStatus) && localStatus != U_MISSING_RESOURCE_ERROR) {
+ err = localStatus;
+ return;
+ }
+ if (calendarTypeLen < ULOC_KEYWORDS_CAPACITY) {
destination.clear().append(calendarType, -1, err);
if (U_FAILURE(err)) { return; }
}
@@ -903,10 +903,10 @@ DateTimePatternGenerator::getCalendarTypeToUse(const Locale& locale, CharString&
void
DateTimePatternGenerator::consumeShortTimePattern(const UnicodeString& shortTimePattern,
UErrorCode& status) {
- if (U_FAILURE(status)) { return; }
- // ICU-20383 No longer set fDefaultHourFormatChar to the hour format character from
- // this pattern; instead it is set from localeToAllowedHourFormatsMap which now
- // includes entries for both preferred and allowed formats.
+ if (U_FAILURE(status)) { return; }
+ // ICU-20383 No longer set fDefaultHourFormatChar to the hour format character from
+ // this pattern; instead it is set from localeToAllowedHourFormatsMap which now
+ // includes entries for both preferred and allowed formats.
// HACK for hh:ss
hackTimes(shortTimePattern, status);
@@ -958,16 +958,16 @@ struct DateTimePatternGenerator::AppendItemNamesSink : public ResourceSink {
ResourceTable itemsTable = value.getTable(errorCode);
if (U_FAILURE(errorCode)) { return; }
for (int32_t i = 0; itemsTable.getKeyAndValue(i, key, value); ++i) {
- UDateTimePGDisplayWidth width;
- UDateTimePatternField field = dtpg.getFieldAndWidthIndices(key, &width);
+ UDateTimePGDisplayWidth width;
+ UDateTimePatternField field = dtpg.getFieldAndWidthIndices(key, &width);
if (field == UDATPG_FIELD_COUNT) { continue; }
ResourceTable detailsTable = value.getTable(errorCode);
if (U_FAILURE(errorCode)) { return; }
for (int32_t j = 0; detailsTable.getKeyAndValue(j, key, value); ++j) {
if (uprv_strcmp(key, "dn") != 0) { continue; }
const UnicodeString& valueStr = value.getUnicodeString(errorCode);
- if (dtpg.getFieldDisplayName(field,width).isEmpty() && !valueStr.isEmpty()) {
- dtpg.setFieldDisplayName(field,width,valueStr);
+ if (dtpg.getFieldDisplayName(field,width).isEmpty() && !valueStr.isEmpty()) {
+ dtpg.setFieldDisplayName(field,width,valueStr);
}
break;
}
@@ -976,7 +976,7 @@ struct DateTimePatternGenerator::AppendItemNamesSink : public ResourceSink {
void fillInMissing() {
for (int32_t i = 0; i < UDATPG_FIELD_COUNT; i++) {
- UnicodeString& valueStr = dtpg.getMutableFieldDisplayName((UDateTimePatternField)i, UDATPG_WIDE);
+ UnicodeString& valueStr = dtpg.getMutableFieldDisplayName((UDateTimePatternField)i, UDATPG_WIDE);
if (valueStr.isEmpty()) {
valueStr = CAP_F;
U_ASSERT(i < 20);
@@ -991,12 +991,12 @@ struct DateTimePatternGenerator::AppendItemNamesSink : public ResourceSink {
// NUL-terminate for the C API.
valueStr.getTerminatedBuffer();
}
- for (int32_t j = 1; j < UDATPG_WIDTH_COUNT; j++) {
- UnicodeString& valueStr2 = dtpg.getMutableFieldDisplayName((UDateTimePatternField)i, (UDateTimePGDisplayWidth)j);
- if (valueStr2.isEmpty()) {
- valueStr2 = dtpg.getFieldDisplayName((UDateTimePatternField)i, (UDateTimePGDisplayWidth)(j-1));
- }
- }
+ for (int32_t j = 1; j < UDATPG_WIDTH_COUNT; j++) {
+ UnicodeString& valueStr2 = dtpg.getMutableFieldDisplayName((UDateTimePatternField)i, (UDateTimePGDisplayWidth)j);
+ if (valueStr2.isEmpty()) {
+ valueStr2 = dtpg.getFieldDisplayName((UDateTimePatternField)i, (UDateTimePGDisplayWidth)(j-1));
+ }
+ }
}
}
};
@@ -1041,7 +1041,7 @@ DateTimePatternGenerator::addCLDRData(const Locale& locale, UErrorCode& errorCod
UnicodeString rbPattern, value, field;
CharString path;
- LocalUResourceBundlePointer rb(ures_open(nullptr, locale.getName(), &errorCode));
+ LocalUResourceBundlePointer rb(ures_open(nullptr, locale.getName(), &errorCode));
if (U_FAILURE(errorCode)) { return; }
CharString calendarTypeToUse; // to be filled in with the type to use, if all goes well
@@ -1086,13 +1086,13 @@ DateTimePatternGenerator::addCLDRData(const Locale& locale, UErrorCode& errorCod
void
DateTimePatternGenerator::initHashtable(UErrorCode& err) {
- if (U_FAILURE(err)) { return; }
- if (fAvailableFormatKeyHash!=nullptr) {
+ if (U_FAILURE(err)) { return; }
+ if (fAvailableFormatKeyHash!=nullptr) {
return;
}
- LocalPointer<Hashtable> hash(new Hashtable(FALSE, err), err);
- if (U_SUCCESS(err)) {
- fAvailableFormatKeyHash = hash.orphan();
+ LocalPointer<Hashtable> hash(new Hashtable(FALSE, err), err);
+ if (U_SUCCESS(err)) {
+ fAvailableFormatKeyHash = hash.orphan();
}
}
@@ -1110,35 +1110,35 @@ DateTimePatternGenerator::getAppendItemFormat(UDateTimePatternField field) const
void
DateTimePatternGenerator::setAppendItemName(UDateTimePatternField field, const UnicodeString& value) {
- setFieldDisplayName(field, UDATPG_WIDTH_APPENDITEM, value);
+ setFieldDisplayName(field, UDATPG_WIDTH_APPENDITEM, value);
}
const UnicodeString&
DateTimePatternGenerator::getAppendItemName(UDateTimePatternField field) const {
- return fieldDisplayNames[field][UDATPG_WIDTH_APPENDITEM];
-}
-
-void
-DateTimePatternGenerator::setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value) {
- fieldDisplayNames[field][width] = value;
- // NUL-terminate for the C API.
- fieldDisplayNames[field][width].getTerminatedBuffer();
-}
-
-UnicodeString
-DateTimePatternGenerator::getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const {
- return fieldDisplayNames[field][width];
-}
-
+ return fieldDisplayNames[field][UDATPG_WIDTH_APPENDITEM];
+}
+
+void
+DateTimePatternGenerator::setFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width, const UnicodeString& value) {
+ fieldDisplayNames[field][width] = value;
+ // NUL-terminate for the C API.
+ fieldDisplayNames[field][width].getTerminatedBuffer();
+}
+
+UnicodeString
+DateTimePatternGenerator::getFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) const {
+ return fieldDisplayNames[field][width];
+}
+
UnicodeString&
-DateTimePatternGenerator::getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) {
- return fieldDisplayNames[field][width];
+DateTimePatternGenerator::getMutableFieldDisplayName(UDateTimePatternField field, UDateTimePGDisplayWidth width) {
+ return fieldDisplayNames[field][width];
}
void
DateTimePatternGenerator::getAppendName(UDateTimePatternField field, UnicodeString& value) {
value = SINGLE_QUOTE;
- value += fieldDisplayNames[field][UDATPG_WIDTH_APPENDITEM];
+ value += fieldDisplayNames[field][UDATPG_WIDTH_APPENDITEM];
value += SINGLE_QUOTE;
}
@@ -1149,14 +1149,14 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UErro
UnicodeString
DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDateTimePatternMatchOptions options, UErrorCode& status) {
- if (U_FAILURE(status)) {
- return UnicodeString();
- }
- if (U_FAILURE(internalErrorCode)) {
- status = internalErrorCode;
- return UnicodeString();
- }
- const UnicodeString *bestPattern = nullptr;
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UnicodeString();
+ }
+ const UnicodeString *bestPattern = nullptr;
UnicodeString dtFormat;
UnicodeString resultPattern;
int32_t flags = kDTPGNoFlags;
@@ -1165,17 +1165,17 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
int32_t timeMask=(1<<UDATPG_FIELD_COUNT) - 1 - dateMask;
// Replace hour metacharacters 'j', 'C' and 'J', set flags as necessary
- UnicodeString patternFormMapped = mapSkeletonMetacharacters(patternForm, &flags, status);
- if (U_FAILURE(status)) {
- return UnicodeString();
- }
+ UnicodeString patternFormMapped = mapSkeletonMetacharacters(patternForm, &flags, status);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
- resultPattern.remove();
- dtMatcher->set(patternFormMapped, fp);
- const PtnSkeleton* specifiedSkeleton = nullptr;
- bestPattern=getBestRaw(*dtMatcher, -1, distanceInfo, status, &specifiedSkeleton);
- if (U_FAILURE(status)) {
- return UnicodeString();
+ resultPattern.remove();
+ dtMatcher->set(patternFormMapped, fp);
+ const PtnSkeleton* specifiedSkeleton = nullptr;
+ bestPattern=getBestRaw(*dtMatcher, -1, distanceInfo, status, &specifiedSkeleton);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
}
if ( distanceInfo->missingFieldMask==0 && distanceInfo->extraFieldMask==0 ) {
@@ -1184,11 +1184,11 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
return resultPattern;
}
int32_t neededFields = dtMatcher->getFieldMask();
- UnicodeString datePattern=getBestAppending(neededFields & dateMask, flags, status, options);
- UnicodeString timePattern=getBestAppending(neededFields & timeMask, flags, status, options);
- if (U_FAILURE(status)) {
- return UnicodeString();
- }
+ UnicodeString datePattern=getBestAppending(neededFields & dateMask, flags, status, options);
+ UnicodeString timePattern=getBestAppending(neededFields & timeMask, flags, status, options);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
if (datePattern.length()==0) {
if (timePattern.length()==0) {
resultPattern.remove();
@@ -1207,87 +1207,87 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
return resultPattern;
}
-/*
- * Map a skeleton that may have metacharacters jJC to one without, by replacing
- * the metacharacters with locale-appropriate fields of h/H/k/K and of a/b/B
- * (depends on fDefaultHourFormatChar and fAllowedHourFormats being set, which in
- * turn depends on initData having been run). This method also updates the flags
- * as necessary. Returns the updated skeleton.
- */
+/*
+ * Map a skeleton that may have metacharacters jJC to one without, by replacing
+ * the metacharacters with locale-appropriate fields of h/H/k/K and of a/b/B
+ * (depends on fDefaultHourFormatChar and fAllowedHourFormats being set, which in
+ * turn depends on initData having been run). This method also updates the flags
+ * as necessary. Returns the updated skeleton.
+ */
+UnicodeString
+DateTimePatternGenerator::mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status) {
+ UnicodeString patternFormMapped;
+ patternFormMapped.remove();
+ UBool inQuoted = FALSE;
+ int32_t patPos, patLen = patternForm.length();
+ for (patPos = 0; patPos < patLen; patPos++) {
+ UChar patChr = patternForm.charAt(patPos);
+ if (patChr == SINGLE_QUOTE) {
+ inQuoted = !inQuoted;
+ } else if (!inQuoted) {
+ // Handle special mappings for 'j' and 'C' in which fields lengths
+ // 1,3,5 => hour field length 1
+ // 2,4,6 => hour field length 2
+ // 1,2 => abbreviated dayPeriod (field length 1..3)
+ // 3,4 => long dayPeriod (field length 4)
+ // 5,6 => narrow dayPeriod (field length 5)
+ if (patChr == LOW_J || patChr == CAP_C) {
+ int32_t extraLen = 0; // 1 less than total field length
+ while (patPos+1 < patLen && patternForm.charAt(patPos+1)==patChr) {
+ extraLen++;
+ patPos++;
+ }
+ int32_t hourLen = 1 + (extraLen & 1);
+ int32_t dayPeriodLen = (extraLen < 2)? 1: 3 + (extraLen >> 1);
+ UChar hourChar = LOW_H;
+ UChar dayPeriodChar = LOW_A;
+ if (patChr == LOW_J) {
+ hourChar = fDefaultHourFormatChar;
+ } else {
+ AllowedHourFormat bestAllowed;
+ if (fAllowedHourFormats[0] != ALLOWED_HOUR_FORMAT_UNKNOWN) {
+ bestAllowed = (AllowedHourFormat)fAllowedHourFormats[0];
+ } else {
+ status = U_INVALID_FORMAT_ERROR;
+ return UnicodeString();
+ }
+ if (bestAllowed == ALLOWED_HOUR_FORMAT_H || bestAllowed == ALLOWED_HOUR_FORMAT_HB || bestAllowed == ALLOWED_HOUR_FORMAT_Hb) {
+ hourChar = CAP_H;
+ } else if (bestAllowed == ALLOWED_HOUR_FORMAT_K || bestAllowed == ALLOWED_HOUR_FORMAT_KB || bestAllowed == ALLOWED_HOUR_FORMAT_Kb) {
+ hourChar = CAP_K;
+ } else if (bestAllowed == ALLOWED_HOUR_FORMAT_k) {
+ hourChar = LOW_K;
+ }
+ // in #13183 just add b/B to skeleton, no longer need to set special flags
+ if (bestAllowed == ALLOWED_HOUR_FORMAT_HB || bestAllowed == ALLOWED_HOUR_FORMAT_hB || bestAllowed == ALLOWED_HOUR_FORMAT_KB) {
+ dayPeriodChar = CAP_B;
+ } else if (bestAllowed == ALLOWED_HOUR_FORMAT_Hb || bestAllowed == ALLOWED_HOUR_FORMAT_hb || bestAllowed == ALLOWED_HOUR_FORMAT_Kb) {
+ dayPeriodChar = LOW_B;
+ }
+ }
+ if (hourChar==CAP_H || hourChar==LOW_K) {
+ dayPeriodLen = 0;
+ }
+ while (dayPeriodLen-- > 0) {
+ patternFormMapped.append(dayPeriodChar);
+ }
+ while (hourLen-- > 0) {
+ patternFormMapped.append(hourChar);
+ }
+ } else if (patChr == CAP_J) {
+ // Get pattern for skeleton with H, then replace H or k
+ // with fDefaultHourFormatChar (if different)
+ patternFormMapped.append(CAP_H);
+ *flags |= kDTPGSkeletonUsesCapJ;
+ } else {
+ patternFormMapped.append(patChr);
+ }
+ }
+ }
+ return patternFormMapped;
+}
+
UnicodeString
-DateTimePatternGenerator::mapSkeletonMetacharacters(const UnicodeString& patternForm, int32_t* flags, UErrorCode& status) {
- UnicodeString patternFormMapped;
- patternFormMapped.remove();
- UBool inQuoted = FALSE;
- int32_t patPos, patLen = patternForm.length();
- for (patPos = 0; patPos < patLen; patPos++) {
- UChar patChr = patternForm.charAt(patPos);
- if (patChr == SINGLE_QUOTE) {
- inQuoted = !inQuoted;
- } else if (!inQuoted) {
- // Handle special mappings for 'j' and 'C' in which fields lengths
- // 1,3,5 => hour field length 1
- // 2,4,6 => hour field length 2
- // 1,2 => abbreviated dayPeriod (field length 1..3)
- // 3,4 => long dayPeriod (field length 4)
- // 5,6 => narrow dayPeriod (field length 5)
- if (patChr == LOW_J || patChr == CAP_C) {
- int32_t extraLen = 0; // 1 less than total field length
- while (patPos+1 < patLen && patternForm.charAt(patPos+1)==patChr) {
- extraLen++;
- patPos++;
- }
- int32_t hourLen = 1 + (extraLen & 1);
- int32_t dayPeriodLen = (extraLen < 2)? 1: 3 + (extraLen >> 1);
- UChar hourChar = LOW_H;
- UChar dayPeriodChar = LOW_A;
- if (patChr == LOW_J) {
- hourChar = fDefaultHourFormatChar;
- } else {
- AllowedHourFormat bestAllowed;
- if (fAllowedHourFormats[0] != ALLOWED_HOUR_FORMAT_UNKNOWN) {
- bestAllowed = (AllowedHourFormat)fAllowedHourFormats[0];
- } else {
- status = U_INVALID_FORMAT_ERROR;
- return UnicodeString();
- }
- if (bestAllowed == ALLOWED_HOUR_FORMAT_H || bestAllowed == ALLOWED_HOUR_FORMAT_HB || bestAllowed == ALLOWED_HOUR_FORMAT_Hb) {
- hourChar = CAP_H;
- } else if (bestAllowed == ALLOWED_HOUR_FORMAT_K || bestAllowed == ALLOWED_HOUR_FORMAT_KB || bestAllowed == ALLOWED_HOUR_FORMAT_Kb) {
- hourChar = CAP_K;
- } else if (bestAllowed == ALLOWED_HOUR_FORMAT_k) {
- hourChar = LOW_K;
- }
- // in #13183 just add b/B to skeleton, no longer need to set special flags
- if (bestAllowed == ALLOWED_HOUR_FORMAT_HB || bestAllowed == ALLOWED_HOUR_FORMAT_hB || bestAllowed == ALLOWED_HOUR_FORMAT_KB) {
- dayPeriodChar = CAP_B;
- } else if (bestAllowed == ALLOWED_HOUR_FORMAT_Hb || bestAllowed == ALLOWED_HOUR_FORMAT_hb || bestAllowed == ALLOWED_HOUR_FORMAT_Kb) {
- dayPeriodChar = LOW_B;
- }
- }
- if (hourChar==CAP_H || hourChar==LOW_K) {
- dayPeriodLen = 0;
- }
- while (dayPeriodLen-- > 0) {
- patternFormMapped.append(dayPeriodChar);
- }
- while (hourLen-- > 0) {
- patternFormMapped.append(hourChar);
- }
- } else if (patChr == CAP_J) {
- // Get pattern for skeleton with H, then replace H or k
- // with fDefaultHourFormatChar (if different)
- patternFormMapped.append(CAP_H);
- *flags |= kDTPGSkeletonUsesCapJ;
- } else {
- patternFormMapped.append(patChr);
- }
- }
- }
- return patternFormMapped;
-}
-
-UnicodeString
DateTimePatternGenerator::replaceFieldTypes(const UnicodeString& pattern,
const UnicodeString& skeleton,
UErrorCode& status) {
@@ -1298,16 +1298,16 @@ UnicodeString
DateTimePatternGenerator::replaceFieldTypes(const UnicodeString& pattern,
const UnicodeString& skeleton,
UDateTimePatternMatchOptions options,
- UErrorCode& status) {
- if (U_FAILURE(status)) {
- return UnicodeString();
- }
- if (U_FAILURE(internalErrorCode)) {
- status = internalErrorCode;
- return UnicodeString();
- }
+ UErrorCode& status) {
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UnicodeString();
+ }
dtMatcher->set(skeleton, fp);
- UnicodeString result = adjustFieldTypes(pattern, nullptr, kDTPGNoFlags, options);
+ UnicodeString result = adjustFieldTypes(pattern, nullptr, kDTPGNoFlags, options);
return result;
}
@@ -1350,24 +1350,24 @@ DateTimePatternGenerator::getDateTimeFormat() const {
void
DateTimePatternGenerator::setDateTimeFromCalendar(const Locale& locale, UErrorCode& status) {
- if (U_FAILURE(status)) { return; }
-
+ if (U_FAILURE(status)) { return; }
+
const UChar *resStr;
int32_t resStrLen = 0;
- LocalPointer<Calendar> fCalendar(Calendar::createInstance(locale, status), status);
+ LocalPointer<Calendar> fCalendar(Calendar::createInstance(locale, status), status);
if (U_FAILURE(status)) { return; }
- LocalUResourceBundlePointer calData(ures_open(nullptr, locale.getBaseName(), &status));
- if (U_FAILURE(status)) { return; }
+ LocalUResourceBundlePointer calData(ures_open(nullptr, locale.getBaseName(), &status));
+ if (U_FAILURE(status)) { return; }
ures_getByKey(calData.getAlias(), DT_DateTimeCalendarTag, calData.getAlias(), &status);
- if (U_FAILURE(status)) { return; }
+ if (U_FAILURE(status)) { return; }
LocalUResourceBundlePointer dateTimePatterns;
- if (fCalendar->getType() != nullptr && *fCalendar->getType() != '\0'
+ if (fCalendar->getType() != nullptr && *fCalendar->getType() != '\0'
&& uprv_strcmp(fCalendar->getType(), DT_DateTimeGregorianTag) != 0) {
dateTimePatterns.adoptInstead(ures_getByKeyWithFallback(calData.getAlias(), fCalendar->getType(),
- nullptr, &status));
+ nullptr, &status));
ures_getByKeyWithFallback(dateTimePatterns.getAlias(), DT_DateTimePatternsTag,
dateTimePatterns.getAlias(), &status);
}
@@ -1407,12 +1407,12 @@ DateTimePatternGenerator::addPattern(
UnicodeString &conflictingPattern,
UErrorCode& status)
{
- if (U_FAILURE(internalErrorCode)) {
- status = internalErrorCode;
- return UDATPG_NO_CONFLICT;
- }
-
- return addPatternWithSkeleton(pattern, nullptr, override, conflictingPattern, status);
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UDATPG_NO_CONFLICT;
+ }
+
+ return addPatternWithSkeleton(pattern, nullptr, override, conflictingPattern, status);
}
// For DateTimePatternGenerator::addPatternWithSkeleton -
@@ -1433,17 +1433,17 @@ DateTimePatternGenerator::addPatternWithSkeleton(
UnicodeString& conflictingPattern,
UErrorCode& status)
{
- if (U_FAILURE(internalErrorCode)) {
- status = internalErrorCode;
- return UDATPG_NO_CONFLICT;
- }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return UDATPG_NO_CONFLICT;
+ }
UnicodeString basePattern;
PtnSkeleton skeleton;
UDateTimePatternConflict conflictingStatus = UDATPG_NO_CONFLICT;
DateTimeMatcher matcher;
- if ( skeletonToUse == nullptr ) {
+ if ( skeletonToUse == nullptr ) {
matcher.set(pattern, fp, skeleton);
matcher.getBasePattern(basePattern);
} else {
@@ -1459,7 +1459,7 @@ DateTimePatternGenerator::addPatternWithSkeleton(
// availableFormats items from root, which should not override any previous entry with the same base.
UBool entryHadSpecifiedSkeleton;
const UnicodeString *duplicatePattern = patternMap->getPatternFromBasePattern(basePattern, entryHadSpecifiedSkeleton);
- if (duplicatePattern != nullptr && (!entryHadSpecifiedSkeleton || (skeletonToUse != nullptr && !override))) {
+ if (duplicatePattern != nullptr && (!entryHadSpecifiedSkeleton || (skeletonToUse != nullptr && !override))) {
conflictingStatus = UDATPG_BASE_CONFLICT;
conflictingPattern = *duplicatePattern;
if (!override) {
@@ -1470,16 +1470,16 @@ DateTimePatternGenerator::addPatternWithSkeleton(
// items from CLDR data. In that case, we don't want an item from a parent locale to replace an item with
// same skeleton from the specified locale, so skip the current item if skeletonWasSpecified is true for
// the previously-specified conflicting item.
- const PtnSkeleton* entrySpecifiedSkeleton = nullptr;
+ const PtnSkeleton* entrySpecifiedSkeleton = nullptr;
duplicatePattern = patternMap->getPatternFromSkeleton(skeleton, &entrySpecifiedSkeleton);
- if (duplicatePattern != nullptr ) {
+ if (duplicatePattern != nullptr ) {
conflictingStatus = UDATPG_CONFLICT;
conflictingPattern = *duplicatePattern;
- if (!override || (skeletonToUse != nullptr && entrySpecifiedSkeleton != nullptr)) {
+ if (!override || (skeletonToUse != nullptr && entrySpecifiedSkeleton != nullptr)) {
return conflictingStatus;
}
}
- patternMap->add(basePattern, skeleton, pattern, skeletonToUse != nullptr, status);
+ patternMap->add(basePattern, skeleton, pattern, skeletonToUse != nullptr, status);
if(U_FAILURE(status)) {
return conflictingStatus;
}
@@ -1499,23 +1499,23 @@ DateTimePatternGenerator::getAppendFormatNumber(const char* field) const {
}
UDateTimePatternField
-DateTimePatternGenerator::getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const {
- char cldrFieldKey[UDATPG_FIELD_KEY_MAX + 1];
- uprv_strncpy(cldrFieldKey, key, UDATPG_FIELD_KEY_MAX);
- cldrFieldKey[UDATPG_FIELD_KEY_MAX]=0; // ensure termination
- *widthP = UDATPG_WIDE;
- char* hyphenPtr = uprv_strchr(cldrFieldKey, '-');
- if (hyphenPtr) {
- for (int32_t i=UDATPG_WIDTH_COUNT-1; i>0; --i) {
- if (uprv_strcmp(CLDR_FIELD_WIDTH[i], hyphenPtr)==0) {
- *widthP=(UDateTimePGDisplayWidth)i;
- break;
- }
- }
- *hyphenPtr = 0; // now delete width portion of key
- }
+DateTimePatternGenerator::getFieldAndWidthIndices(const char* key, UDateTimePGDisplayWidth* widthP) const {
+ char cldrFieldKey[UDATPG_FIELD_KEY_MAX + 1];
+ uprv_strncpy(cldrFieldKey, key, UDATPG_FIELD_KEY_MAX);
+ cldrFieldKey[UDATPG_FIELD_KEY_MAX]=0; // ensure termination
+ *widthP = UDATPG_WIDE;
+ char* hyphenPtr = uprv_strchr(cldrFieldKey, '-');
+ if (hyphenPtr) {
+ for (int32_t i=UDATPG_WIDTH_COUNT-1; i>0; --i) {
+ if (uprv_strcmp(CLDR_FIELD_WIDTH[i], hyphenPtr)==0) {
+ *widthP=(UDateTimePGDisplayWidth)i;
+ break;
+ }
+ }
+ *hyphenPtr = 0; // now delete width portion of key
+ }
for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i ) {
- if (uprv_strcmp(CLDR_FIELD_NAME[i],cldrFieldKey)==0) {
+ if (uprv_strcmp(CLDR_FIELD_NAME[i],cldrFieldKey)==0) {
return (UDateTimePatternField)i;
}
}
@@ -1526,32 +1526,32 @@ const UnicodeString*
DateTimePatternGenerator::getBestRaw(DateTimeMatcher& source,
int32_t includeMask,
DistanceInfo* missingFields,
- UErrorCode &status,
+ UErrorCode &status,
const PtnSkeleton** specifiedSkeletonPtr) {
int32_t bestDistance = 0x7fffffff;
- int32_t bestMissingFieldMask = -1;
+ int32_t bestMissingFieldMask = -1;
DistanceInfo tempInfo;
- const UnicodeString *bestPattern=nullptr;
- const PtnSkeleton* specifiedSkeleton=nullptr;
+ const UnicodeString *bestPattern=nullptr;
+ const PtnSkeleton* specifiedSkeleton=nullptr;
+
+ PatternMapIterator it(status);
+ if (U_FAILURE(status)) { return nullptr; }
- PatternMapIterator it(status);
- if (U_FAILURE(status)) { return nullptr; }
-
for (it.set(*patternMap); it.hasNext(); ) {
DateTimeMatcher trial = it.next();
if (trial.equals(skipMatcher)) {
continue;
}
int32_t distance=source.getDistance(trial, includeMask, tempInfo);
- // Because we iterate over a map the order is undefined. Can change between implementations,
- // versions, and will very likely be different between Java and C/C++.
- // So if we have patterns with the same distance we also look at the missingFieldMask,
- // and we favour the smallest one. Because the field is a bitmask this technically means we
- // favour differences in the "least significant fields". For example we prefer the one with differences
- // in seconds field vs one with difference in the hours field.
- if (distance<bestDistance || (distance==bestDistance && bestMissingFieldMask<tempInfo.missingFieldMask)) {
+ // Because we iterate over a map the order is undefined. Can change between implementations,
+ // versions, and will very likely be different between Java and C/C++.
+ // So if we have patterns with the same distance we also look at the missingFieldMask,
+ // and we favour the smallest one. Because the field is a bitmask this technically means we
+ // favour differences in the "least significant fields". For example we prefer the one with differences
+ // in seconds field vs one with difference in the hours field.
+ if (distance<bestDistance || (distance==bestDistance && bestMissingFieldMask<tempInfo.missingFieldMask)) {
bestDistance=distance;
- bestMissingFieldMask=tempInfo.missingFieldMask;
+ bestMissingFieldMask=tempInfo.missingFieldMask;
bestPattern=patternMap->getPatternFromSkeleton(*trial.getSkeletonPtr(), &specifiedSkeleton);
missingFields->setTo(tempInfo);
if (distance==0) {
@@ -1597,23 +1597,23 @@ DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
const dtTypeElem *row = &dtTypes[canonicalIndex];
int32_t typeValue = row->field;
- // handle day periods - with #13183, no longer need special handling here, integrated with normal types
+ // handle day periods - with #13183, no longer need special handling here, integrated with normal types
if ((flags & kDTPGFixFractionalSeconds) != 0 && typeValue == UDATPG_SECOND_FIELD) {
field += decimal;
dtMatcher->skeleton.original.appendFieldTo(UDATPG_FRACTIONAL_SECOND_FIELD, field);
} else if (dtMatcher->skeleton.type[typeValue]!=0) {
// Here:
- // - "reqField" is the field from the originally requested skeleton after replacement
- // of metacharacters 'j', 'C' and 'J', with length "reqFieldLen".
+ // - "reqField" is the field from the originally requested skeleton after replacement
+ // of metacharacters 'j', 'C' and 'J', with length "reqFieldLen".
// - "field" is the field from the found pattern.
//
// The adjusted field should consist of characters from the originally requested
- // skeleton, except in the case of UDATPG_MONTH_FIELD or
+ // skeleton, except in the case of UDATPG_MONTH_FIELD or
// UDATPG_WEEKDAY_FIELD or UDATPG_YEAR_FIELD, in which case it should consist
- // of characters from the found pattern. In some cases of UDATPG_HOUR_FIELD,
- // there is adjustment following the "defaultHourFormatChar". There is explanation
- // how it is done below.
+ // of characters from the found pattern. In some cases of UDATPG_HOUR_FIELD,
+ // there is adjustment following the "defaultHourFormatChar". There is explanation
+ // how it is done below.
//
// The length of the adjusted field (adjFieldLen) should match that in the originally
// requested skeleton, except that in the following cases the length of the adjusted field
@@ -1651,31 +1651,31 @@ DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
&& (typeValue!= UDATPG_YEAR_FIELD || reqFieldChar==CAP_Y))
? reqFieldChar
: field.charAt(0);
- if (typeValue == UDATPG_HOUR_FIELD && fDefaultHourFormatChar != 0) {
- // The adjustment here is required to match spec (https://www.unicode.org/reports/tr35/tr35-dates.html#dfst-hour).
- // It is necessary to match the hour-cycle preferred by the Locale.
- // Given that, we need to do the following adjustments:
- // 1. When hour-cycle is h11 it should replace 'h' by 'K'.
- // 2. When hour-cycle is h23 it should replace 'H' by 'k'.
- // 3. When hour-cycle is h24 it should replace 'k' by 'H'.
- // 4. When hour-cycle is h12 it should replace 'K' by 'h'.
-
- if ((flags & kDTPGSkeletonUsesCapJ) != 0 || reqFieldChar == fDefaultHourFormatChar) {
- c = fDefaultHourFormatChar;
- } else if (reqFieldChar == LOW_H && fDefaultHourFormatChar == CAP_K) {
- c = CAP_K;
- } else if (reqFieldChar == CAP_H && fDefaultHourFormatChar == LOW_K) {
- c = LOW_K;
- } else if (reqFieldChar == LOW_K && fDefaultHourFormatChar == CAP_H) {
- c = CAP_H;
- } else if (reqFieldChar == CAP_K && fDefaultHourFormatChar == LOW_H) {
- c = LOW_H;
- }
+ if (typeValue == UDATPG_HOUR_FIELD && fDefaultHourFormatChar != 0) {
+ // The adjustment here is required to match spec (https://www.unicode.org/reports/tr35/tr35-dates.html#dfst-hour).
+ // It is necessary to match the hour-cycle preferred by the Locale.
+ // Given that, we need to do the following adjustments:
+ // 1. When hour-cycle is h11 it should replace 'h' by 'K'.
+ // 2. When hour-cycle is h23 it should replace 'H' by 'k'.
+ // 3. When hour-cycle is h24 it should replace 'k' by 'H'.
+ // 4. When hour-cycle is h12 it should replace 'K' by 'h'.
+
+ if ((flags & kDTPGSkeletonUsesCapJ) != 0 || reqFieldChar == fDefaultHourFormatChar) {
+ c = fDefaultHourFormatChar;
+ } else if (reqFieldChar == LOW_H && fDefaultHourFormatChar == CAP_K) {
+ c = CAP_K;
+ } else if (reqFieldChar == CAP_H && fDefaultHourFormatChar == LOW_K) {
+ c = LOW_K;
+ } else if (reqFieldChar == LOW_K && fDefaultHourFormatChar == CAP_H) {
+ c = CAP_H;
+ } else if (reqFieldChar == CAP_K && fDefaultHourFormatChar == LOW_H) {
+ c = LOW_H;
+ }
}
-
+
field.remove();
- for (int32_t j=adjFieldLen; j>0; --j) {
- field += c;
+ for (int32_t j=adjFieldLen; j>0; --j) {
+ field += c;
}
}
newPattern+=field;
@@ -1685,21 +1685,21 @@ DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
}
UnicodeString
-DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags, UErrorCode &status, UDateTimePatternMatchOptions options) {
- if (U_FAILURE(status)) {
- return UnicodeString();
- }
+DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags, UErrorCode &status, UDateTimePatternMatchOptions options) {
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
UnicodeString resultPattern, tempPattern;
- const UnicodeString* tempPatternPtr;
+ const UnicodeString* tempPatternPtr;
int32_t lastMissingFieldMask=0;
if (missingFields!=0) {
resultPattern=UnicodeString();
- const PtnSkeleton* specifiedSkeleton=nullptr;
- tempPatternPtr = getBestRaw(*dtMatcher, missingFields, distanceInfo, status, &specifiedSkeleton);
- if (U_FAILURE(status)) {
- return UnicodeString();
- }
- tempPattern = *tempPatternPtr;
+ const PtnSkeleton* specifiedSkeleton=nullptr;
+ tempPatternPtr = getBestRaw(*dtMatcher, missingFields, distanceInfo, status, &specifiedSkeleton);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ tempPattern = *tempPatternPtr;
resultPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);
if ( distanceInfo->missingFieldMask==0 ) {
return resultPattern;
@@ -1715,26 +1715,26 @@ DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags,
continue;
}
int32_t startingMask = distanceInfo->missingFieldMask;
- tempPatternPtr = getBestRaw(*dtMatcher, distanceInfo->missingFieldMask, distanceInfo, status, &specifiedSkeleton);
- if (U_FAILURE(status)) {
- return UnicodeString();
- }
- tempPattern = *tempPatternPtr;
+ tempPatternPtr = getBestRaw(*dtMatcher, distanceInfo->missingFieldMask, distanceInfo, status, &specifiedSkeleton);
+ if (U_FAILURE(status)) {
+ return UnicodeString();
+ }
+ tempPattern = *tempPatternPtr;
tempPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);
int32_t foundMask=startingMask& ~distanceInfo->missingFieldMask;
int32_t topField=getTopBitNumber(foundMask);
-
- if (appendItemFormats[topField].length() != 0) {
- UnicodeString appendName;
- getAppendName((UDateTimePatternField)topField, appendName);
- const UnicodeString *values[3] = {
- &resultPattern,
- &tempPattern,
- &appendName
- };
- SimpleFormatter(appendItemFormats[topField], 2, 3, status).
- formatAndReplace(values, 3, resultPattern, nullptr, 0, status);
- }
+
+ if (appendItemFormats[topField].length() != 0) {
+ UnicodeString appendName;
+ getAppendName((UDateTimePatternField)topField, appendName);
+ const UnicodeString *values[3] = {
+ &resultPattern,
+ &tempPattern,
+ &appendName
+ };
+ SimpleFormatter(appendItemFormats[topField], 2, 3, status).
+ formatAndReplace(values, 3, resultPattern, nullptr, 0, status);
+ }
lastMissingFieldMask = distanceInfo->missingFieldMask;
}
}
@@ -1742,7 +1742,7 @@ DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags,
}
int32_t
-DateTimePatternGenerator::getTopBitNumber(int32_t foundMask) const {
+DateTimePatternGenerator::getTopBitNumber(int32_t foundMask) const {
if ( foundMask==0 ) {
return 0;
}
@@ -1771,21 +1771,21 @@ DateTimePatternGenerator::isAvailableFormatSet(const UnicodeString &key) const {
void
DateTimePatternGenerator::copyHashtable(Hashtable *other, UErrorCode &status) {
- if (other == nullptr || U_FAILURE(status)) {
+ if (other == nullptr || U_FAILURE(status)) {
return;
}
- if (fAvailableFormatKeyHash != nullptr) {
+ if (fAvailableFormatKeyHash != nullptr) {
delete fAvailableFormatKeyHash;
- fAvailableFormatKeyHash = nullptr;
+ fAvailableFormatKeyHash = nullptr;
}
initHashtable(status);
if(U_FAILURE(status)){
return;
}
int32_t pos = UHASH_FIRST;
- const UHashElement* elem = nullptr;
+ const UHashElement* elem = nullptr;
// walk through the hash table and create a deep clone
- while((elem = other->nextElement(pos))!= nullptr){
+ while((elem = other->nextElement(pos))!= nullptr){
const UHashTok otherKeyTok = elem->key;
UnicodeString* otherKey = (UnicodeString*)otherKeyTok.pointer;
fAvailableFormatKeyHash->puti(*otherKey, 1, status);
@@ -1797,17 +1797,17 @@ DateTimePatternGenerator::copyHashtable(Hashtable *other, UErrorCode &status) {
StringEnumeration*
DateTimePatternGenerator::getSkeletons(UErrorCode& status) const {
- if (U_FAILURE(status)) {
- return nullptr;
- }
- if (U_FAILURE(internalErrorCode)) {
- status = internalErrorCode;
- return nullptr;
- }
- LocalPointer<StringEnumeration> skeletonEnumerator(
- new DTSkeletonEnumeration(*patternMap, DT_SKELETON, status), status);
-
- return U_SUCCESS(status) ? skeletonEnumerator.orphan() : nullptr;
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> skeletonEnumerator(
+ new DTSkeletonEnumeration(*patternMap, DT_SKELETON, status), status);
+
+ return U_SUCCESS(status) ? skeletonEnumerator.orphan() : nullptr;
}
const UnicodeString&
@@ -1818,70 +1818,70 @@ DateTimePatternGenerator::getPatternForSkeleton(const UnicodeString& skeleton) c
return emptyString;
}
curElem = patternMap->getHeader(skeleton.charAt(0));
- while ( curElem != nullptr ) {
+ while ( curElem != nullptr ) {
if ( curElem->skeleton->getSkeleton()==skeleton ) {
return curElem->pattern;
}
- curElem = curElem->next.getAlias();
+ curElem = curElem->next.getAlias();
}
return emptyString;
}
StringEnumeration*
DateTimePatternGenerator::getBaseSkeletons(UErrorCode& status) const {
- if (U_FAILURE(status)) {
- return nullptr;
- }
- if (U_FAILURE(internalErrorCode)) {
- status = internalErrorCode;
- return nullptr;
- }
- LocalPointer<StringEnumeration> baseSkeletonEnumerator(
- new DTSkeletonEnumeration(*patternMap, DT_BASESKELETON, status), status);
-
- return U_SUCCESS(status) ? baseSkeletonEnumerator.orphan() : nullptr;
+ if (U_FAILURE(status)) {
+ return nullptr;
+ }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> baseSkeletonEnumerator(
+ new DTSkeletonEnumeration(*patternMap, DT_BASESKELETON, status), status);
+
+ return U_SUCCESS(status) ? baseSkeletonEnumerator.orphan() : nullptr;
}
StringEnumeration*
DateTimePatternGenerator::getRedundants(UErrorCode& status) {
- if (U_FAILURE(status)) { return nullptr; }
- if (U_FAILURE(internalErrorCode)) {
- status = internalErrorCode;
- return nullptr;
- }
- LocalPointer<StringEnumeration> output(new DTRedundantEnumeration(), status);
- if (U_FAILURE(status)) { return nullptr; }
+ if (U_FAILURE(status)) { return nullptr; }
+ if (U_FAILURE(internalErrorCode)) {
+ status = internalErrorCode;
+ return nullptr;
+ }
+ LocalPointer<StringEnumeration> output(new DTRedundantEnumeration(), status);
+ if (U_FAILURE(status)) { return nullptr; }
const UnicodeString *pattern;
- PatternMapIterator it(status);
- if (U_FAILURE(status)) { return nullptr; }
-
+ PatternMapIterator it(status);
+ if (U_FAILURE(status)) { return nullptr; }
+
for (it.set(*patternMap); it.hasNext(); ) {
DateTimeMatcher current = it.next();
pattern = patternMap->getPatternFromSkeleton(*(it.getSkeleton()));
if ( isCanonicalItem(*pattern) ) {
continue;
}
- if ( skipMatcher == nullptr ) {
+ if ( skipMatcher == nullptr ) {
skipMatcher = new DateTimeMatcher(current);
- if (skipMatcher == nullptr) {
- status = U_MEMORY_ALLOCATION_ERROR;
- return nullptr;
- }
+ if (skipMatcher == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
}
else {
*skipMatcher = current;
}
UnicodeString trial = getBestPattern(current.getPattern(), status);
- if (U_FAILURE(status)) { return nullptr; }
+ if (U_FAILURE(status)) { return nullptr; }
if (trial == *pattern) {
- ((DTRedundantEnumeration *)output.getAlias())->add(*pattern, status);
- if (U_FAILURE(status)) { return nullptr; }
+ ((DTRedundantEnumeration *)output.getAlias())->add(*pattern, status);
+ if (U_FAILURE(status)) { return nullptr; }
}
if (current.equals(skipMatcher)) {
continue;
}
}
- return output.orphan();
+ return output.orphan();
}
UBool
@@ -1905,54 +1905,54 @@ DateTimePatternGenerator::clone() const {
PatternMap::PatternMap() {
for (int32_t i=0; i < MAX_PATTERN_ENTRIES; ++i ) {
- boot[i] = nullptr;
+ boot[i] = nullptr;
}
isDupAllowed = TRUE;
}
void
PatternMap::copyFrom(const PatternMap& other, UErrorCode& status) {
- if (U_FAILURE(status)) {
- return;
- }
+ if (U_FAILURE(status)) {
+ return;
+ }
this->isDupAllowed = other.isDupAllowed;
- for (int32_t bootIndex = 0; bootIndex < MAX_PATTERN_ENTRIES; ++bootIndex) {
- PtnElem *curElem, *otherElem, *prevElem=nullptr;
+ for (int32_t bootIndex = 0; bootIndex < MAX_PATTERN_ENTRIES; ++bootIndex) {
+ PtnElem *curElem, *otherElem, *prevElem=nullptr;
otherElem = other.boot[bootIndex];
- while (otherElem != nullptr) {
- LocalPointer<PtnElem> newElem(new PtnElem(otherElem->basePattern, otherElem->pattern), status);
- if (U_FAILURE(status)) {
- return; // out of memory
+ while (otherElem != nullptr) {
+ LocalPointer<PtnElem> newElem(new PtnElem(otherElem->basePattern, otherElem->pattern), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(*(otherElem->skeleton)), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
}
- newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(*(otherElem->skeleton)), status);
- if (U_FAILURE(status)) {
- return; // out of memory
- }
- newElem->skeletonWasSpecified = otherElem->skeletonWasSpecified;
-
- // Release ownership from the LocalPointer of the PtnElem object.
- // The PtnElem will now be owned by either the boot (for the first entry in the linked-list)
- // or owned by the previous PtnElem object in the linked-list.
- curElem = newElem.orphan();
-
- if (this->boot[bootIndex] == nullptr) {
+ newElem->skeletonWasSpecified = otherElem->skeletonWasSpecified;
+
+ // Release ownership from the LocalPointer of the PtnElem object.
+ // The PtnElem will now be owned by either the boot (for the first entry in the linked-list)
+ // or owned by the previous PtnElem object in the linked-list.
+ curElem = newElem.orphan();
+
+ if (this->boot[bootIndex] == nullptr) {
this->boot[bootIndex] = curElem;
- } else {
- if (prevElem != nullptr) {
- prevElem->next.adoptInstead(curElem);
- } else {
- UPRV_UNREACHABLE;
- }
+ } else {
+ if (prevElem != nullptr) {
+ prevElem->next.adoptInstead(curElem);
+ } else {
+ UPRV_UNREACHABLE;
+ }
}
prevElem = curElem;
- otherElem = otherElem->next.getAlias();
+ otherElem = otherElem->next.getAlias();
}
}
}
PtnElem*
-PatternMap::getHeader(UChar baseChar) const {
+PatternMap::getHeader(UChar baseChar) const {
PtnElem* curElem;
if ( (baseChar >= CAP_A) && (baseChar <= CAP_Z) ) {
@@ -1963,7 +1963,7 @@ PatternMap::getHeader(UChar baseChar) const {
curElem = boot[26+baseChar-LOW_A];
}
else {
- return nullptr;
+ return nullptr;
}
}
return curElem;
@@ -1971,9 +1971,9 @@ PatternMap::getHeader(UChar baseChar) const {
PatternMap::~PatternMap() {
for (int32_t i=0; i < MAX_PATTERN_ENTRIES; ++i ) {
- if (boot[i] != nullptr ) {
+ if (boot[i] != nullptr ) {
delete boot[i];
- boot[i] = nullptr;
+ boot[i] = nullptr;
}
}
} // PatternMap destructor
@@ -2002,45 +2002,45 @@ PatternMap::add(const UnicodeString& basePattern,
}
}
- if (baseElem == nullptr) {
- LocalPointer<PtnElem> newElem(new PtnElem(basePattern, value), status);
- if (U_FAILURE(status)) {
- return; // out of memory
+ if (baseElem == nullptr) {
+ LocalPointer<PtnElem> newElem(new PtnElem(basePattern, value), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
}
- newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(skeleton), status);
- if (U_FAILURE(status)) {
- return; // out of memory
- }
- newElem->skeletonWasSpecified = skeletonWasSpecified;
+ newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(skeleton), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
+ }
+ newElem->skeletonWasSpecified = skeletonWasSpecified;
if (baseChar >= LOW_A) {
- boot[26 + (baseChar - LOW_A)] = newElem.orphan(); // the boot array now owns the PtnElem.
+ boot[26 + (baseChar - LOW_A)] = newElem.orphan(); // the boot array now owns the PtnElem.
}
else {
- boot[baseChar - CAP_A] = newElem.orphan(); // the boot array now owns the PtnElem.
+ boot[baseChar - CAP_A] = newElem.orphan(); // the boot array now owns the PtnElem.
}
}
- if ( baseElem != nullptr ) {
+ if ( baseElem != nullptr ) {
curElem = getDuplicateElem(basePattern, skeleton, baseElem);
- if (curElem == nullptr) {
+ if (curElem == nullptr) {
// add new element to the list.
curElem = baseElem;
- while( curElem -> next != nullptr )
+ while( curElem -> next != nullptr )
{
- curElem = curElem->next.getAlias();
+ curElem = curElem->next.getAlias();
+ }
+
+ LocalPointer<PtnElem> newElem(new PtnElem(basePattern, value), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
}
-
- LocalPointer<PtnElem> newElem(new PtnElem(basePattern, value), status);
- if (U_FAILURE(status)) {
- return; // out of memory
+ newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(skeleton), status);
+ if (U_FAILURE(status)) {
+ return; // out of memory
}
- newElem->skeleton.adoptInsteadAndCheckErrorCode(new PtnSkeleton(skeleton), status);
- if (U_FAILURE(status)) {
- return; // out of memory
- }
- newElem->skeletonWasSpecified = skeletonWasSpecified;
- curElem->next.adoptInstead(newElem.orphan());
- curElem = curElem->next.getAlias();
+ newElem->skeletonWasSpecified = skeletonWasSpecified;
+ curElem->next.adoptInstead(newElem.orphan());
+ curElem = curElem->next.getAlias();
}
else {
// Pattern exists in the list already.
@@ -2058,11 +2058,11 @@ PatternMap::add(const UnicodeString& basePattern,
// Find the pattern from the given basePattern string.
const UnicodeString *
-PatternMap::getPatternFromBasePattern(const UnicodeString& basePattern, UBool& skeletonWasSpecified) const { // key to search for
+PatternMap::getPatternFromBasePattern(const UnicodeString& basePattern, UBool& skeletonWasSpecified) const { // key to search for
PtnElem *curElem;
- if ((curElem=getHeader(basePattern.charAt(0)))==nullptr) {
- return nullptr; // no match
+ if ((curElem=getHeader(basePattern.charAt(0)))==nullptr) {
+ return nullptr; // no match
}
do {
@@ -2070,10 +2070,10 @@ PatternMap::getPatternFromBasePattern(const UnicodeString& basePattern, UBool& s
skeletonWasSpecified = curElem->skeletonWasSpecified;
return &(curElem->pattern);
}
- curElem = curElem->next.getAlias();
- } while (curElem != nullptr);
+ curElem = curElem->next.getAlias();
+ } while (curElem != nullptr);
- return nullptr;
+ return nullptr;
} // PatternMap::getFromBasePattern
@@ -2084,69 +2084,69 @@ PatternMap::getPatternFromBasePattern(const UnicodeString& basePattern, UBool& s
// optimum distance value in getBestRaw. When this is called from public getRedundants (specifiedSkeletonPtr is NULL),
// for now it will continue to compare based on baseOriginal so as not to change the behavior unnecessarily.
const UnicodeString *
-PatternMap::getPatternFromSkeleton(const PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr) const { // key to search for
+PatternMap::getPatternFromSkeleton(const PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr) const { // key to search for
PtnElem *curElem;
if (specifiedSkeletonPtr) {
- *specifiedSkeletonPtr = nullptr;
+ *specifiedSkeletonPtr = nullptr;
}
// find boot entry
UChar baseChar = skeleton.getFirstChar();
- if ((curElem=getHeader(baseChar))==nullptr) {
- return nullptr; // no match
+ if ((curElem=getHeader(baseChar))==nullptr) {
+ return nullptr; // no match
}
do {
UBool equal;
- if (specifiedSkeletonPtr != nullptr) { // called from DateTimePatternGenerator::getBestRaw or addPattern, use original
+ if (specifiedSkeletonPtr != nullptr) { // called from DateTimePatternGenerator::getBestRaw or addPattern, use original
equal = curElem->skeleton->original == skeleton.original;
} else { // called from DateTimePatternGenerator::getRedundants, use baseOriginal
equal = curElem->skeleton->baseOriginal == skeleton.baseOriginal;
}
if (equal) {
if (specifiedSkeletonPtr && curElem->skeletonWasSpecified) {
- *specifiedSkeletonPtr = curElem->skeleton.getAlias();
+ *specifiedSkeletonPtr = curElem->skeleton.getAlias();
}
return &(curElem->pattern);
}
- curElem = curElem->next.getAlias();
- } while (curElem != nullptr);
+ curElem = curElem->next.getAlias();
+ } while (curElem != nullptr);
- return nullptr;
+ return nullptr;
}
UBool
-PatternMap::equals(const PatternMap& other) const {
+PatternMap::equals(const PatternMap& other) const {
if ( this==&other ) {
return TRUE;
}
- for (int32_t bootIndex = 0; bootIndex < MAX_PATTERN_ENTRIES; ++bootIndex) {
- if (boot[bootIndex] == other.boot[bootIndex]) {
+ for (int32_t bootIndex = 0; bootIndex < MAX_PATTERN_ENTRIES; ++bootIndex) {
+ if (boot[bootIndex] == other.boot[bootIndex]) {
continue;
}
- if ((boot[bootIndex] == nullptr) || (other.boot[bootIndex] == nullptr)) {
+ if ((boot[bootIndex] == nullptr) || (other.boot[bootIndex] == nullptr)) {
return FALSE;
}
PtnElem *otherElem = other.boot[bootIndex];
PtnElem *myElem = boot[bootIndex];
- while ((otherElem != nullptr) || (myElem != nullptr)) {
+ while ((otherElem != nullptr) || (myElem != nullptr)) {
if ( myElem == otherElem ) {
break;
}
- if ((otherElem == nullptr) || (myElem == nullptr)) {
+ if ((otherElem == nullptr) || (myElem == nullptr)) {
return FALSE;
}
if ( (myElem->basePattern != otherElem->basePattern) ||
(myElem->pattern != otherElem->pattern) ) {
return FALSE;
}
- if ((myElem->skeleton.getAlias() != otherElem->skeleton.getAlias()) &&
+ if ((myElem->skeleton.getAlias() != otherElem->skeleton.getAlias()) &&
!myElem->skeleton->equals(*(otherElem->skeleton))) {
return FALSE;
}
- myElem = myElem->next.getAlias();
- otherElem = otherElem->next.getAlias();
+ myElem = myElem->next.getAlias();
+ otherElem = otherElem->next.getAlias();
}
}
return TRUE;
@@ -2158,21 +2158,21 @@ PtnElem*
PatternMap::getDuplicateElem(
const UnicodeString &basePattern,
const PtnSkeleton &skeleton,
- PtnElem *baseElem) {
+ PtnElem *baseElem) {
PtnElem *curElem;
- if ( baseElem == nullptr ) {
- return nullptr;
+ if ( baseElem == nullptr ) {
+ return nullptr;
}
else {
curElem = baseElem;
}
do {
if ( basePattern.compare(curElem->basePattern)==0 ) {
- UBool isEqual = TRUE;
- for (int32_t i = 0; i < UDATPG_FIELD_COUNT; ++i) {
+ UBool isEqual = TRUE;
+ for (int32_t i = 0; i < UDATPG_FIELD_COUNT; ++i) {
if (curElem->skeleton->type[i] != skeleton.type[i] ) {
- isEqual = FALSE;
+ isEqual = FALSE;
break;
}
}
@@ -2180,11 +2180,11 @@ PatternMap::getDuplicateElem(
return curElem;
}
}
- curElem = curElem->next.getAlias();
- } while( curElem != nullptr );
+ curElem = curElem->next.getAlias();
+ } while( curElem != nullptr );
// end of the list
- return nullptr;
+ return nullptr;
} // PatternMap::getDuplicateElem
@@ -2197,12 +2197,12 @@ DateTimeMatcher::DateTimeMatcher(const DateTimeMatcher& other) {
copyFrom(other.skeleton);
}
-DateTimeMatcher& DateTimeMatcher::operator=(const DateTimeMatcher& other) {
- copyFrom(other.skeleton);
- return *this;
-}
+DateTimeMatcher& DateTimeMatcher::operator=(const DateTimeMatcher& other) {
+ copyFrom(other.skeleton);
+ return *this;
+}
+
-
void
DateTimeMatcher::set(const UnicodeString& pattern, FormatParser* fp) {
PtnSkeleton localSkeleton;
@@ -2215,14 +2215,14 @@ DateTimeMatcher::set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton
for (i=0; i<UDATPG_FIELD_COUNT; ++i) {
skeletonResult.type[i] = NONE;
}
- skeletonResult.original.clear();
- skeletonResult.baseOriginal.clear();
- skeletonResult.addedDefaultDayPeriod = FALSE;
-
+ skeletonResult.original.clear();
+ skeletonResult.baseOriginal.clear();
+ skeletonResult.addedDefaultDayPeriod = FALSE;
+
fp->set(pattern);
for (i=0; i < fp->itemNumber; i++) {
const UnicodeString& value = fp->items[i];
- // don't skip 'a' anymore, dayPeriod handled specially below
+ // don't skip 'a' anymore, dayPeriod handled specially below
if ( fp->isQuoteLiteral(value) ) {
UnicodeString quoteLiteral;
@@ -2230,73 +2230,73 @@ DateTimeMatcher::set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton
continue;
}
int32_t canonicalIndex = fp->getCanonicalIndex(value);
- if (canonicalIndex < 0) {
+ if (canonicalIndex < 0) {
continue;
}
const dtTypeElem *row = &dtTypes[canonicalIndex];
int32_t field = row->field;
skeletonResult.original.populate(field, value);
UChar repeatChar = row->patternChar;
- int32_t repeatCount = row->minLen;
+ int32_t repeatCount = row->minLen;
skeletonResult.baseOriginal.populate(field, repeatChar, repeatCount);
int16_t subField = row->type;
- if (row->type > 0) {
- U_ASSERT(value.length() < INT16_MAX);
- subField += static_cast<int16_t>(value.length());
+ if (row->type > 0) {
+ U_ASSERT(value.length() < INT16_MAX);
+ subField += static_cast<int16_t>(value.length());
}
skeletonResult.type[field] = subField;
}
-
- // #20739, we have a skeleton with minutes and milliseconds, but no seconds
- //
- // Theoretically we would need to check and fix all fields with "gaps":
- // for example year-day (no month), month-hour (no day), and so on, All the possible field combinations.
- // Plus some smartness: year + hour => should we add month, or add day-of-year?
- // What about month + day-of-week, or month + am/pm indicator.
- // I think beyond a certain point we should not try to fix bad developer input and try guessing what they mean.
- // Garbage in, garbage out.
- if (!skeletonResult.original.isFieldEmpty(UDATPG_MINUTE_FIELD)
- && !skeletonResult.original.isFieldEmpty(UDATPG_FRACTIONAL_SECOND_FIELD)
- && skeletonResult.original.isFieldEmpty(UDATPG_SECOND_FIELD)) {
- // Force the use of seconds
- for (i = 0; dtTypes[i].patternChar != 0; i++) {
- if (dtTypes[i].field == UDATPG_SECOND_FIELD) {
- // first entry for UDATPG_SECOND_FIELD
- skeletonResult.original.populate(UDATPG_SECOND_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
- skeletonResult.baseOriginal.populate(UDATPG_SECOND_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
- // We add value.length, same as above, when type is first initialized.
- // The value we want to "fake" here is "s", and 1 means "s".length()
- int16_t subField = dtTypes[i].type;
- skeletonResult.type[UDATPG_SECOND_FIELD] = (subField > 0) ? subField + 1 : subField;
- break;
- }
- }
- }
-
- // #13183, handle special behavior for day period characters (a, b, B)
- if (!skeletonResult.original.isFieldEmpty(UDATPG_HOUR_FIELD)) {
- if (skeletonResult.original.getFieldChar(UDATPG_HOUR_FIELD)==LOW_H || skeletonResult.original.getFieldChar(UDATPG_HOUR_FIELD)==CAP_K) {
- // We have a skeleton with 12-hour-cycle format
- if (skeletonResult.original.isFieldEmpty(UDATPG_DAYPERIOD_FIELD)) {
- // But we do not have a day period in the skeleton; add the default DAYPERIOD (currently "a")
- for (i = 0; dtTypes[i].patternChar != 0; i++) {
- if ( dtTypes[i].field == UDATPG_DAYPERIOD_FIELD ) {
- // first entry for UDATPG_DAYPERIOD_FIELD
- skeletonResult.original.populate(UDATPG_DAYPERIOD_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
- skeletonResult.baseOriginal.populate(UDATPG_DAYPERIOD_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
- skeletonResult.type[UDATPG_DAYPERIOD_FIELD] = dtTypes[i].type;
- skeletonResult.addedDefaultDayPeriod = TRUE;
- break;
- }
- }
- }
- } else {
- // Skeleton has 24-hour-cycle hour format and has dayPeriod, delete dayPeriod (i.e. ignore it)
- skeletonResult.original.clearField(UDATPG_DAYPERIOD_FIELD);
- skeletonResult.baseOriginal.clearField(UDATPG_DAYPERIOD_FIELD);
- skeletonResult.type[UDATPG_DAYPERIOD_FIELD] = NONE;
- }
- }
+
+ // #20739, we have a skeleton with minutes and milliseconds, but no seconds
+ //
+ // Theoretically we would need to check and fix all fields with "gaps":
+ // for example year-day (no month), month-hour (no day), and so on, All the possible field combinations.
+ // Plus some smartness: year + hour => should we add month, or add day-of-year?
+ // What about month + day-of-week, or month + am/pm indicator.
+ // I think beyond a certain point we should not try to fix bad developer input and try guessing what they mean.
+ // Garbage in, garbage out.
+ if (!skeletonResult.original.isFieldEmpty(UDATPG_MINUTE_FIELD)
+ && !skeletonResult.original.isFieldEmpty(UDATPG_FRACTIONAL_SECOND_FIELD)
+ && skeletonResult.original.isFieldEmpty(UDATPG_SECOND_FIELD)) {
+ // Force the use of seconds
+ for (i = 0; dtTypes[i].patternChar != 0; i++) {
+ if (dtTypes[i].field == UDATPG_SECOND_FIELD) {
+ // first entry for UDATPG_SECOND_FIELD
+ skeletonResult.original.populate(UDATPG_SECOND_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
+ skeletonResult.baseOriginal.populate(UDATPG_SECOND_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
+ // We add value.length, same as above, when type is first initialized.
+ // The value we want to "fake" here is "s", and 1 means "s".length()
+ int16_t subField = dtTypes[i].type;
+ skeletonResult.type[UDATPG_SECOND_FIELD] = (subField > 0) ? subField + 1 : subField;
+ break;
+ }
+ }
+ }
+
+ // #13183, handle special behavior for day period characters (a, b, B)
+ if (!skeletonResult.original.isFieldEmpty(UDATPG_HOUR_FIELD)) {
+ if (skeletonResult.original.getFieldChar(UDATPG_HOUR_FIELD)==LOW_H || skeletonResult.original.getFieldChar(UDATPG_HOUR_FIELD)==CAP_K) {
+ // We have a skeleton with 12-hour-cycle format
+ if (skeletonResult.original.isFieldEmpty(UDATPG_DAYPERIOD_FIELD)) {
+ // But we do not have a day period in the skeleton; add the default DAYPERIOD (currently "a")
+ for (i = 0; dtTypes[i].patternChar != 0; i++) {
+ if ( dtTypes[i].field == UDATPG_DAYPERIOD_FIELD ) {
+ // first entry for UDATPG_DAYPERIOD_FIELD
+ skeletonResult.original.populate(UDATPG_DAYPERIOD_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
+ skeletonResult.baseOriginal.populate(UDATPG_DAYPERIOD_FIELD, dtTypes[i].patternChar, dtTypes[i].minLen);
+ skeletonResult.type[UDATPG_DAYPERIOD_FIELD] = dtTypes[i].type;
+ skeletonResult.addedDefaultDayPeriod = TRUE;
+ break;
+ }
+ }
+ }
+ } else {
+ // Skeleton has 24-hour-cycle hour format and has dayPeriod, delete dayPeriod (i.e. ignore it)
+ skeletonResult.original.clearField(UDATPG_DAYPERIOD_FIELD);
+ skeletonResult.baseOriginal.clearField(UDATPG_DAYPERIOD_FIELD);
+ skeletonResult.type[UDATPG_DAYPERIOD_FIELD] = NONE;
+ }
+ }
copyFrom(skeletonResult);
}
@@ -2313,8 +2313,8 @@ DateTimeMatcher::getPattern() {
}
int32_t
-DateTimeMatcher::getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo) const {
- int32_t result = 0;
+DateTimeMatcher::getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo) const {
+ int32_t result = 0;
distanceInfo.clear();
for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i ) {
int32_t myType = (includeMask&(1<<i))==0 ? 0 : skeleton.type[i];
@@ -2353,13 +2353,13 @@ DateTimeMatcher::copyFrom() {
UBool
DateTimeMatcher::equals(const DateTimeMatcher* other) const {
- if (other==nullptr) { return FALSE; }
+ if (other==nullptr) { return FALSE; }
return skeleton.original == other->skeleton.original;
}
int32_t
-DateTimeMatcher::getFieldMask() const {
- int32_t result = 0;
+DateTimeMatcher::getFieldMask() const {
+ int32_t result = 0;
for (int32_t i=0; i<UDATPG_FIELD_COUNT; ++i) {
if (skeleton.type[i]!=0) {
@@ -2376,7 +2376,7 @@ DateTimeMatcher::getSkeletonPtr() {
FormatParser::FormatParser () {
status = START;
- itemNumber = 0;
+ itemNumber = 0;
}
@@ -2388,7 +2388,7 @@ FormatParser::~FormatParser () {
// Note: the startPos may
FormatParser::TokenStatus
FormatParser::setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len) {
- int32_t curLoc = startPos;
+ int32_t curLoc = startPos;
if ( curLoc >= pattern.length()) {
return DONE;
}
@@ -2414,10 +2414,10 @@ FormatParser::setTokens(const UnicodeString& pattern, int32_t startPos, int32_t
void
FormatParser::set(const UnicodeString& pattern) {
- int32_t startPos = 0;
- TokenStatus result = START;
- int32_t len = 0;
- itemNumber = 0;
+ int32_t startPos = 0;
+ TokenStatus result = START;
+ int32_t len = 0;
+ itemNumber = 0;
do {
result = setTokens( pattern, startPos, &len );
@@ -2468,14 +2468,14 @@ FormatParser::getCanonicalIndex(const UnicodeString& s, UBool strict) {
UBool
FormatParser::isQuoteLiteral(const UnicodeString& s) {
- return (UBool)(s.charAt(0) == SINGLE_QUOTE);
+ return (UBool)(s.charAt(0) == SINGLE_QUOTE);
}
-// This function assumes the current itemIndex points to the quote literal.
+// This function assumes the current itemIndex points to the quote literal.
// Please call isQuoteLiteral prior to this function.
void
FormatParser::getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex) {
- int32_t i = *itemIndex;
+ int32_t i = *itemIndex;
quote.remove();
if (items[i].charAt(0)==SINGLE_QUOTE) {
@@ -2504,7 +2504,7 @@ FormatParser::getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex) {
}
UBool
-FormatParser::isPatternSeparator(const UnicodeString& field) const {
+FormatParser::isPatternSeparator(const UnicodeString& field) const {
for (int32_t i=0; i<field.length(); ++i ) {
UChar c= field.charAt(i);
if ( (c==SINGLE_QUOTE) || (c==BACKSLASH) || (c==SPACE) || (c==COLON) ||
@@ -2521,16 +2521,16 @@ FormatParser::isPatternSeparator(const UnicodeString& field) const {
DistanceInfo::~DistanceInfo() {}
void
-DistanceInfo::setTo(const DistanceInfo& other) {
+DistanceInfo::setTo(const DistanceInfo& other) {
missingFieldMask = other.missingFieldMask;
extraFieldMask= other.extraFieldMask;
}
-PatternMapIterator::PatternMapIterator(UErrorCode& status) :
- bootIndex(0), nodePtr(nullptr), matcher(nullptr), patternMap(nullptr)
-{
- if (U_FAILURE(status)) { return; }
- matcher.adoptInsteadAndCheckErrorCode(new DateTimeMatcher(), status);
+PatternMapIterator::PatternMapIterator(UErrorCode& status) :
+ bootIndex(0), nodePtr(nullptr), matcher(nullptr), patternMap(nullptr)
+{
+ if (U_FAILURE(status)) { return; }
+ matcher.adoptInsteadAndCheckErrorCode(new DateTimeMatcher(), status);
}
PatternMapIterator::~PatternMapIterator() {
@@ -2542,36 +2542,36 @@ PatternMapIterator::set(PatternMap& newPatternMap) {
}
PtnSkeleton*
-PatternMapIterator::getSkeleton() const {
- if ( nodePtr == nullptr ) {
- return nullptr;
+PatternMapIterator::getSkeleton() const {
+ if ( nodePtr == nullptr ) {
+ return nullptr;
}
else {
- return nodePtr->skeleton.getAlias();
+ return nodePtr->skeleton.getAlias();
}
}
UBool
-PatternMapIterator::hasNext() const {
- int32_t headIndex = bootIndex;
- PtnElem *curPtr = nodePtr;
+PatternMapIterator::hasNext() const {
+ int32_t headIndex = bootIndex;
+ PtnElem *curPtr = nodePtr;
- if (patternMap==nullptr) {
+ if (patternMap==nullptr) {
return FALSE;
}
while ( headIndex < MAX_PATTERN_ENTRIES ) {
- if ( curPtr != nullptr ) {
- if ( curPtr->next != nullptr ) {
+ if ( curPtr != nullptr ) {
+ if ( curPtr->next != nullptr ) {
return TRUE;
}
else {
headIndex++;
- curPtr=nullptr;
+ curPtr=nullptr;
continue;
}
}
else {
- if ( patternMap->boot[headIndex] != nullptr ) {
+ if ( patternMap->boot[headIndex] != nullptr ) {
return TRUE;
}
else {
@@ -2586,19 +2586,19 @@ PatternMapIterator::hasNext() const {
DateTimeMatcher&
PatternMapIterator::next() {
while ( bootIndex < MAX_PATTERN_ENTRIES ) {
- if ( nodePtr != nullptr ) {
- if ( nodePtr->next != nullptr ) {
- nodePtr = nodePtr->next.getAlias();
+ if ( nodePtr != nullptr ) {
+ if ( nodePtr->next != nullptr ) {
+ nodePtr = nodePtr->next.getAlias();
break;
}
else {
bootIndex++;
- nodePtr=nullptr;
+ nodePtr=nullptr;
continue;
}
}
else {
- if ( patternMap->boot[bootIndex] != nullptr ) {
+ if ( patternMap->boot[bootIndex] != nullptr ) {
nodePtr = patternMap->boot[bootIndex];
break;
}
@@ -2608,7 +2608,7 @@ PatternMapIterator::next() {
}
}
}
- if (nodePtr!=nullptr) {
+ if (nodePtr!=nullptr) {
matcher->copyFrom(*nodePtr->skeleton);
}
else {
@@ -2686,8 +2686,8 @@ UChar SkeletonFields::getFirstChar() const {
}
-PtnSkeleton::PtnSkeleton()
- : addedDefaultDayPeriod(FALSE) {
+PtnSkeleton::PtnSkeleton()
+ : addedDefaultDayPeriod(FALSE) {
}
PtnSkeleton::PtnSkeleton(const PtnSkeleton& other) {
@@ -2698,7 +2698,7 @@ void PtnSkeleton::copyFrom(const PtnSkeleton& other) {
uprv_memcpy(type, other.type, sizeof(type));
original.copyFrom(other.original);
baseOriginal.copyFrom(other.baseOriginal);
- addedDefaultDayPeriod = other.addedDefaultDayPeriod;
+ addedDefaultDayPeriod = other.addedDefaultDayPeriod;
}
void PtnSkeleton::clear() {
@@ -2717,27 +2717,27 @@ PtnSkeleton::equals(const PtnSkeleton& other) const {
UnicodeString
PtnSkeleton::getSkeleton() const {
UnicodeString result;
- result = original.appendTo(result);
- int32_t pos;
- if (addedDefaultDayPeriod && (pos = result.indexOf(LOW_A)) >= 0) {
- // for backward compatibility: if DateTimeMatcher.set added a single 'a' that
- // was not in the provided skeleton, remove it here before returning skeleton.
- result.remove(pos, 1);
- }
- return result;
+ result = original.appendTo(result);
+ int32_t pos;
+ if (addedDefaultDayPeriod && (pos = result.indexOf(LOW_A)) >= 0) {
+ // for backward compatibility: if DateTimeMatcher.set added a single 'a' that
+ // was not in the provided skeleton, remove it here before returning skeleton.
+ result.remove(pos, 1);
+ }
+ return result;
}
UnicodeString
PtnSkeleton::getBaseSkeleton() const {
UnicodeString result;
- result = baseOriginal.appendTo(result);
- int32_t pos;
- if (addedDefaultDayPeriod && (pos = result.indexOf(LOW_A)) >= 0) {
- // for backward compatibility: if DateTimeMatcher.set added a single 'a' that
- // was not in the provided skeleton, remove it here before returning skeleton.
- result.remove(pos, 1);
- }
- return result;
+ result = baseOriginal.appendTo(result);
+ int32_t pos;
+ if (addedDefaultDayPeriod && (pos = result.indexOf(LOW_A)) >= 0) {
+ // for backward compatibility: if DateTimeMatcher.set added a single 'a' that
+ // was not in the provided skeleton, remove it here before returning skeleton.
+ result.remove(pos, 1);
+ }
+ return result;
}
UChar
@@ -2749,28 +2749,28 @@ PtnSkeleton::~PtnSkeleton() {
}
PtnElem::PtnElem(const UnicodeString &basePat, const UnicodeString &pat) :
- basePattern(basePat), skeleton(nullptr), pattern(pat), next(nullptr)
+ basePattern(basePat), skeleton(nullptr), pattern(pat), next(nullptr)
{
}
PtnElem::~PtnElem() {
}
-DTSkeletonEnumeration::DTSkeletonEnumeration(PatternMap& patternMap, dtStrEnum type, UErrorCode& status) : fSkeletons(nullptr) {
+DTSkeletonEnumeration::DTSkeletonEnumeration(PatternMap& patternMap, dtStrEnum type, UErrorCode& status) : fSkeletons(nullptr) {
PtnElem *curElem;
PtnSkeleton *curSkeleton;
UnicodeString s;
int32_t bootIndex;
pos=0;
- fSkeletons.adoptInsteadAndCheckErrorCode(new UVector(status), status);
+ fSkeletons.adoptInsteadAndCheckErrorCode(new UVector(status), status);
if (U_FAILURE(status)) {
return;
}
-
+
for (bootIndex=0; bootIndex<MAX_PATTERN_ENTRIES; ++bootIndex ) {
curElem = patternMap.boot[bootIndex];
- while (curElem!=nullptr) {
+ while (curElem!=nullptr) {
switch(type) {
case DT_BASESKELETON:
s=curElem->basePattern;
@@ -2779,36 +2779,36 @@ DTSkeletonEnumeration::DTSkeletonEnumeration(PatternMap& patternMap, dtStrEnum t
s=curElem->pattern;
break;
case DT_SKELETON:
- curSkeleton=curElem->skeleton.getAlias();
+ curSkeleton=curElem->skeleton.getAlias();
s=curSkeleton->getSkeleton();
break;
}
if ( !isCanonicalItem(s) ) {
- LocalPointer<UnicodeString> newElem(new UnicodeString(s), status);
- if (U_FAILURE(status)) {
- return;
- }
- fSkeletons->addElement(newElem.getAlias(), status);
+ LocalPointer<UnicodeString> newElem(new UnicodeString(s), status);
+ if (U_FAILURE(status)) {
+ return;
+ }
+ fSkeletons->addElement(newElem.getAlias(), status);
if (U_FAILURE(status)) {
- fSkeletons.adoptInstead(nullptr);
+ fSkeletons.adoptInstead(nullptr);
return;
}
- newElem.orphan(); // fSkeletons vector now owns the UnicodeString.
+ newElem.orphan(); // fSkeletons vector now owns the UnicodeString.
}
- curElem = curElem->next.getAlias();
+ curElem = curElem->next.getAlias();
}
}
- if ((bootIndex==MAX_PATTERN_ENTRIES) && (curElem!=nullptr) ) {
+ if ((bootIndex==MAX_PATTERN_ENTRIES) && (curElem!=nullptr) ) {
status = U_BUFFER_OVERFLOW_ERROR;
}
}
const UnicodeString*
DTSkeletonEnumeration::snext(UErrorCode& status) {
- if (U_SUCCESS(status) && fSkeletons.isValid() && pos < fSkeletons->size()) {
+ if (U_SUCCESS(status) && fSkeletons.isValid() && pos < fSkeletons->size()) {
return (const UnicodeString*)fSkeletons->elementAt(pos++);
}
- return nullptr;
+ return nullptr;
}
void
@@ -2818,7 +2818,7 @@ DTSkeletonEnumeration::reset(UErrorCode& /*status*/) {
int32_t
DTSkeletonEnumeration::count(UErrorCode& /*status*/) const {
- return (fSkeletons.isNull()) ? 0 : fSkeletons->size();
+ return (fSkeletons.isNull()) ? 0 : fSkeletons->size();
}
UBool
@@ -2836,45 +2836,45 @@ DTSkeletonEnumeration::isCanonicalItem(const UnicodeString& item) {
DTSkeletonEnumeration::~DTSkeletonEnumeration() {
UnicodeString *s;
- if (fSkeletons.isValid()) {
- for (int32_t i = 0; i < fSkeletons->size(); ++i) {
- if ((s = (UnicodeString *)fSkeletons->elementAt(i)) != nullptr) {
- delete s;
- }
+ if (fSkeletons.isValid()) {
+ for (int32_t i = 0; i < fSkeletons->size(); ++i) {
+ if ((s = (UnicodeString *)fSkeletons->elementAt(i)) != nullptr) {
+ delete s;
+ }
}
}
}
-DTRedundantEnumeration::DTRedundantEnumeration() : pos(0), fPatterns(nullptr) {
+DTRedundantEnumeration::DTRedundantEnumeration() : pos(0), fPatterns(nullptr) {
}
void
DTRedundantEnumeration::add(const UnicodeString& pattern, UErrorCode& status) {
- if (U_FAILURE(status)) { return; }
- if (fPatterns.isNull()) {
- fPatterns.adoptInsteadAndCheckErrorCode(new UVector(status), status);
+ if (U_FAILURE(status)) { return; }
+ if (fPatterns.isNull()) {
+ fPatterns.adoptInsteadAndCheckErrorCode(new UVector(status), status);
if (U_FAILURE(status)) {
return;
}
}
- LocalPointer<UnicodeString> newElem(new UnicodeString(pattern), status);
+ LocalPointer<UnicodeString> newElem(new UnicodeString(pattern), status);
if (U_FAILURE(status)) {
return;
}
- fPatterns->addElement(newElem.getAlias(), status);
- if (U_FAILURE(status)) {
- fPatterns.adoptInstead(nullptr);
- return;
- }
- newElem.orphan(); // fPatterns now owns the string.
+ fPatterns->addElement(newElem.getAlias(), status);
+ if (U_FAILURE(status)) {
+ fPatterns.adoptInstead(nullptr);
+ return;
+ }
+ newElem.orphan(); // fPatterns now owns the string.
}
const UnicodeString*
DTRedundantEnumeration::snext(UErrorCode& status) {
- if (U_SUCCESS(status) && fPatterns.isValid() && pos < fPatterns->size()) {
+ if (U_SUCCESS(status) && fPatterns.isValid() && pos < fPatterns->size()) {
return (const UnicodeString*)fPatterns->elementAt(pos++);
}
- return nullptr;
+ return nullptr;
}
void
@@ -2884,11 +2884,11 @@ DTRedundantEnumeration::reset(UErrorCode& /*status*/) {
int32_t
DTRedundantEnumeration::count(UErrorCode& /*status*/) const {
- return (fPatterns.isNull()) ? 0 : fPatterns->size();
+ return (fPatterns.isNull()) ? 0 : fPatterns->size();
}
UBool
-DTRedundantEnumeration::isCanonicalItem(const UnicodeString& item) const {
+DTRedundantEnumeration::isCanonicalItem(const UnicodeString& item) const {
if ( item.length() != 1 ) {
return FALSE;
}
@@ -2902,13 +2902,13 @@ DTRedundantEnumeration::isCanonicalItem(const UnicodeString& item) const {
DTRedundantEnumeration::~DTRedundantEnumeration() {
UnicodeString *s;
- if (fPatterns.isValid()) {
- for (int32_t i = 0; i < fPatterns->size(); ++i) {
- if ((s = (UnicodeString *)fPatterns->elementAt(i)) != nullptr) {
- delete s;
- }
+ if (fPatterns.isValid()) {
+ for (int32_t i = 0; i < fPatterns->size(); ++i) {
+ if ((s = (UnicodeString *)fPatterns->elementAt(i)) != nullptr) {
+ delete s;
+ }
}
- }
+ }
}
U_NAMESPACE_END