rtl_TextEncoding osl_getTextEncodingFromLocale( rtl_Locale * pLocale ) { const _pair *language = 0; char locale_buf[64] = ""; char *cp; WinMessageBox(HWND_DESKTOP,HWND_DESKTOP, "Please contact technical support and report above informations.\n\n", "Critical error: osl_getTextEncodingFromLocale", 0, MB_ERROR | MB_OK | MB_MOVEABLE); /* default to process locale if pLocale == NULL */ if( NULL == pLocale ) osl_getProcessLocale( &pLocale ); /* convert rtl_Locale to locale string */ if( _compose_locale( pLocale, locale_buf, 64 ) ) { /* check special handling list (EUC) first */ const unsigned int members = sizeof( _full_locale_list ) / sizeof( _pair ); language = _pair_search( locale_buf, _full_locale_list, members); if( NULL == language ) { /* * check if there is a charset qualifier at the end of the given locale string * e.g. de.ISO8859-15 or de.ISO8859-15@euro which strongly indicates what * charset to use */ cp = strrchr( locale_buf, '.' ); if( NULL != cp ) { const unsigned int members = sizeof( _locale_extension_list ) / sizeof( _pair ); language = _pair_search( cp + 1, _locale_extension_list, members); } } /* use iso language code to determine the charset */ if( NULL == language ) { const unsigned int members = sizeof( _iso_language_list ) / sizeof( _pair ); /* iso lang codes have 2 charaters */ locale_buf[2] = '\0'; language = _pair_search( locale_buf, _iso_language_list, members); } } /* a matching item in our list provides a mapping from codeset to * rtl-codeset */ if ( language != NULL ) return language->value; return RTL_TEXTENCODING_DONTKNOW; }
rtl_TextEncoding osl_getTextEncodingFromLocale( rtl_Locale * pLocale ) { const _pair *language = 0; char locale_buf[64] = ""; char *cp; /* default to process locale if pLocale == NULL */ if( NULL == pLocale ) osl_getProcessLocale( &pLocale ); /* convert rtl_Locale to locale string */ if( _compose_locale( pLocale, locale_buf, 64 ) ) { /* check special handling list (EUC) first */ language = _pair_search( locale_buf, _full_locale_list, SAL_N_ELEMENTS( _full_locale_list ) ); if( NULL == language ) { /* * check if there is a charset qualifier at the end of the given locale string * e.g. de.ISO8859-15 or de.ISO8859-15@euro which strongly indicates what * charset to use */ cp = strrchr( locale_buf, '.' ); if( NULL != cp ) { language = _pair_search( cp + 1, _locale_extension_list, SAL_N_ELEMENTS( _locale_extension_list ) ); } } /* use iso language code to determine the charset */ if( NULL == language ) { /* iso lang codes have 2 charaters */ locale_buf[2] = '\0'; language = _pair_search( locale_buf, _iso_language_list, SAL_N_ELEMENTS( _iso_language_list ) ); } } /* a matching item in our list provides a mapping from codeset to * rtl-codeset */ if ( language != NULL ) return language->value; return RTL_TEXTENCODING_DONTKNOW; }
rtl_TextEncoding SAL_CALL osl_getTextEncodingFromLocale( rtl_Locale * pLocale ) { struct EnumLocalesParams params = { L"", L"", 0 }; /* initialise global TLS id */ if( (DWORD) -1 == g_dwTLSLocaleEncId ) { oslMutex globalMutex = * osl_getGlobalMutex(); /* initializing must be thread save */ osl_acquireMutex( globalMutex ); if( (DWORD) -1 == g_dwTLSLocaleEncId ) g_dwTLSLocaleEncId = TlsAlloc(); osl_releaseMutex( globalMutex ); } /* if pLocale is NULL, use process locale as default */ if( NULL == pLocale ) osl_getProcessLocale( &pLocale ); /* copy in parameters to structure */ if( pLocale && pLocale->Language && pLocale->Language->length < ELP_LANGUAGE_FIELD_LENGTH ) { wcscpy( params.Language, pLocale->Language->buffer ); if( pLocale->Country && pLocale->Country->length < ELP_COUNTRY_FIELD_LENGTH ) wcscpy( params.Country, pLocale->Country->buffer ); /* save pointer to local structure in TLS */ TlsSetValue( g_dwTLSLocaleEncId, ¶ms ); /* enum all locales known to Windows */ EnumSystemLocalesA( EnumLocalesProcA, LCID_SUPPORTED ); /* use the LCID found in iteration */ return GetTextEncodingFromLCID( params.Locale ); } return RTL_TEXTENCODING_DONTKNOW; }
rtl_TextEncoding osl_getTextEncodingFromLocale( rtl_Locale * pLocale ) { const _pair *language=0; char locale_buf[64] = ""; char codeset_buf[64]; char *ctype_locale = 0; char *codeset = 0; /* default to process locale if pLocale == NULL */ if( NULL == pLocale ) osl_getProcessLocale( &pLocale ); /* convert rtl_Locale to locale string */ _compose_locale( pLocale, locale_buf, 64 ); /* basic thread safeness */ pthread_mutex_lock( &aLocalMutex ); /* remember the charset as indicated by the LC_CTYPE locale */ ctype_locale = setlocale( LC_CTYPE, NULL ); /* set the desired LC_CTYPE locale */ if( NULL == setlocale( LC_CTYPE, locale_buf ) ) { pthread_mutex_unlock(&aLocalMutex); return RTL_TEXTENCODING_DONTKNOW; } /* get the charset as indicated by the LC_CTYPE locale */ #if defined(NETBSD) && !defined(CODESET) codeset = NULL; #else codeset = nl_langinfo( CODESET ); #endif if ( codeset != NULL ) { /* get codeset into mt save memory */ strncpy( codeset_buf, codeset, sizeof(codeset_buf) ); codeset_buf[sizeof(codeset_buf) - 1] = 0; codeset = codeset_buf; } /* restore the original value of locale */ if ( ctype_locale != NULL ) setlocale( LC_CTYPE, ctype_locale ); pthread_mutex_unlock( &aLocalMutex ); /* search the codeset in our language list */ if ( codeset != NULL ) { language = _pair_search (codeset, _nl_language_list, SAL_N_ELEMENTS( _nl_language_list ) ); } OSL_ASSERT( language && ( RTL_TEXTENCODING_DONTKNOW != language->value ) ); /* a matching item in our list provides a mapping from codeset to * rtl-codeset */ if ( language != NULL ) return language->value; return RTL_TEXTENCODING_DONTKNOW; }