X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Flocales.c;h=2adadc6ed6ea52e638f47b2e74e0a03fabf3ae3f;hb=ef0ddf45c3081e799edcb4e95770186514b80cf1;hp=3ff9598c04e426830db418d27e829451d249424f;hpb=8b10aac7533570a50a63e9716c39f0efd49b0be1;p=mono.git diff --git a/mono/metadata/locales.c b/mono/metadata/locales.c index 3ff9598c04e..2adadc6ed6e 100644 --- a/mono/metadata/locales.c +++ b/mono/metadata/locales.c @@ -10,6 +10,7 @@ * Copyright 2004-2009 Novell, Inc (http://www.novell.com) * (C) 2003 PT Cakram Datalingga Duaribu http://www.cdl2000.com * Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com) + * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ #include @@ -43,9 +44,6 @@ static gint32 string_invariant_compare (MonoString *str1, gint32 off1, gint32 len1, MonoString *str2, gint32 off2, gint32 len2, gint32 options); -static MonoString *string_invariant_replace (MonoString *me, - MonoString *oldValue, - MonoString *newValue); static gint32 string_invariant_indexof (MonoString *source, gint32 sindex, gint32 count, MonoString *value, MonoBoolean first); @@ -57,11 +55,14 @@ static const CultureInfoEntry* culture_info_entry_from_lcid (int lcid); static const RegionInfoEntry* region_info_entry_from_lcid (int lcid); +/* Lazy class loading functions */ +static GENERATE_GET_CLASS_WITH_CACHE (culture_info, System.Globalization, CultureInfo) + static int culture_lcid_locator (const void *a, const void *b) { - const int *lcid = a; - const CultureInfoEntry *bb = b; + const int *lcid = (const int *)a; + const CultureInfoEntry *bb = (const CultureInfoEntry *)b; return *lcid - bb->lcid; } @@ -69,8 +70,8 @@ culture_lcid_locator (const void *a, const void *b) static int culture_name_locator (const void *a, const void *b) { - const char *aa = a; - const CultureInfoNameEntry *bb = b; + const char *aa = (const char *)a; + const CultureInfoNameEntry *bb = (const CultureInfoNameEntry *)b; int ret; ret = strcmp (aa, idx2string (bb->name)); @@ -81,8 +82,8 @@ culture_name_locator (const void *a, const void *b) static int region_name_locator (const void *a, const void *b) { - const char *aa = a; - const RegionInfoNameEntry *bb = b; + const char *aa = (const char *)a; + const RegionInfoNameEntry *bb = (const RegionInfoNameEntry *)b; int ret; ret = strcmp (aa, idx2string (bb->name)); @@ -167,7 +168,7 @@ ves_icall_System_Globalization_CalendarData_fill_calendar_data (MonoCalendarData char *n; n = mono_string_to_utf8 (name); - ne = mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES, + ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoNameEntry), culture_name_locator); g_free (n); if (ne == NULL) { @@ -231,7 +232,7 @@ ves_icall_System_Globalization_CultureData_fill_number_data (MonoNumberFormatInf MonoDomain *domain; const NumberFormatEntry *nfe; - g_assert (number_index != 0); + g_assert (number_index >= 0); nfe = &number_format_entries [number_index]; @@ -317,7 +318,7 @@ culture_info_entry_from_lcid (int lcid) { const CultureInfoEntry *ci; - ci = mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator); + ci = (const CultureInfoEntry *)mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator); return ci; } @@ -328,7 +329,7 @@ region_info_entry_from_lcid (int lcid) const RegionInfoEntry *entry; const CultureInfoEntry *ne; - ne = mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator); + ne = (const CultureInfoEntry *)mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator); if (ne == NULL) return FALSE; @@ -509,7 +510,7 @@ ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name ( char *n; n = mono_string_to_utf8 (name); - ne = mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES, + ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoNameEntry), culture_name_locator); if (ne == NULL) { @@ -557,7 +558,7 @@ ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name (M char *n; n = mono_string_to_utf8 (name); - ne = mono_binary_search (n, region_name_entries, NUM_REGION_ENTRIES, + ne = (const RegionInfoNameEntry *)mono_binary_search (n, region_name_entries, NUM_REGION_ENTRIES, sizeof (RegionInfoNameEntry), region_name_locator); if (ne == NULL) { @@ -574,6 +575,7 @@ MonoArray* ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean neutral, MonoBoolean specific, MonoBoolean installed) { + MonoError error; MonoArray *ret; MonoClass *klass; MonoCultureInfo *culture; @@ -592,8 +594,7 @@ ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean ne len++; } - klass = mono_class_from_name (mono_get_corlib (), - "System.Globalization", "CultureInfo"); + klass = mono_class_get_culture_info_class (); /* The InvariantCulture is not in culture_entries */ /* We reserve the first slot in the array for it */ @@ -613,8 +614,10 @@ ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean ne ci = &culture_entries [i]; is_neutral = ci->territory == 0; if ((neutral && is_neutral) || (specific && !is_neutral)) { - culture = (MonoCultureInfo *) mono_object_new (domain, klass); - mono_runtime_object_init ((MonoObject *) culture); + culture = (MonoCultureInfo *) mono_object_new_checked (domain, klass, &error); + if (!is_ok (&error)) goto fail; + mono_runtime_object_init_checked ((MonoObject *) culture, &error); + if (!is_ok (&error)) goto fail; construct_culture (culture, ci); culture->use_user_override = TRUE; mono_array_setref (ret, len++, culture); @@ -622,6 +625,10 @@ ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean ne } return ret; + +fail: + mono_error_set_pending_exception (&error); + return ret; } int ves_icall_System_Globalization_CompareInfo_internal_compare (MonoCompareInfo *this_obj, MonoString *str1, gint32 off1, gint32 len1, MonoString *str2, gint32 off2, gint32 len2, gint32 options) @@ -666,14 +673,6 @@ int ves_icall_System_Threading_Thread_current_lcid (void) return(0x007F); } -MonoString *ves_icall_System_String_InternalReplace_Str_Comp (MonoString *this_obj, MonoString *old, MonoString *new, MonoCompareInfo *comp) -{ - /* Do a normal ascii string compare and replace, as we only - * know the invariant locale if we dont have ICU - */ - return(string_invariant_replace (this_obj, old, new)); -} - static gint32 string_invariant_compare_char (gunichar2 c1, gunichar2 c2, gint32 options) { @@ -766,81 +765,6 @@ static gint32 string_invariant_compare (MonoString *str1, gint32 off1, return(string_invariant_compare_char(ustr1[pos], ustr2[pos], options)); } -static MonoString *string_invariant_replace (MonoString *me, - MonoString *oldValue, - MonoString *newValue) -{ - MonoString *ret; - gunichar2 *src; - gunichar2 *dest=NULL; /* shut gcc up */ - gunichar2 *oldstr; - gunichar2 *newstr=NULL; /* shut gcc up here too */ - gint32 i, destpos; - gint32 occurr; - gint32 newsize; - gint32 oldstrlen; - gint32 newstrlen; - gint32 srclen; - - occurr = 0; - destpos = 0; - - oldstr = mono_string_chars(oldValue); - oldstrlen = mono_string_length(oldValue); - - if (NULL != newValue) { - newstr = mono_string_chars(newValue); - newstrlen = mono_string_length(newValue); - } else - newstrlen = 0; - - src = mono_string_chars(me); - srclen = mono_string_length(me); - - if (oldstrlen != newstrlen) { - i = 0; - while (i <= srclen - oldstrlen) { - if (0 == memcmp(src + i, oldstr, oldstrlen * sizeof(gunichar2))) { - occurr++; - i += oldstrlen; - } - else - i ++; - } - if (occurr == 0) - return me; - newsize = srclen + ((newstrlen - oldstrlen) * occurr); - } else - newsize = srclen; - - ret = NULL; - i = 0; - while (i < srclen) { - if (0 == memcmp(src + i, oldstr, oldstrlen * sizeof(gunichar2))) { - if (ret == NULL) { - ret = mono_string_new_size( mono_domain_get (), newsize); - dest = mono_string_chars(ret); - memcpy (dest, src, i * sizeof(gunichar2)); - } - if (newstrlen > 0) { - memcpy(dest + destpos, newstr, newstrlen * sizeof(gunichar2)); - destpos += newstrlen; - } - i += oldstrlen; - continue; - } else if (ret != NULL) { - dest[destpos] = src[i]; - } - destpos++; - i++; - } - - if (ret == NULL) - return me; - - return ret; -} - static gint32 string_invariant_indexof (MonoString *source, gint32 sindex, gint32 count, MonoString *value, MonoBoolean first) @@ -904,12 +828,12 @@ static gint32 string_invariant_indexof_char (MonoString *source, gint32 sindex, } } -void load_normalization_resource (guint8 **argProps, - guint8 **argMappedChars, - guint8 **argCharMapIndex, - guint8 **argHelperIndex, - guint8 **argMapIdxToComposite, - guint8 **argCombiningClass) +void ves_icall_System_Text_Normalization_load_normalization_resource (guint8 **argProps, + guint8 **argMappedChars, + guint8 **argCharMapIndex, + guint8 **argHelperIndex, + guint8 **argMapIdxToComposite, + guint8 **argCombiningClass) { #ifdef DISABLE_NORMALIZATION mono_set_pending_exception (mono_get_exception_not_supported ("This runtime has been compiled without string normalization support."));