3 * Culture-sensitive handling
6 * Dick Porter (dick@ximian.com)
7 * Mohammad DAMT (mdamt@cdl2000.com)
8 * Marek Safar (marek.safar@gmail.com)
10 * Copyright 2003 Ximian, Inc (http://www.ximian.com)
11 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
12 * (C) 2003 PT Cakram Datalingga Duaribu http://www.cdl2000.com
13 * Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
14 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
21 #include <mono/metadata/debug-helpers.h>
22 #include <mono/metadata/object.h>
23 #include <mono/metadata/appdomain.h>
24 #include <mono/metadata/exception.h>
25 #include <mono/metadata/monitor.h>
26 #include <mono/metadata/locales.h>
27 #include <mono/metadata/culture-info.h>
28 #include <mono/metadata/culture-info-tables.h>
29 #include <mono/utils/bsearch.h>
31 #ifndef DISABLE_NORMALIZATION
32 #include <mono/metadata/normalization-tables.h>
36 #if defined(__APPLE__)
37 #include <CoreFoundation/CoreFoundation.h>
42 static gint32 string_invariant_compare_char (gunichar2 c1, gunichar2 c2,
44 static gint32 string_invariant_compare (MonoString *str1, gint32 off1,
45 gint32 len1, MonoString *str2,
46 gint32 off2, gint32 len2,
48 static gint32 string_invariant_indexof (MonoString *source, gint32 sindex,
49 gint32 count, MonoString *value,
51 static gint32 string_invariant_indexof_char (MonoString *source, gint32 sindex,
52 gint32 count, gunichar2 value,
55 static const CultureInfoEntry* culture_info_entry_from_lcid (int lcid);
57 static const RegionInfoEntry* region_info_entry_from_lcid (int lcid);
59 /* Lazy class loading functions */
60 static GENERATE_GET_CLASS_WITH_CACHE (culture_info, "System.Globalization", "CultureInfo")
63 culture_lcid_locator (const void *a, const void *b)
65 const int *lcid = (const int *)a;
66 const CultureInfoEntry *bb = (const CultureInfoEntry *)b;
68 return *lcid - bb->lcid;
72 culture_name_locator (const void *a, const void *b)
74 const char *aa = (const char *)a;
75 const CultureInfoNameEntry *bb = (const CultureInfoNameEntry *)b;
78 ret = strcmp (aa, idx2string (bb->name));
84 region_name_locator (const void *a, const void *b)
86 const char *aa = (const char *)a;
87 const RegionInfoNameEntry *bb = (const RegionInfoNameEntry *)b;
90 ret = strcmp (aa, idx2string (bb->name));
96 create_group_sizes_array (const gint *gs, gint ml, MonoError *error)
103 for (i = 0; i < ml; i++) {
109 ret = mono_array_new_cached (mono_domain_get (),
110 mono_get_int32_class (), len, error);
111 return_val_if_nok (error, NULL);
113 for(i = 0; i < len; i++)
114 mono_array_set (ret, gint32, i, gs [i]);
120 create_names_array_idx (const guint16 *names, int ml, MonoError *error)
131 domain = mono_domain_get ();
133 ret = mono_array_new_cached (mono_domain_get (), mono_get_string_class (), ml, error);
134 return_val_if_nok (error, NULL);
136 for(i = 0; i < ml; i++)
137 mono_array_setref (ret, i, mono_string_new (domain, dtidx2string (names [i])));
143 create_names_array_idx_dynamic (const guint16 *names, int ml, MonoError *error)
154 domain = mono_domain_get ();
156 for (i = 0; i < ml; i++) {
162 ret = mono_array_new_cached (mono_domain_get (), mono_get_string_class (), len, error);
163 return_val_if_nok (error, NULL);
165 for(i = 0; i < len; i++)
166 mono_array_setref (ret, i, mono_string_new (domain, pattern2string (names [i])));
172 ves_icall_System_Globalization_CalendarData_fill_calendar_data (MonoCalendarData *this_obj, MonoString *name, gint32 calendar_index)
176 const DateTimeFormatEntry *dfe;
177 const CultureInfoNameEntry *ne;
178 const CultureInfoEntry *ci;
181 n = mono_string_to_utf8_checked (name, &error);
182 if (mono_error_set_pending_exception (&error))
184 ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES,
185 sizeof (CultureInfoNameEntry), culture_name_locator);
191 ci = &culture_entries [ne->culture_entry_index];
192 dfe = &datetime_format_entries [ci->datetime_format_index];
194 domain = mono_domain_get ();
196 MONO_OBJECT_SETREF (this_obj, NativeName, mono_string_new (domain, idx2string (ci->nativename)));
197 MonoArray *short_date_patterns = create_names_array_idx_dynamic (dfe->short_date_patterns,
198 NUM_SHORT_DATE_PATTERNS, &error);
199 return_val_and_set_pending_if_nok (&error, FALSE);
200 MONO_OBJECT_SETREF (this_obj, ShortDatePatterns, short_date_patterns);
201 MonoArray *year_month_patterns =create_names_array_idx_dynamic (dfe->year_month_patterns,
202 NUM_YEAR_MONTH_PATTERNS, &error);
203 return_val_and_set_pending_if_nok (&error, FALSE);
204 MONO_OBJECT_SETREF (this_obj, YearMonthPatterns, year_month_patterns);
206 MonoArray *long_date_patterns = create_names_array_idx_dynamic (dfe->long_date_patterns,
207 NUM_LONG_DATE_PATTERNS, &error);
208 return_val_and_set_pending_if_nok (&error, FALSE);
209 MONO_OBJECT_SETREF (this_obj, LongDatePatterns, long_date_patterns);
211 MONO_OBJECT_SETREF (this_obj, MonthDayPattern, mono_string_new (domain, pattern2string (dfe->month_day_pattern)));
213 MonoArray *day_names = create_names_array_idx (dfe->day_names, NUM_DAYS, &error);
214 return_val_and_set_pending_if_nok (&error, FALSE);
215 MONO_OBJECT_SETREF (this_obj, DayNames, day_names);
217 MonoArray *abbr_day_names = create_names_array_idx (dfe->abbreviated_day_names,
219 return_val_and_set_pending_if_nok (&error, FALSE);
220 MONO_OBJECT_SETREF (this_obj, AbbreviatedDayNames, abbr_day_names);
222 MonoArray *ss_day_names = create_names_array_idx (dfe->shortest_day_names, NUM_DAYS, &error);
223 return_val_and_set_pending_if_nok (&error, FALSE);
224 MONO_OBJECT_SETREF (this_obj, SuperShortDayNames, ss_day_names);
226 MonoArray *month_names = create_names_array_idx (dfe->month_names, NUM_MONTHS, &error);
227 return_val_and_set_pending_if_nok (&error, FALSE);
228 MONO_OBJECT_SETREF (this_obj, MonthNames, month_names);
230 MonoArray *abbr_mon_names = create_names_array_idx (dfe->abbreviated_month_names,
232 return_val_and_set_pending_if_nok (&error, FALSE);
233 MONO_OBJECT_SETREF (this_obj, AbbreviatedMonthNames, abbr_mon_names);
236 MonoArray *gen_month_names = create_names_array_idx (dfe->month_genitive_names, NUM_MONTHS, &error);
237 return_val_and_set_pending_if_nok (&error, FALSE);
238 MONO_OBJECT_SETREF (this_obj, GenitiveMonthNames, gen_month_names);
240 MonoArray *gen_abbr_mon_names = create_names_array_idx (dfe->abbreviated_month_genitive_names, NUM_MONTHS, &error);
241 return_val_and_set_pending_if_nok (&error, FALSE);
242 MONO_OBJECT_SETREF (this_obj, GenitiveAbbreviatedMonthNames, gen_abbr_mon_names);
248 ves_icall_System_Globalization_CultureData_fill_culture_data (MonoCultureData *this_obj, gint32 datetime_index)
252 const DateTimeFormatEntry *dfe;
254 g_assert (datetime_index >= 0);
256 dfe = &datetime_format_entries [datetime_index];
258 domain = mono_domain_get ();
260 MONO_OBJECT_SETREF (this_obj, AMDesignator, mono_string_new (domain, idx2string (dfe->am_designator)));
261 MONO_OBJECT_SETREF (this_obj, PMDesignator, mono_string_new (domain, idx2string (dfe->pm_designator)));
262 MONO_OBJECT_SETREF (this_obj, TimeSeparator, mono_string_new (domain, idx2string (dfe->time_separator)));
264 MonoArray *long_time_patterns = create_names_array_idx_dynamic (dfe->long_time_patterns,
265 NUM_LONG_TIME_PATTERNS, &error);
266 if (mono_error_set_pending_exception (&error))
268 MONO_OBJECT_SETREF (this_obj, LongTimePatterns, long_time_patterns);
270 MonoArray *short_time_patterns = create_names_array_idx_dynamic (dfe->short_time_patterns,
271 NUM_SHORT_TIME_PATTERNS, &error);
272 if (mono_error_set_pending_exception (&error))
274 MONO_OBJECT_SETREF (this_obj, ShortTimePatterns, short_time_patterns);
275 this_obj->FirstDayOfWeek = dfe->first_day_of_week;
276 this_obj->CalendarWeekRule = dfe->calendar_week_rule;
280 ves_icall_System_Globalization_CultureData_fill_number_data (MonoNumberFormatInfo* number, gint32 number_index)
284 const NumberFormatEntry *nfe;
286 g_assert (number_index >= 0);
288 nfe = &number_format_entries [number_index];
290 domain = mono_domain_get ();
292 number->currencyDecimalDigits = nfe->currency_decimal_digits;
293 MONO_OBJECT_SETREF (number, currencyDecimalSeparator, mono_string_new (domain,
294 idx2string (nfe->currency_decimal_separator)));
295 MONO_OBJECT_SETREF (number, currencyGroupSeparator, mono_string_new (domain,
296 idx2string (nfe->currency_group_separator)));
297 MonoArray *currency_sizes_arr = create_group_sizes_array (nfe->currency_group_sizes,
299 if (mono_error_set_pending_exception (&error))
301 MONO_OBJECT_SETREF (number, currencyGroupSizes, currency_sizes_arr);
302 number->currencyNegativePattern = nfe->currency_negative_pattern;
303 number->currencyPositivePattern = nfe->currency_positive_pattern;
304 MONO_OBJECT_SETREF (number, currencySymbol, mono_string_new (domain, idx2string (nfe->currency_symbol)));
305 MONO_OBJECT_SETREF (number, naNSymbol, mono_string_new (domain, idx2string (nfe->nan_symbol)));
306 MONO_OBJECT_SETREF (number, negativeInfinitySymbol, mono_string_new (domain,
307 idx2string (nfe->negative_infinity_symbol)));
308 MONO_OBJECT_SETREF (number, negativeSign, mono_string_new (domain, idx2string (nfe->negative_sign)));
309 number->numberDecimalDigits = nfe->number_decimal_digits;
310 MONO_OBJECT_SETREF (number, numberDecimalSeparator, mono_string_new (domain,
311 idx2string (nfe->number_decimal_separator)));
312 MONO_OBJECT_SETREF (number, numberGroupSeparator, mono_string_new (domain, idx2string (nfe->number_group_separator)));
313 MonoArray *number_sizes_arr = create_group_sizes_array (nfe->number_group_sizes,
315 if (mono_error_set_pending_exception (&error))
317 MONO_OBJECT_SETREF (number, numberGroupSizes, number_sizes_arr);
318 number->numberNegativePattern = nfe->number_negative_pattern;
319 number->percentNegativePattern = nfe->percent_negative_pattern;
320 number->percentPositivePattern = nfe->percent_positive_pattern;
321 MONO_OBJECT_SETREF (number, percentSymbol, mono_string_new (domain, idx2string (nfe->percent_symbol)));
322 MONO_OBJECT_SETREF (number, perMilleSymbol, mono_string_new (domain, idx2string (nfe->per_mille_symbol)));
323 MONO_OBJECT_SETREF (number, positiveInfinitySymbol, mono_string_new (domain,
324 idx2string (nfe->positive_infinity_symbol)));
325 MONO_OBJECT_SETREF (number, positiveSign, mono_string_new (domain, idx2string (nfe->positive_sign)));
329 construct_culture (MonoCultureInfo *this_obj, const CultureInfoEntry *ci, MonoError *error)
331 MonoDomain *domain = mono_domain_get ();
335 this_obj->lcid = ci->lcid;
336 MONO_OBJECT_SETREF (this_obj, name, mono_string_new (domain, idx2string (ci->name)));
337 MONO_OBJECT_SETREF (this_obj, englishname, mono_string_new (domain, idx2string (ci->englishname)));
338 MONO_OBJECT_SETREF (this_obj, nativename, mono_string_new (domain, idx2string (ci->nativename)));
339 MONO_OBJECT_SETREF (this_obj, win3lang, mono_string_new (domain, idx2string (ci->win3lang)));
340 MONO_OBJECT_SETREF (this_obj, iso3lang, mono_string_new (domain, idx2string (ci->iso3lang)));
341 MONO_OBJECT_SETREF (this_obj, iso2lang, mono_string_new (domain, idx2string (ci->iso2lang)));
343 // It's null for neutral cultures
344 if (ci->territory > 0)
345 MONO_OBJECT_SETREF (this_obj, territory, mono_string_new (domain, idx2string (ci->territory)));
347 MonoArray *native_calendar_names = create_names_array_idx (ci->native_calendar_names, NUM_CALENDARS, error);
348 return_val_if_nok (error, FALSE);
349 MONO_OBJECT_SETREF (this_obj, native_calendar_names, native_calendar_names);
350 this_obj->parent_lcid = ci->parent_lcid;
351 this_obj->datetime_index = ci->datetime_format_index;
352 this_obj->number_index = ci->number_format_index;
353 this_obj->calendar_type = ci->calendar_type;
354 this_obj->text_info_data = &ci->text_info;
360 construct_region (MonoRegionInfo *this_obj, const RegionInfoEntry *ri)
362 MonoDomain *domain = mono_domain_get ();
364 this_obj->geo_id = ri->geo_id;
365 MONO_OBJECT_SETREF (this_obj, iso2name, mono_string_new (domain, idx2string (ri->iso2name)));
366 MONO_OBJECT_SETREF (this_obj, iso3name, mono_string_new (domain, idx2string (ri->iso3name)));
367 MONO_OBJECT_SETREF (this_obj, win3name, mono_string_new (domain, idx2string (ri->win3name)));
368 MONO_OBJECT_SETREF (this_obj, english_name, mono_string_new (domain, idx2string (ri->english_name)));
369 MONO_OBJECT_SETREF (this_obj, native_name, mono_string_new (domain, idx2string (ri->native_name)));
370 MONO_OBJECT_SETREF (this_obj, currency_symbol, mono_string_new (domain, idx2string (ri->currency_symbol)));
371 MONO_OBJECT_SETREF (this_obj, iso_currency_symbol, mono_string_new (domain, idx2string (ri->iso_currency_symbol)));
372 MONO_OBJECT_SETREF (this_obj, currency_english_name, mono_string_new (domain, idx2string (ri->currency_english_name)));
373 MONO_OBJECT_SETREF (this_obj, currency_native_name, mono_string_new (domain, idx2string (ri->currency_native_name)));
378 static const CultureInfoEntry*
379 culture_info_entry_from_lcid (int lcid)
381 const CultureInfoEntry *ci;
383 ci = (const CultureInfoEntry *)mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
388 static const RegionInfoEntry*
389 region_info_entry_from_lcid (int lcid)
391 const RegionInfoEntry *entry;
392 const CultureInfoEntry *ne;
394 ne = (const CultureInfoEntry *)mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
399 entry = ®ion_entries [ne->region_entry_index];
404 #if defined (__APPLE__)
406 get_darwin_locale (void)
408 static gchar *darwin_locale = NULL;
409 CFLocaleRef locale = NULL;
410 CFStringRef locale_language = NULL;
411 CFStringRef locale_country = NULL;
412 CFStringRef locale_script = NULL;
413 CFStringRef locale_cfstr = NULL;
414 CFIndex bytes_converted;
415 CFIndex bytes_written;
419 if (darwin_locale != NULL)
420 return g_strdup (darwin_locale);
422 locale = CFLocaleCopyCurrent ();
425 locale_language = CFLocaleGetValue (locale, kCFLocaleLanguageCode);
426 if (locale_language != NULL && CFStringGetBytes(locale_language, CFRangeMake (0, CFStringGetLength (locale_language)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) {
427 len = bytes_converted + 1;
429 locale_country = CFLocaleGetValue (locale, kCFLocaleCountryCode);
430 if (locale_country != NULL && CFStringGetBytes (locale_country, CFRangeMake (0, CFStringGetLength (locale_country)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) {
431 len += bytes_converted + 1;
433 locale_script = CFLocaleGetValue (locale, kCFLocaleScriptCode);
434 if (locale_script != NULL && CFStringGetBytes (locale_script, CFRangeMake (0, CFStringGetLength (locale_script)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) {
435 len += bytes_converted + 1;
438 darwin_locale = (char *) g_malloc (len + 1);
439 CFStringGetBytes (locale_language, CFRangeMake (0, CFStringGetLength (locale_language)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) darwin_locale, len, &bytes_converted);
441 darwin_locale[bytes_converted] = '-';
442 bytes_written = bytes_converted + 1;
443 if (locale_script != NULL && CFStringGetBytes (locale_script, CFRangeMake (0, CFStringGetLength (locale_script)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) &darwin_locale[bytes_written], len - bytes_written, &bytes_converted) > 0) {
444 darwin_locale[bytes_written + bytes_converted] = '-';
445 bytes_written += bytes_converted + 1;
448 CFStringGetBytes (locale_country, CFRangeMake (0, CFStringGetLength (locale_country)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) &darwin_locale[bytes_written], len - bytes_written, &bytes_converted);
449 darwin_locale[bytes_written + bytes_converted] = '\0';
453 if (darwin_locale == NULL) {
454 locale_cfstr = CFLocaleGetIdentifier (locale);
457 len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1;
458 darwin_locale = (char *) g_malloc (len);
459 if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) {
460 g_free (darwin_locale);
462 darwin_locale = NULL;
466 for (i = 0; i < strlen (darwin_locale); i++)
467 if (darwin_locale [i] == '_')
468 darwin_locale [i] = '-';
475 return g_strdup (darwin_locale);
480 get_posix_locale (void)
484 locale = g_getenv ("LC_ALL");
485 if (locale == NULL) {
486 locale = g_getenv ("LANG");
487 if (locale == NULL) {
488 char *static_locale = setlocale (LC_ALL, NULL);
490 locale = g_strdup (static_locale);
496 /* Skip English-only locale 'C' */
497 if (strcmp (locale, "C") == 0) {
507 get_current_locale_name (void)
513 locale = g_win32_getlocale ();
514 #elif defined (__APPLE__)
515 locale = get_darwin_locale ();
517 locale = get_posix_locale ();
519 locale = get_posix_locale ();
525 p = strchr (locale, '.');
528 p = strchr (locale, '@');
531 p = strchr (locale, '_');
535 ret = g_ascii_strdown (locale, -1);
542 ves_icall_System_Globalization_CultureInfo_get_current_locale_name (void)
548 locale = get_current_locale_name ();
552 domain = mono_domain_get ();
553 ret = mono_string_new (domain, locale);
560 ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid (MonoCultureInfo *this_obj,
564 const CultureInfoEntry *ci;
566 ci = culture_info_entry_from_lcid (lcid);
570 if (!construct_culture (this_obj, ci, &error)) {
571 mono_error_set_pending_exception (&error);
578 ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name (MonoCultureInfo *this_obj,
582 const CultureInfoNameEntry *ne;
585 n = mono_string_to_utf8_checked (name, &error);
586 if (mono_error_set_pending_exception (&error))
588 ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES,
589 sizeof (CultureInfoNameEntry), culture_name_locator);
592 /*g_print ("ne (%s) is null\n", n);*/
598 if (!construct_culture (this_obj, &culture_entries [ne->culture_entry_index], &error)) {
599 mono_error_set_pending_exception (&error);
606 ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name (MonoCultureInfo *ci,
612 locale = mono_string_to_utf8 (name);
613 ret = construct_culture_from_specific_name (ci, locale);
620 ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_lcid (MonoRegionInfo *this_obj,
623 const RegionInfoEntry *ri;
625 ri = region_info_entry_from_lcid (lcid);
629 return construct_region (this_obj, ri);
633 ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name (MonoRegionInfo *this_obj,
637 const RegionInfoNameEntry *ne;
640 n = mono_string_to_utf8_checked (name, &error);
641 if (mono_error_set_pending_exception (&error))
643 ne = (const RegionInfoNameEntry *)mono_binary_search (n, region_name_entries, NUM_REGION_ENTRIES,
644 sizeof (RegionInfoNameEntry), region_name_locator);
647 /*g_print ("ne (%s) is null\n", n);*/
653 return construct_region (this_obj, ®ion_entries [ne->region_entry_index]);
657 ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean neutral,
658 MonoBoolean specific, MonoBoolean installed)
663 MonoCultureInfo *culture;
665 const CultureInfoEntry *ci;
669 domain = mono_domain_get ();
672 for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
673 ci = &culture_entries [i];
674 is_neutral = ci->territory == 0;
675 if ((neutral && is_neutral) || (specific && !is_neutral))
679 klass = mono_class_get_culture_info_class ();
681 /* The InvariantCulture is not in culture_entries */
682 /* We reserve the first slot in the array for it */
686 ret = mono_array_new_checked (domain, klass, len, &error);
695 mono_array_setref (ret, len++, NULL);
697 for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
698 ci = &culture_entries [i];
699 is_neutral = ci->territory == 0;
700 if ((neutral && is_neutral) || (specific && !is_neutral)) {
701 culture = (MonoCultureInfo *) mono_object_new_checked (domain, klass, &error);
702 if (!is_ok (&error)) goto fail;
703 mono_runtime_object_init_checked ((MonoObject *) culture, &error);
704 if (!is_ok (&error)) goto fail;
705 if (!construct_culture (culture, ci, &error))
707 culture->use_user_override = TRUE;
708 mono_array_setref (ret, len++, culture);
715 mono_error_set_pending_exception (&error);
719 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)
721 /* Do a normal ascii string compare, as we only know the
722 * invariant locale if we dont have ICU
724 return(string_invariant_compare (str1, off1, len1, str2, off2, len2,
728 void ves_icall_System_Globalization_CompareInfo_assign_sortkey (MonoCompareInfo *this_obj, MonoSortKey *key, MonoString *source, gint32 options)
734 keylen=mono_string_length (source);
736 arr=mono_array_new_checked (mono_domain_get (), mono_get_byte_class (),
738 if (mono_error_set_pending_exception (&error))
741 for(i=0; i<keylen; i++) {
742 mono_array_set (arr, guint8, i, mono_string_chars (source)[i]);
745 MONO_OBJECT_SETREF (key, key, arr);
748 int ves_icall_System_Globalization_CompareInfo_internal_index (MonoCompareInfo *this_obj, MonoString *source, gint32 sindex, gint32 count, MonoString *value, gint32 options, MonoBoolean first)
750 return(string_invariant_indexof (source, sindex, count, value, first));
753 int ves_icall_System_Globalization_CompareInfo_internal_index_char (MonoCompareInfo *this_obj, MonoString *source, gint32 sindex, gint32 count, gunichar2 value, gint32 options, MonoBoolean first)
755 return(string_invariant_indexof_char (source, sindex, count, value,
759 int ves_icall_System_Threading_Thread_current_lcid (void)
765 static gint32 string_invariant_compare_char (gunichar2 c1, gunichar2 c2,
770 /* Ordinal can not be mixed with other options, and must return the difference, not only -1, 0, 1 */
771 if (options & CompareOptions_Ordinal)
772 return (gint32) c1 - c2;
774 if (options & CompareOptions_IgnoreCase) {
775 GUnicodeType c1type, c2type;
777 c1type = g_unichar_type (c1);
778 c2type = g_unichar_type (c2);
780 result = (gint32) (c1type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c1) : c1) -
781 (c2type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c2) : c2);
784 * No options. Kana, symbol and spacing options don't
785 * apply to the invariant culture.
789 * FIXME: here we must use the information from c1type and c2type
790 * to find out the proper collation, even on the InvariantCulture, the
791 * sorting is not done by computing the unicode values, but their
794 result = (gint32) c1 - c2;
797 return ((result < 0) ? -1 : (result > 0) ? 1 : 0);
800 static gint32 string_invariant_compare (MonoString *str1, gint32 off1,
801 gint32 len1, MonoString *str2,
802 gint32 off2, gint32 len2,
805 /* c translation of C# code from old string.cs.. :) */
818 ustr1 = mono_string_chars(str1)+off1;
819 ustr2 = mono_string_chars(str2)+off2;
823 for (pos = 0; pos != length; pos++) {
824 if (pos >= len1 || pos >= len2)
827 charcmp = string_invariant_compare_char(ustr1[pos], ustr2[pos],
834 /* the lesser wins, so if we have looped until length we just
835 * need to check the last char
838 return(string_invariant_compare_char(ustr1[pos - 1],
839 ustr2[pos - 1], options));
842 /* Test if one of the strings has been compared to the end */
849 } else if (pos >= len2) {
853 /* if not, check our last char only.. (can this happen?) */
854 return(string_invariant_compare_char(ustr1[pos], ustr2[pos], options));
857 static gint32 string_invariant_indexof (MonoString *source, gint32 sindex,
858 gint32 count, MonoString *value,
866 lencmpstr = mono_string_length(value);
868 src = mono_string_chars(source);
869 cmpstr = mono_string_chars(value);
873 for(pos=sindex;pos <= sindex+count;pos++) {
874 for(i=0;src[pos+i]==cmpstr[i];) {
883 for(pos=sindex-lencmpstr+1;pos>sindex-count;pos--) {
884 if(memcmp (src+pos, cmpstr,
885 lencmpstr*sizeof(gunichar2))==0) {
894 static gint32 string_invariant_indexof_char (MonoString *source, gint32 sindex,
895 gint32 count, gunichar2 value,
901 src = mono_string_chars(source);
903 for (pos = sindex; pos != count + sindex; pos++) {
904 if (src [pos] == value) {
911 for (pos = sindex; pos > sindex - count; pos--) {
912 if (src [pos] == value)
920 void ves_icall_System_Text_Normalization_load_normalization_resource (guint8 **argProps,
921 guint8 **argMappedChars,
922 guint8 **argCharMapIndex,
923 guint8 **argHelperIndex,
924 guint8 **argMapIdxToComposite,
925 guint8 **argCombiningClass)
927 #ifdef DISABLE_NORMALIZATION
928 mono_set_pending_exception (mono_get_exception_not_supported ("This runtime has been compiled without string normalization support."));
931 *argProps = (guint8*)props;
932 *argMappedChars = (guint8*) mappedChars;
933 *argCharMapIndex = (guint8*) charMapIndex;
934 *argHelperIndex = (guint8*) helperIndex;
935 *argMapIdxToComposite = (guint8*) mapIdxToComposite;
936 *argCombiningClass = (guint8*)combiningClass;