Simplify locale fetching, we have very simple needs
authorMiguel de Icaza <miguel@gnome.org>
Thu, 12 Sep 2013 21:21:39 +0000 (17:21 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 12 Sep 2013 21:21:39 +0000 (17:21 -0400)
mono/metadata/locales.c

index 1b8be8ade966d7f3dfd329fc13158f6fd0cac35a..0c7ab4b2f6b0e72767ee0fab20e5c7989926425c 100644 (file)
@@ -356,40 +356,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)
@@ -430,14 +396,34 @@ get_darwin_locale (void)
 }
 #endif
 
-static gchar*
-get_current_locale_name (void)
+static char *
+get_posix_locale ()
 {
-       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__)      
@@ -446,52 +432,23 @@ 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) {
+       p = strchr (locale, '.');
+       if (p != NULL)
+               *p = 0;
+       p = strchr (locale, '@');
+       if (p != NULL)
+               *p = 0;
 
-               /*
-                * 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);
+       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)