2 * locales.c: Culture-sensitive handling
5 * Dick Porter (dick@ximian.com)
6 * Mohammad DAMT (mdamt@cdl2000.com)
7 * Marek Safar (marek.safar@gmail.com)
9 * Copyright 2003 Ximian, Inc (http://www.ximian.com)
10 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
11 * (C) 2003 PT Cakram Datalingga Duaribu http://www.cdl2000.com
12 * Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
13 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
20 #include <mono/metadata/debug-helpers.h>
21 #include <mono/metadata/object.h>
22 #include <mono/metadata/appdomain.h>
23 #include <mono/metadata/exception.h>
24 #include <mono/metadata/monitor.h>
25 #include <mono/metadata/locales.h>
26 #include <mono/metadata/culture-info.h>
27 #include <mono/metadata/culture-info-tables.h>
28 #include <mono/utils/bsearch.h>
30 #ifndef DISABLE_NORMALIZATION
31 #include <mono/metadata/normalization-tables.h>
35 #if defined(__APPLE__)
36 #include <CoreFoundation/CoreFoundation.h>
41 static gint32 string_invariant_compare_char (gunichar2 c1, gunichar2 c2,
43 static gint32 string_invariant_compare (MonoString *str1, gint32 off1,
44 gint32 len1, MonoString *str2,
45 gint32 off2, gint32 len2,
47 static gint32 string_invariant_indexof (MonoString *source, gint32 sindex,
48 gint32 count, MonoString *value,
50 static gint32 string_invariant_indexof_char (MonoString *source, gint32 sindex,
51 gint32 count, gunichar2 value,
54 static const CultureInfoEntry* culture_info_entry_from_lcid (int lcid);
56 static const RegionInfoEntry* region_info_entry_from_lcid (int lcid);
58 /* Lazy class loading functions */
59 static GENERATE_GET_CLASS_WITH_CACHE (culture_info, System.Globalization, CultureInfo)
62 culture_lcid_locator (const void *a, const void *b)
64 const int *lcid = (const int *)a;
65 const CultureInfoEntry *bb = (const CultureInfoEntry *)b;
67 return *lcid - bb->lcid;
71 culture_name_locator (const void *a, const void *b)
73 const char *aa = (const char *)a;
74 const CultureInfoNameEntry *bb = (const CultureInfoNameEntry *)b;
77 ret = strcmp (aa, idx2string (bb->name));
83 region_name_locator (const void *a, const void *b)
85 const char *aa = (const char *)a;
86 const RegionInfoNameEntry *bb = (const RegionInfoNameEntry *)b;
89 ret = strcmp (aa, idx2string (bb->name));
95 create_group_sizes_array (const gint *gs, gint ml)
100 for (i = 0; i < ml; i++) {
106 ret = mono_array_new_cached (mono_domain_get (),
107 mono_get_int32_class (), len);
109 for(i = 0; i < len; i++)
110 mono_array_set (ret, gint32, i, gs [i]);
116 create_names_array_idx (const guint16 *names, int ml)
125 domain = mono_domain_get ();
127 ret = mono_array_new_cached (mono_domain_get (), mono_get_string_class (), ml);
129 for(i = 0; i < ml; i++)
130 mono_array_setref (ret, i, mono_string_new (domain, idx2string (names [i])));
136 create_names_array_idx_dynamic (const guint16 *names, int ml)
145 domain = mono_domain_get ();
147 for (i = 0; i < ml; i++) {
153 ret = mono_array_new_cached (mono_domain_get (), mono_get_string_class (), len);
155 for(i = 0; i < len; i++)
156 mono_array_setref (ret, i, mono_string_new (domain, idx2string (names [i])));
162 ves_icall_System_Globalization_CalendarData_fill_calendar_data (MonoCalendarData *this_obj, MonoString *name, gint32 calendar_index)
165 const DateTimeFormatEntry *dfe;
166 const CultureInfoNameEntry *ne;
167 const CultureInfoEntry *ci;
170 n = mono_string_to_utf8 (name);
171 ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES,
172 sizeof (CultureInfoNameEntry), culture_name_locator);
178 ci = &culture_entries [ne->culture_entry_index];
179 dfe = &datetime_format_entries [ci->datetime_format_index];
181 domain = mono_domain_get ();
183 MONO_OBJECT_SETREF (this_obj, NativeName, mono_string_new (domain, idx2string (ci->nativename)));
184 MONO_OBJECT_SETREF (this_obj, ShortDatePatterns, create_names_array_idx_dynamic (dfe->short_date_patterns,
185 NUM_SHORT_DATE_PATTERNS));
186 MONO_OBJECT_SETREF (this_obj, YearMonthPatterns, create_names_array_idx_dynamic (dfe->year_month_patterns,
187 NUM_YEAR_MONTH_PATTERNS));
189 MONO_OBJECT_SETREF (this_obj, LongDatePatterns, create_names_array_idx_dynamic (dfe->long_date_patterns,
190 NUM_LONG_DATE_PATTERNS));
191 MONO_OBJECT_SETREF (this_obj, MonthDayPattern, mono_string_new (domain, idx2string (dfe->month_day_pattern)));
193 MONO_OBJECT_SETREF (this_obj, DayNames, create_names_array_idx (dfe->day_names, NUM_DAYS));
194 MONO_OBJECT_SETREF (this_obj, AbbreviatedDayNames, create_names_array_idx (dfe->abbreviated_day_names,
196 MONO_OBJECT_SETREF (this_obj, SuperShortDayNames, create_names_array_idx (dfe->shortest_day_names, NUM_DAYS));
197 MONO_OBJECT_SETREF (this_obj, MonthNames, create_names_array_idx (dfe->month_names, NUM_MONTHS));
198 MONO_OBJECT_SETREF (this_obj, AbbreviatedMonthNames, create_names_array_idx (dfe->abbreviated_month_names,
200 MONO_OBJECT_SETREF (this_obj, GenitiveMonthNames, create_names_array_idx (dfe->month_genitive_names, NUM_MONTHS));
201 MONO_OBJECT_SETREF (this_obj, GenitiveAbbreviatedMonthNames, create_names_array_idx (dfe->abbreviated_month_genitive_names, NUM_MONTHS));
207 ves_icall_System_Globalization_CultureData_fill_culture_data (MonoCultureData *this_obj, gint32 datetime_index)
210 const DateTimeFormatEntry *dfe;
212 g_assert (datetime_index >= 0);
214 dfe = &datetime_format_entries [datetime_index];
216 domain = mono_domain_get ();
218 MONO_OBJECT_SETREF (this_obj, AMDesignator, mono_string_new (domain, idx2string (dfe->am_designator)));
219 MONO_OBJECT_SETREF (this_obj, PMDesignator, mono_string_new (domain, idx2string (dfe->pm_designator)));
220 MONO_OBJECT_SETREF (this_obj, TimeSeparator, mono_string_new (domain, idx2string (dfe->time_separator)));
221 MONO_OBJECT_SETREF (this_obj, LongTimePatterns, create_names_array_idx_dynamic (dfe->long_time_patterns,
222 NUM_LONG_TIME_PATTERNS));
223 MONO_OBJECT_SETREF (this_obj, ShortTimePatterns, create_names_array_idx_dynamic (dfe->short_time_patterns,
224 NUM_SHORT_TIME_PATTERNS));
225 this_obj->FirstDayOfWeek = dfe->first_day_of_week;
226 this_obj->CalendarWeekRule = dfe->calendar_week_rule;
230 ves_icall_System_Globalization_CultureData_fill_number_data (MonoNumberFormatInfo* number, gint32 number_index)
233 const NumberFormatEntry *nfe;
235 g_assert (number_index >= 0);
237 nfe = &number_format_entries [number_index];
239 domain = mono_domain_get ();
241 number->currencyDecimalDigits = nfe->currency_decimal_digits;
242 MONO_OBJECT_SETREF (number, currencyDecimalSeparator, mono_string_new (domain,
243 idx2string (nfe->currency_decimal_separator)));
244 MONO_OBJECT_SETREF (number, currencyGroupSeparator, mono_string_new (domain,
245 idx2string (nfe->currency_group_separator)));
246 MONO_OBJECT_SETREF (number, currencyGroupSizes, create_group_sizes_array (nfe->currency_group_sizes,
248 number->currencyNegativePattern = nfe->currency_negative_pattern;
249 number->currencyPositivePattern = nfe->currency_positive_pattern;
250 MONO_OBJECT_SETREF (number, currencySymbol, mono_string_new (domain, idx2string (nfe->currency_symbol)));
251 MONO_OBJECT_SETREF (number, naNSymbol, mono_string_new (domain, idx2string (nfe->nan_symbol)));
252 MONO_OBJECT_SETREF (number, negativeInfinitySymbol, mono_string_new (domain,
253 idx2string (nfe->negative_infinity_symbol)));
254 MONO_OBJECT_SETREF (number, negativeSign, mono_string_new (domain, idx2string (nfe->negative_sign)));
255 number->numberDecimalDigits = nfe->number_decimal_digits;
256 MONO_OBJECT_SETREF (number, numberDecimalSeparator, mono_string_new (domain,
257 idx2string (nfe->number_decimal_separator)));
258 MONO_OBJECT_SETREF (number, numberGroupSeparator, mono_string_new (domain, idx2string (nfe->number_group_separator)));
259 MONO_OBJECT_SETREF (number, numberGroupSizes, create_group_sizes_array (nfe->number_group_sizes,
261 number->numberNegativePattern = nfe->number_negative_pattern;
262 number->percentNegativePattern = nfe->percent_negative_pattern;
263 number->percentPositivePattern = nfe->percent_positive_pattern;
264 MONO_OBJECT_SETREF (number, percentSymbol, mono_string_new (domain, idx2string (nfe->percent_symbol)));
265 MONO_OBJECT_SETREF (number, perMilleSymbol, mono_string_new (domain, idx2string (nfe->per_mille_symbol)));
266 MONO_OBJECT_SETREF (number, positiveInfinitySymbol, mono_string_new (domain,
267 idx2string (nfe->positive_infinity_symbol)));
268 MONO_OBJECT_SETREF (number, positiveSign, mono_string_new (domain, idx2string (nfe->positive_sign)));
272 construct_culture (MonoCultureInfo *this_obj, const CultureInfoEntry *ci)
274 MonoDomain *domain = mono_domain_get ();
276 this_obj->lcid = ci->lcid;
277 MONO_OBJECT_SETREF (this_obj, name, mono_string_new (domain, idx2string (ci->name)));
278 MONO_OBJECT_SETREF (this_obj, englishname, mono_string_new (domain, idx2string (ci->englishname)));
279 MONO_OBJECT_SETREF (this_obj, nativename, mono_string_new (domain, idx2string (ci->nativename)));
280 MONO_OBJECT_SETREF (this_obj, win3lang, mono_string_new (domain, idx2string (ci->win3lang)));
281 MONO_OBJECT_SETREF (this_obj, iso3lang, mono_string_new (domain, idx2string (ci->iso3lang)));
282 MONO_OBJECT_SETREF (this_obj, iso2lang, mono_string_new (domain, idx2string (ci->iso2lang)));
284 // It's null for neutral cultures
285 if (ci->territory > 0)
286 MONO_OBJECT_SETREF (this_obj, territory, mono_string_new (domain, idx2string (ci->territory)));
287 MONO_OBJECT_SETREF (this_obj, native_calendar_names, create_names_array_idx (ci->native_calendar_names, NUM_CALENDARS));
288 this_obj->parent_lcid = ci->parent_lcid;
289 this_obj->datetime_index = ci->datetime_format_index;
290 this_obj->number_index = ci->number_format_index;
291 this_obj->calendar_type = ci->calendar_type;
292 this_obj->text_info_data = &ci->text_info;
298 construct_region (MonoRegionInfo *this_obj, const RegionInfoEntry *ri)
300 MonoDomain *domain = mono_domain_get ();
302 this_obj->geo_id = ri->geo_id;
303 MONO_OBJECT_SETREF (this_obj, iso2name, mono_string_new (domain, idx2string (ri->iso2name)));
304 MONO_OBJECT_SETREF (this_obj, iso3name, mono_string_new (domain, idx2string (ri->iso3name)));
305 MONO_OBJECT_SETREF (this_obj, win3name, mono_string_new (domain, idx2string (ri->win3name)));
306 MONO_OBJECT_SETREF (this_obj, english_name, mono_string_new (domain, idx2string (ri->english_name)));
307 MONO_OBJECT_SETREF (this_obj, native_name, mono_string_new (domain, idx2string (ri->native_name)));
308 MONO_OBJECT_SETREF (this_obj, currency_symbol, mono_string_new (domain, idx2string (ri->currency_symbol)));
309 MONO_OBJECT_SETREF (this_obj, iso_currency_symbol, mono_string_new (domain, idx2string (ri->iso_currency_symbol)));
310 MONO_OBJECT_SETREF (this_obj, currency_english_name, mono_string_new (domain, idx2string (ri->currency_english_name)));
311 MONO_OBJECT_SETREF (this_obj, currency_native_name, mono_string_new (domain, idx2string (ri->currency_native_name)));
316 static const CultureInfoEntry*
317 culture_info_entry_from_lcid (int lcid)
319 const CultureInfoEntry *ci;
321 ci = (const CultureInfoEntry *)mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
326 static const RegionInfoEntry*
327 region_info_entry_from_lcid (int lcid)
329 const RegionInfoEntry *entry;
330 const CultureInfoEntry *ne;
332 ne = (const CultureInfoEntry *)mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
337 entry = ®ion_entries [ne->region_entry_index];
342 #if defined (__APPLE__)
344 get_darwin_locale (void)
346 static gchar *darwin_locale = NULL;
347 CFLocaleRef locale = NULL;
348 CFStringRef locale_language = NULL;
349 CFStringRef locale_country = NULL;
350 CFStringRef locale_script = NULL;
351 CFStringRef locale_cfstr = NULL;
352 CFIndex bytes_converted;
353 CFIndex bytes_written;
357 if (darwin_locale != NULL)
358 return g_strdup (darwin_locale);
360 locale = CFLocaleCopyCurrent ();
363 locale_language = CFLocaleGetValue (locale, kCFLocaleLanguageCode);
364 if (locale_language != NULL && CFStringGetBytes(locale_language, CFRangeMake (0, CFStringGetLength (locale_language)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) {
365 len = bytes_converted + 1;
367 locale_country = CFLocaleGetValue (locale, kCFLocaleCountryCode);
368 if (locale_country != NULL && CFStringGetBytes (locale_country, CFRangeMake (0, CFStringGetLength (locale_country)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) {
369 len += bytes_converted + 1;
371 locale_script = CFLocaleGetValue (locale, kCFLocaleScriptCode);
372 if (locale_script != NULL && CFStringGetBytes (locale_script, CFRangeMake (0, CFStringGetLength (locale_script)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) {
373 len += bytes_converted + 1;
376 darwin_locale = (char *) malloc (len + 1);
377 CFStringGetBytes (locale_language, CFRangeMake (0, CFStringGetLength (locale_language)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) darwin_locale, len, &bytes_converted);
379 darwin_locale[bytes_converted] = '-';
380 bytes_written = bytes_converted + 1;
381 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) {
382 darwin_locale[bytes_written + bytes_converted] = '-';
383 bytes_written += bytes_converted + 1;
386 CFStringGetBytes (locale_country, CFRangeMake (0, CFStringGetLength (locale_country)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) &darwin_locale[bytes_written], len - bytes_written, &bytes_converted);
387 darwin_locale[bytes_written + bytes_converted] = '\0';
391 if (darwin_locale == NULL) {
392 locale_cfstr = CFLocaleGetIdentifier (locale);
395 len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1;
396 darwin_locale = (char *) malloc (len);
397 if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) {
398 free (darwin_locale);
400 darwin_locale = NULL;
404 for (i = 0; i < strlen (darwin_locale); i++)
405 if (darwin_locale [i] == '_')
406 darwin_locale [i] = '-';
413 return g_strdup (darwin_locale);
418 get_posix_locale (void)
422 locale = g_getenv ("LC_ALL");
423 if (locale == NULL) {
424 locale = g_getenv ("LANG");
426 locale = setlocale (LC_ALL, NULL);
431 /* Skip English-only locale 'C' */
432 if (strcmp (locale, "C") == 0)
435 return g_strdup (locale);
440 get_current_locale_name (void)
446 locale = g_win32_getlocale ();
447 #elif defined (__APPLE__)
448 locale = get_darwin_locale ();
450 locale = get_posix_locale ();
452 locale = get_posix_locale ();
458 p = strchr (locale, '.');
461 p = strchr (locale, '@');
464 p = strchr (locale, '_');
468 ret = g_ascii_strdown (locale, -1);
475 ves_icall_System_Globalization_CultureInfo_get_current_locale_name (void)
481 locale = get_current_locale_name ();
485 domain = mono_domain_get ();
486 ret = mono_string_new (domain, locale);
493 ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_lcid (MonoCultureInfo *this_obj,
496 const CultureInfoEntry *ci;
498 ci = culture_info_entry_from_lcid (lcid);
502 return construct_culture (this_obj, ci);
506 ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name (MonoCultureInfo *this_obj,
509 const CultureInfoNameEntry *ne;
512 n = mono_string_to_utf8 (name);
513 ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES,
514 sizeof (CultureInfoNameEntry), culture_name_locator);
517 /*g_print ("ne (%s) is null\n", n);*/
523 return construct_culture (this_obj, &culture_entries [ne->culture_entry_index]);
527 ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_specific_name (MonoCultureInfo *ci,
533 locale = mono_string_to_utf8 (name);
534 ret = construct_culture_from_specific_name (ci, locale);
541 ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_lcid (MonoRegionInfo *this_obj,
544 const RegionInfoEntry *ri;
546 ri = region_info_entry_from_lcid (lcid);
550 return construct_region (this_obj, ri);
554 ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name (MonoRegionInfo *this_obj,
557 const RegionInfoNameEntry *ne;
560 n = mono_string_to_utf8 (name);
561 ne = (const RegionInfoNameEntry *)mono_binary_search (n, region_name_entries, NUM_REGION_ENTRIES,
562 sizeof (RegionInfoNameEntry), region_name_locator);
565 /*g_print ("ne (%s) is null\n", n);*/
571 return construct_region (this_obj, ®ion_entries [ne->region_entry_index]);
575 ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean neutral,
576 MonoBoolean specific, MonoBoolean installed)
581 MonoCultureInfo *culture;
583 const CultureInfoEntry *ci;
587 domain = mono_domain_get ();
590 for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
591 ci = &culture_entries [i];
592 is_neutral = ci->territory == 0;
593 if ((neutral && is_neutral) || (specific && !is_neutral))
597 klass = mono_class_get_culture_info_class ();
599 /* The InvariantCulture is not in culture_entries */
600 /* We reserve the first slot in the array for it */
604 ret = mono_array_new (domain, klass, len);
611 mono_array_setref (ret, len++, NULL);
613 for (i = 0; i < NUM_CULTURE_ENTRIES; i++) {
614 ci = &culture_entries [i];
615 is_neutral = ci->territory == 0;
616 if ((neutral && is_neutral) || (specific && !is_neutral)) {
617 culture = (MonoCultureInfo *) mono_object_new_checked (domain, klass, &error);
618 if (!is_ok (&error)) goto fail;
619 mono_runtime_object_init_checked ((MonoObject *) culture, &error);
620 if (!is_ok (&error)) goto fail;
621 construct_culture (culture, ci);
622 culture->use_user_override = TRUE;
623 mono_array_setref (ret, len++, culture);
630 mono_error_set_pending_exception (&error);
634 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)
636 /* Do a normal ascii string compare, as we only know the
637 * invariant locale if we dont have ICU
639 return(string_invariant_compare (str1, off1, len1, str2, off2, len2,
643 void ves_icall_System_Globalization_CompareInfo_assign_sortkey (MonoCompareInfo *this_obj, MonoSortKey *key, MonoString *source, gint32 options)
648 keylen=mono_string_length (source);
650 arr=mono_array_new (mono_domain_get (), mono_get_byte_class (),
652 for(i=0; i<keylen; i++) {
653 mono_array_set (arr, guint8, i, mono_string_chars (source)[i]);
656 MONO_OBJECT_SETREF (key, key, arr);
659 int ves_icall_System_Globalization_CompareInfo_internal_index (MonoCompareInfo *this_obj, MonoString *source, gint32 sindex, gint32 count, MonoString *value, gint32 options, MonoBoolean first)
661 return(string_invariant_indexof (source, sindex, count, value, first));
664 int ves_icall_System_Globalization_CompareInfo_internal_index_char (MonoCompareInfo *this_obj, MonoString *source, gint32 sindex, gint32 count, gunichar2 value, gint32 options, MonoBoolean first)
666 return(string_invariant_indexof_char (source, sindex, count, value,
670 int ves_icall_System_Threading_Thread_current_lcid (void)
676 static gint32 string_invariant_compare_char (gunichar2 c1, gunichar2 c2,
681 /* Ordinal can not be mixed with other options, and must return the difference, not only -1, 0, 1 */
682 if (options & CompareOptions_Ordinal)
683 return (gint32) c1 - c2;
685 if (options & CompareOptions_IgnoreCase) {
686 GUnicodeType c1type, c2type;
688 c1type = g_unichar_type (c1);
689 c2type = g_unichar_type (c2);
691 result = (gint32) (c1type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c1) : c1) -
692 (c2type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c2) : c2);
695 * No options. Kana, symbol and spacing options don't
696 * apply to the invariant culture.
700 * FIXME: here we must use the information from c1type and c2type
701 * to find out the proper collation, even on the InvariantCulture, the
702 * sorting is not done by computing the unicode values, but their
705 result = (gint32) c1 - c2;
708 return ((result < 0) ? -1 : (result > 0) ? 1 : 0);
711 static gint32 string_invariant_compare (MonoString *str1, gint32 off1,
712 gint32 len1, MonoString *str2,
713 gint32 off2, gint32 len2,
716 /* c translation of C# code from old string.cs.. :) */
729 ustr1 = mono_string_chars(str1)+off1;
730 ustr2 = mono_string_chars(str2)+off2;
734 for (pos = 0; pos != length; pos++) {
735 if (pos >= len1 || pos >= len2)
738 charcmp = string_invariant_compare_char(ustr1[pos], ustr2[pos],
745 /* the lesser wins, so if we have looped until length we just
746 * need to check the last char
749 return(string_invariant_compare_char(ustr1[pos - 1],
750 ustr2[pos - 1], options));
753 /* Test if one of the strings has been compared to the end */
760 } else if (pos >= len2) {
764 /* if not, check our last char only.. (can this happen?) */
765 return(string_invariant_compare_char(ustr1[pos], ustr2[pos], options));
768 static gint32 string_invariant_indexof (MonoString *source, gint32 sindex,
769 gint32 count, MonoString *value,
777 lencmpstr = mono_string_length(value);
779 src = mono_string_chars(source);
780 cmpstr = mono_string_chars(value);
784 for(pos=sindex;pos <= sindex+count;pos++) {
785 for(i=0;src[pos+i]==cmpstr[i];) {
794 for(pos=sindex-lencmpstr+1;pos>sindex-count;pos--) {
795 if(memcmp (src+pos, cmpstr,
796 lencmpstr*sizeof(gunichar2))==0) {
805 static gint32 string_invariant_indexof_char (MonoString *source, gint32 sindex,
806 gint32 count, gunichar2 value,
812 src = mono_string_chars(source);
814 for (pos = sindex; pos != count + sindex; pos++) {
815 if (src [pos] == value) {
822 for (pos = sindex; pos > sindex - count; pos--) {
823 if (src [pos] == value)
831 void ves_icall_System_Text_Normalization_load_normalization_resource (guint8 **argProps,
832 guint8 **argMappedChars,
833 guint8 **argCharMapIndex,
834 guint8 **argHelperIndex,
835 guint8 **argMapIdxToComposite,
836 guint8 **argCombiningClass)
838 #ifdef DISABLE_NORMALIZATION
839 mono_set_pending_exception (mono_get_exception_not_supported ("This runtime has been compiled without string normalization support."));
842 *argProps = (guint8*)props;
843 *argMappedChars = (guint8*) mappedChars;
844 *argCharMapIndex = (guint8*) charMapIndex;
845 *argHelperIndex = (guint8*) helperIndex;
846 *argMapIdxToComposite = (guint8*) mapIdxToComposite;
847 *argCombiningClass = (guint8*)combiningClass;