- memcpy(en, &defaultKeywordValues, sizeof(UEnumeration));
- en->context = results;
-
- /* Open the resource bundle for collation with the given locale. */
- UResourceBundle bundle, collations, collres, defres;
- ures_initStackObject(&bundle);
- ures_initStackObject(&collations);
- ures_initStackObject(&collres);
- ures_initStackObject(&defres);
-
- ures_openFillIn(&bundle, U_ICUDATA_COLL, localeBuffer, status);
-
- while (U_SUCCESS(*status)) {
- ures_getByKey(&bundle, RESOURCE_NAME, &collations, status);
- ures_resetIterator(&collations);
- while (U_SUCCESS(*status) && ures_hasNext(&collations)) {
- ures_getNextResource(&collations, &collres, status);
- const char *key = ures_getKey(&collres);
- /* If the key is default, get the string and store it in results list only
- * if results list is empty.
- */
- if (uprv_strcmp(key, "default") == 0) {
- if (ulist_getListSize(results) == 0) {
- char *defcoll = (char *)uprv_malloc(sizeof(char) * ULOC_KEYWORDS_CAPACITY);
- int32_t defcollLength = ULOC_KEYWORDS_CAPACITY;
-
- ures_getNextResource(&collres, &defres, status);
-#if U_CHARSET_FAMILY==U_ASCII_FAMILY
- /* optimize - use the utf-8 string */
- ures_getUTF8String(&defres, defcoll, &defcollLength, TRUE, status);
-#else
- {
- const UChar* defString = ures_getString(&defres, &defcollLength, status);
- if(U_SUCCESS(*status)) {
- if(defcollLength+1 > ULOC_KEYWORDS_CAPACITY) {
- *status = U_BUFFER_OVERFLOW_ERROR;
- } else {
- u_UCharsToChars(defString, defcoll, defcollLength+1);
- }
- }
+struct KeywordsSink : public ResourceSink {
+public:
+ KeywordsSink(UErrorCode &errorCode) :
+ values(ulist_createEmptyList(&errorCode)), hasDefault(FALSE) {}
+ virtual ~KeywordsSink();
+
+ virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
+ UErrorCode &errorCode) {
+ if (U_FAILURE(errorCode)) { return; }
+ ResourceTable collations = value.getTable(errorCode);
+ for (int32_t i = 0; collations.getKeyAndValue(i, key, value); ++i) {
+ UResType type = value.getType();
+ if (type == URES_STRING) {
+ if (!hasDefault && uprv_strcmp(key, "default") == 0) {
+ CharString defcoll;
+ defcoll.appendInvariantChars(value.getUnicodeString(errorCode), errorCode);
+ if (U_SUCCESS(errorCode) && !defcoll.isEmpty()) {
+ char *ownedDefault = uprv_strdup(defcoll.data());
+ if (ownedDefault == NULL) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ ulist_removeString(values, defcoll.data());
+ ulist_addItemBeginList(values, ownedDefault, TRUE, &errorCode);
+ hasDefault = TRUE;