X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mono%2Fmetadata%2Flocales.c;h=e188ee4ae49a480b08034d7652af0868f61e2c5f;hb=e152071d2a0061d7aa6d7f40b220b78f43132aa2;hp=9d977d1e85e2b00979fc9584366cae42c9a18527;hpb=6f2b5cd69f33daad2303e46311e7333239dadfdc;p=mono.git diff --git a/mono/metadata/locales.c b/mono/metadata/locales.c index 9d977d1e85e..e188ee4ae49 100644 --- a/mono/metadata/locales.c +++ b/mono/metadata/locales.c @@ -22,10 +22,15 @@ #include #include #include -#include +#ifndef DISABLE_NORMALIZATION +#include +#endif #include +#if defined(__APPLE__) +#include +#endif #undef DEBUG @@ -195,6 +200,8 @@ ves_icall_System_Globalization_CultureInfo_construct_number_format (MonoCultureI MONO_ARCH_SAVE_REGS; g_assert (this->number_format != 0); + if (this->number_index < 0) + return; number = this->number_format; nfe = &number_format_entries [this->number_index]; @@ -301,7 +308,10 @@ construct_culture_from_specific_name (MonoCultureInfo *ci, gchar *name) if (entry->lcid != entry->specific_lcid) entry = culture_info_entry_from_lcid (entry->specific_lcid); - return construct_culture (ci, entry); + if (entry) + return construct_culture (ci, entry); + else + return FALSE; } static const CultureInfoEntry* @@ -369,17 +379,61 @@ get_posix_locale (void) return g_strdup (posix_locale); } +#if defined (__APPLE__) +static gchar* +get_darwin_locale (void) +{ + static gchar *darwin_locale = NULL; + CFLocaleRef locale = NULL; + CFStringRef locale_cfstr = NULL; + CFIndex len; + int i; + + if (darwin_locale != NULL) + return g_strdup (darwin_locale); + + locale = CFLocaleCopyCurrent (); + + if (locale) { + locale_cfstr = CFLocaleGetIdentifier (locale); + + if (locale_cfstr) { + len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1; + darwin_locale = (char *) malloc (len); + if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) { + free (darwin_locale); + CFRelease (locale); + darwin_locale = NULL; + return NULL; + } + + for (i = 0; i < strlen (darwin_locale); i++) + if (darwin_locale [i] == '_') + darwin_locale [i] = '-'; + } + + CFRelease (locale); + } + + return g_strdup (darwin_locale); +} +#endif + static gchar* get_current_locale_name (void) { gchar *locale; gchar *corrected = NULL; const gchar *p; - gchar *c; + gchar *c; -#ifdef PLATFORM_WIN32 +#ifdef HOST_WIN32 locale = g_win32_getlocale (); -#else +#elif defined (__APPLE__) + locale = get_darwin_locale (); + if (!locale) + locale = get_posix_locale (); +#else locale = get_posix_locale (); #endif @@ -927,12 +981,16 @@ void load_normalization_resource (guint8 **argProps, guint8 **argMapIdxToComposite, guint8 **argCombiningClass) { +#ifdef DISABLE_NORMALIZATION + mono_raise_exception (mono_get_exception_not_supported ("This runtime has been compiled without string normalization support.")); +#else *argProps = (guint8*)props; *argMappedChars = (guint8*) mappedChars; *argCharMapIndex = (guint8*) charMapIndex; *argHelperIndex = (guint8*) helperIndex; *argMapIdxToComposite = (guint8*) mapIdxToComposite; *argCombiningClass = (guint8*)combiningClass; +#endif }