+void
+RelativeDateFormat::initCapitalizationContextInfo(const Locale& thelocale)
+{
+#if !UCONFIG_NO_BREAK_ITERATION
+ const char * localeID = (thelocale != NULL)? thelocale.getBaseName(): NULL;
+ UErrorCode status = U_ZERO_ERROR;
+ LocalUResourceBundlePointer rb(ures_open(NULL, localeID, &status));
+ ures_getByKeyWithFallback(rb.getAlias(),
+ "contextTransforms/relative",
+ rb.getAlias(), &status);
+ if (U_SUCCESS(status) && rb != NULL) {
+ int32_t len = 0;
+ const int32_t * intVector = ures_getIntVector(rb.getAlias(),
+ &len, &status);
+ if (U_SUCCESS(status) && intVector != NULL && len >= 2) {
+ fCapitalizationOfRelativeUnitsForUIListMenu = static_cast<UBool>(intVector[0]);
+ fCapitalizationOfRelativeUnitsForStandAlone = static_cast<UBool>(intVector[1]);
+ }
+ }
+#endif
+}
+
+namespace {
+
+/**
+ * Sink for getting data from fields/day/relative data.
+ * For loading relative day names, e.g., "yesterday", "today".
+ */
+
+struct RelDateFmtDataSink : public ResourceSink {
+ URelativeString *fDatesPtr;
+ int32_t fDatesLen;
+
+ RelDateFmtDataSink(URelativeString* fDates, int32_t len) : fDatesPtr(fDates), fDatesLen(len) {
+ for (int32_t i = 0; i < fDatesLen; ++i) {
+ fDatesPtr[i].offset = 0;
+ fDatesPtr[i].string = NULL;
+ fDatesPtr[i].len = -1;
+ }
+ }
+
+ virtual ~RelDateFmtDataSink();
+
+ virtual void put(const char *key, ResourceValue &value,
+ UBool /*noFallback*/, UErrorCode &errorCode) {
+ ResourceTable relDayTable = value.getTable(errorCode);
+ int32_t n = 0;
+ int32_t len = 0;
+ for (int32_t i = 0; relDayTable.getKeyAndValue(i, key, value); ++i) {
+ // Find the relative offset.
+ int32_t offset = atoi(key);
+
+ // Put in the proper spot, but don't override existing data.
+ n = offset + UDAT_DIRECTION_THIS; // Converts to index in UDAT_R
+ if (n < fDatesLen && fDatesPtr[n].string == NULL) {
+ // Not found and n is an empty slot.
+ fDatesPtr[n].offset = offset;
+ fDatesPtr[n].string = value.getString(len, errorCode);
+ fDatesPtr[n].len = len;
+ }
+ }
+ }
+};
+
+
+// Virtual destructors must be defined out of line.
+RelDateFmtDataSink::~RelDateFmtDataSink() {}
+
+} // Namespace
+
+
+static const UChar patItem1[] = {0x7B,0x31,0x7D}; // "{1}"
+static const int32_t patItem1Len = 3;
+