-UnicodeString&
-Locale::getDisplayLanguage(UnicodeString& dispLang) const
-{
- return this->getDisplayLanguage(getDefault(), dispLang);
-}
-
-/*We cannot make any assumptions on the size of the output display strings
-* Yet, since we are calling through to a C API, we need to set limits on
-* buffer size. For all the following getDisplay functions we first attempt
-* to fill up a stack allocated buffer. If it is to small we heap allocated
-* the exact buffer we need copy it to the UnicodeString and delete it*/
-
-UnicodeString&
-Locale::getDisplayLanguage(const Locale &displayLocale,
- UnicodeString &result) const {
- UChar *buffer;
- UErrorCode errorCode=U_ZERO_ERROR;
- int32_t length;
-
- buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
-
- length=uloc_getDisplayLanguage(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
-
- if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
- buffer=result.getBuffer(length);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
- errorCode=U_ZERO_ERROR;
- length=uloc_getDisplayLanguage(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
- }
-
- return result;
-}
-
-UnicodeString&
-Locale::getDisplayScript(UnicodeString& dispScript) const
-{
- return this->getDisplayScript(getDefault(), dispScript);
-}
-
-UnicodeString&
-Locale::getDisplayScript(const Locale &displayLocale,
- UnicodeString &result) const {
- UChar *buffer;
- UErrorCode errorCode=U_ZERO_ERROR;
- int32_t length;
-
- buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
-
- length=uloc_getDisplayScript(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
-
- if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
- buffer=result.getBuffer(length);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
- errorCode=U_ZERO_ERROR;
- length=uloc_getDisplayScript(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
- }
-
- return result;
-}
-
-UnicodeString&
-Locale::getDisplayCountry(UnicodeString& dispCntry) const
-{
- return this->getDisplayCountry(getDefault(), dispCntry);
-}
-
-UnicodeString&
-Locale::getDisplayCountry(const Locale &displayLocale,
- UnicodeString &result) const {
- UChar *buffer;
- UErrorCode errorCode=U_ZERO_ERROR;
- int32_t length;
-
- buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
-
- length=uloc_getDisplayCountry(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
-
- if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
- buffer=result.getBuffer(length);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
- errorCode=U_ZERO_ERROR;
- length=uloc_getDisplayCountry(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
- }
-
- return result;
-}
-
-UnicodeString&
-Locale::getDisplayVariant(UnicodeString& dispVar) const
-{
- return this->getDisplayVariant(getDefault(), dispVar);
-}
-
-UnicodeString&
-Locale::getDisplayVariant(const Locale &displayLocale,
- UnicodeString &result) const {
- UChar *buffer;
- UErrorCode errorCode=U_ZERO_ERROR;
- int32_t length;
-
- buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
-
- length=uloc_getDisplayVariant(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
-
- if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
- buffer=result.getBuffer(length);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
- errorCode=U_ZERO_ERROR;
- length=uloc_getDisplayVariant(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
- }
-
- return result;
-}
-
-UnicodeString&
-Locale::getDisplayName( UnicodeString& name ) const
-{
- return this->getDisplayName(getDefault(), name);
-}
-
-UnicodeString&
-Locale::getDisplayName(const Locale &displayLocale,
- UnicodeString &result) const {
- UChar *buffer;
- UErrorCode errorCode=U_ZERO_ERROR;
- int32_t length;
-
- buffer=result.getBuffer(ULOC_FULLNAME_CAPACITY);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
-
- length=uloc_getDisplayName(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
-
- if(errorCode==U_BUFFER_OVERFLOW_ERROR) {
- buffer=result.getBuffer(length);
- if(buffer==0) {
- result.truncate(0);
- return result;
- }
- errorCode=U_ZERO_ERROR;
- length=uloc_getDisplayName(fullName, displayLocale.fullName,
- buffer, result.getCapacity(),
- &errorCode);
- result.releaseBuffer(U_SUCCESS(errorCode) ? length : 0);
- }
-
- return result;
-}
-const Locale* U_EXPORT2
-Locale::getAvailableLocales(int32_t& count)
-{
- // for now, there is a hardcoded list, so just walk through that list and set it up.
- umtx_lock(NULL);
- UBool needInit = availableLocaleList == 0;
- umtx_unlock(NULL);
-
- if (needInit) {
- int32_t locCount = uloc_countAvailable();
- Locale *newLocaleList = 0;
- if(locCount) {
- newLocaleList = new Locale[locCount];
- }
- if (newLocaleList == NULL) {
- count = 0;
- return NULL;
- }
-
- count = locCount;
-
- while(--locCount >= 0) {
- newLocaleList[locCount].setFromPOSIXID(uloc_getAvailable(locCount));
- }
-
- umtx_lock(NULL);
- if(availableLocaleList == 0) {
- availableLocaleListCount = count;
- availableLocaleList = newLocaleList;
- newLocaleList = NULL;
- ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
- }
- umtx_unlock(NULL);
- delete []newLocaleList;
- }
- count = availableLocaleListCount;
- return availableLocaleList;
-}
-