* Dick Porter (dick@ximian.com)
* Mohammad DAMT (mdamt@cdl2000.com)
*
- * (C) 2003 Ximian, Inc.
+ * Copyright 2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
* (C) 2003 PT Cakram Datalingga Duaribu http://www.cdl2000.com
*/
#include <mono/metadata/locales.h>
#include <mono/metadata/culture-info.h>
#include <mono/metadata/culture-info-tables.h>
-#include <mono/metadata/normalization-tables.h>
+#ifndef DISABLE_NORMALIZATION
+#include <mono/metadata/normalization-tables.h>
+#endif
#include <locale.h>
+#if defined(__APPLE__)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
#undef DEBUG
len++;
}
- ret = mono_array_new (mono_domain_get (),
+ ret = mono_array_new_cached (mono_domain_get (),
mono_get_int32_class (), len);
for(i = 0; i < len; i++)
len++;
}
- ret = mono_array_new (mono_domain_get (), mono_get_string_class (), len);
+ ret = mono_array_new_cached (mono_domain_get (), mono_get_string_class (), len);
for(i = 0; i < len; i++)
mono_array_setref (ret, i, mono_string_new (domain, idx2string (names [i])));
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];
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*
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
if ((p = strchr (locale, '.')) != NULL) {
/* assume new locale can't be larger than old one? */
- corrected = malloc (strlen (locale));
+ corrected = g_malloc (strlen (locale));
strncpy (corrected, locale, p - locale);
corrected [p - locale] = 0;
*/
if (corrected == NULL) {
- corrected = malloc (strlen (locale));
+ corrected = g_malloc (strlen (locale));
strncpy (corrected, locale, p - locale);
corrected [p - locale] = 0;
}
if ((c = strchr (corrected, '_')) != NULL)
*c = '-';
- g_strdown (corrected);
+ c = corrected;
+ corrected = g_ascii_strdown (c, -1);
+ g_free (c);
return corrected;
}
gint32 options)
{
gint32 result;
- GUnicodeType c1type, c2type;
/* Ordinal can not be mixed with other options, and must return the difference, not only -1, 0, 1 */
if (options & CompareOptions_Ordinal)
return (gint32) c1 - c2;
- c1type = g_unichar_type (c1);
- c2type = g_unichar_type (c2);
-
if (options & CompareOptions_IgnoreCase) {
+ GUnicodeType c1type, c2type;
+
+ c1type = g_unichar_type (c1);
+ c2type = g_unichar_type (c2);
+
result = (gint32) (c1type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c1) : c1) -
(c2type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c2) : c2);
} else {
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
}