+StringEnumeration* NumberingSystem::getAvailableNames(UErrorCode &status) {
+ // TODO(ticket #11908): Init-once static cache, with u_cleanup() callback.
+ static StringEnumeration* availableNames = NULL;
+
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ if ( availableNames == NULL ) {
+ // TODO: Simple array of UnicodeString objects, based on length of table resource?
+ LocalPointer<UVector> numsysNames(new UVector(uprv_deleteUObject, NULL, status), status);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+
+ UErrorCode rbstatus = U_ZERO_ERROR;
+ UResourceBundle *numberingSystemsInfo = ures_openDirect(NULL, "numberingSystems", &rbstatus);
+ numberingSystemsInfo = ures_getByKey(numberingSystemsInfo,"numberingSystems",numberingSystemsInfo,&rbstatus);
+ if(U_FAILURE(rbstatus)) {
+ status = U_MISSING_RESOURCE_ERROR;
+ ures_close(numberingSystemsInfo);
+ return NULL;
+ }
+
+ while ( ures_hasNext(numberingSystemsInfo) ) {
+ UResourceBundle *nsCurrent = ures_getNextResource(numberingSystemsInfo,NULL,&rbstatus);
+ const char *nsName = ures_getKey(nsCurrent);
+ numsysNames->addElement(new UnicodeString(nsName, -1, US_INV),status);
+ ures_close(nsCurrent);
+ }
+
+ ures_close(numberingSystemsInfo);
+ if (U_FAILURE(status)) {
+ return NULL;
+ }
+ availableNames = new NumsysNameEnumeration(numsysNames.getAlias(), status);
+ if (availableNames == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+ numsysNames.orphan(); // The names got adopted.
+ }