Merge branch 'master' into msbuilddll2
[mono.git] / mono / metadata / locales.c
index b652e77549182c3c041373c029a05a632064b258..7fffad9cc8c5bf8206e0b34cefc24362c19d081a 100644 (file)
@@ -306,28 +306,6 @@ construct_region (MonoRegionInfo *this, const RegionInfoEntry *ri)
        return TRUE;
 }
 
-static gboolean
-construct_culture_from_specific_name (MonoCultureInfo *ci, gchar *name)
-{
-       const CultureInfoEntry *entry;
-       const CultureInfoNameEntry *ne;
-
-       MONO_ARCH_SAVE_REGS;
-
-       ne = mono_binary_search (name, culture_name_entries, NUM_CULTURE_ENTRIES,
-                       sizeof (CultureInfoNameEntry), culture_name_locator);
-
-       if (ne == NULL)
-               return FALSE;
-
-       entry = &culture_entries [ne->culture_entry_index];
-
-       if (entry)
-               return construct_culture (ci, entry);
-       else
-               return FALSE;
-}
-
 static const CultureInfoEntry*
 culture_info_entry_from_lcid (int lcid)
 {
@@ -356,40 +334,6 @@ region_info_entry_from_lcid (int lcid)
        return entry;
 }
 
-/*
- * The following two methods are modified from the ICU source code. (http://oss.software.ibm.com/icu)
- * Copyright (c) 1995-2003 International Business Machines Corporation and others
- * All rights reserved.
- */
-static gchar*
-get_posix_locale (void)
-{
-       const gchar* posix_locale = NULL;
-
-       posix_locale = g_getenv("LC_ALL");
-       if (posix_locale == 0) {
-               posix_locale = g_getenv("LANG");
-               if (posix_locale == 0) {
-                       posix_locale = setlocale(LC_ALL, NULL);
-               }
-       }
-
-       if (posix_locale == NULL)
-               return NULL;
-
-       if ((strcmp ("C", posix_locale) == 0) || (strchr (posix_locale, ' ') != NULL)
-                       || (strchr (posix_locale, '/') != NULL)) {
-               /*
-                * HPUX returns 'C C C C C C C'
-                * Solaris can return /en_US/C/C/C/C/C on the second try.
-                * Maybe we got some garbage.
-                */
-               return NULL;
-       }
-
-       return g_strdup (posix_locale);
-}
-
 #if defined (__APPLE__)
 static gchar*
 get_darwin_locale (void)
@@ -435,7 +379,7 @@ get_darwin_locale (void)
                                }
 
                                CFStringGetBytes (locale_country, CFRangeMake (0, CFStringGetLength (locale_country)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) &darwin_locale[bytes_written], len - bytes_written, &bytes_converted);
-                               darwin_locale[bytes_written + bytes_converted] = NULL;
+                               darwin_locale[bytes_written + bytes_converted] = '\0';
                        }
                }
 
@@ -465,14 +409,34 @@ get_darwin_locale (void)
 }
 #endif
 
-static gchar*
-get_current_locale_name (void)
+static char *
+get_posix_locale (void)
 {
-       gchar *locale;
-       gchar *corrected = NULL;
-       const gchar *p;
-       gchar *c;
+       const char *locale;
+
+       locale = g_getenv ("LC_ALL");
+       if (locale == NULL) {
+               locale = g_getenv ("LANG");
+               if (locale == NULL)
+                       locale = setlocale (LC_ALL, NULL);
+       }
+       if (locale == NULL)
+               return NULL;
+
+       /* Skip English-only locale 'C' */
+       if (strcmp (locale, "C") == 0)
+               return NULL;
 
+       return g_strdup (locale);
+}
+
+
+static gchar *
+get_current_locale_name (void)
+{
+       char *locale;
+       char *p, *ret;
+               
 #ifdef HOST_WIN32
        locale = g_win32_getlocale ();
 #elif defined (__APPLE__)      
@@ -481,69 +445,43 @@ get_current_locale_name (void)
                locale = get_posix_locale ();
 #else
        locale = get_posix_locale ();
-#endif 
+#endif
 
        if (locale == NULL)
                return NULL;
 
-       if ((p = strchr (locale, '.')) != NULL) {
-               /* assume new locale can't be larger than old one? */
-               corrected = g_malloc (strlen (locale));
-               strncpy (corrected, locale, p - locale);
-               corrected [p - locale] = 0;
-
-               /* do not copy after the @ */
-               if ((p = strchr (corrected, '@')) != NULL)
-                       corrected [p - corrected] = 0;
-       }
-
-       /* Note that we scan the *uncorrected* ID. */
-       if ((p = strrchr (locale, '@')) != NULL) {
-
-               /*
-                * In Mono we dont handle the '@' modifier because we do
-                * not have any cultures that use it. We just trim it
-                * off of the end of the name.
-                */
-
-               if (corrected == NULL) {
-                       corrected = g_malloc (strlen (locale));
-                       strncpy (corrected, locale, p - locale);
-                       corrected [p - locale] = 0;
-               }
-       }
-
-       if (corrected == NULL)
-               corrected = locale;
-       else
-               g_free (locale);
-
-       if ((c = strchr (corrected, '_')) != NULL)
-               *c = '-';
-
-       c = corrected;
-       corrected = g_ascii_strdown (c, -1);
-       g_free (c);
+       p = strchr (locale, '.');
+       if (p != NULL)
+               *p = 0;
+       p = strchr (locale, '@');
+       if (p != NULL)
+               *p = 0;
+       p = strchr (locale, '_');
+       if (p != NULL)
+               *p = '-';
+
+       ret = g_ascii_strdown (locale, -1);
+       g_free (locale);
 
-       return corrected;
-}       
+       return ret;
+}
 
-MonoBoolean
-ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale (MonoCultureInfo *ci)
+MonoString*
+ves_icall_System_Globalization_CultureInfo_get_current_locale_name (void)
 {
        gchar *locale;
-       gboolean ret;
+       MonoString* ret;
+       MonoDomain *domain;
 
        MONO_ARCH_SAVE_REGS;
 
        locale = get_current_locale_name ();
        if (locale == NULL)
-               return FALSE;
+               return NULL;
 
-       ret = construct_culture_from_specific_name (ci, locale);
+       domain = mono_domain_get ();
+       ret = mono_string_new (domain, locale);
        g_free (locale);
-       ci->is_read_only = TRUE;
-       ci->use_user_override = TRUE;
 
        return ret;
 }
@@ -585,7 +523,7 @@ ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name (
 
        return construct_culture (this, &culture_entries [ne->culture_entry_index]);
 }
-
+/*
 MonoBoolean
 ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name (MonoCultureInfo *ci,
                MonoString *name)
@@ -601,7 +539,7 @@ ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specif
 
        return ret;
 }
-
+*/
 MonoBoolean
 ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_lcid (MonoRegionInfo *this,
                gint lcid)