+// Resource keys to look up localized strings for day periods.
+// The first one must be midnight and the second must be noon, so that their indices coincide
+// with the am/pm field. Formatting and parsing code for day periods relies on this coincidence.
+static const char *dayPeriodKeys[] = {"midnight", "noon",
+ "morning1", "afternoon1", "evening1", "night1",
+ "morning2", "afternoon2", "evening2", "night2"};
+
+UnicodeString* loadDayPeriodStrings(CalendarData &calData, const char *tag, UBool standalone,
+ int32_t &stringCount, UErrorCode &status) {
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ UResourceBundle *dayPeriodData;
+
+ if (standalone) {
+ dayPeriodData = calData.getByKey3(gDayPeriodTag, gNamesStandaloneTag, tag, status);
+ } else {
+ dayPeriodData = calData.getByKey2(gDayPeriodTag, tag, status);
+ }
+
+ stringCount = UPRV_LENGTHOF(dayPeriodKeys);
+ UnicodeString *strings = new UnicodeString[stringCount];
+ for (int32_t i = 0; i < stringCount; ++i) {
+ //TODO: Check if there are fallbacks/aliases defined in the data; e.g., if there
+ //is no wide string, then use the narrow one?
+ strings[i].fastCopyFrom(ures_getUnicodeStringByKey(dayPeriodData, dayPeriodKeys[i], &status));
+ if (U_FAILURE(status)) {
+ // string[i] will be bogus if ures_getUnicodeString() returns with an error,
+ // which is just the behavior we want. Simply reset the error code.
+ status = U_ZERO_ERROR;
+ }
+ }
+ return strings;
+}
+