Skip to content

Commit

Permalink
2009-10-07 Sebastien Pouliot <sebastien@ximian.com>
Browse files Browse the repository at this point in the history
	* CompareInfo.cs: Don't allow MONO_DISABLE_MANAGED_COLLATION
	override for Moonlight and move all icalls together so they
	can be #if-ed out.
	[Backport r143648]


svn path=/branches/mono-2-6/mcs/; revision=143649
  • Loading branch information
Sebastien Pouliot committed Oct 7, 2009
1 parent c3f5ca8 commit e7702bf
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 50 deletions.
7 changes: 7 additions & 0 deletions mcs/class/corlib/System.Globalization/ChangeLog
@@ -1,3 +1,10 @@
2009-10-07 Sebastien Pouliot <sebastien@ximian.com>

* CompareInfo.cs: Don't allow MONO_DISABLE_MANAGED_COLLATION
override for Moonlight and move all icalls together so they
can be #if-ed out.
[Backport r143648]

2009-09-23 Sebastien Pouliot <sebastien@ximian.com>

* Calendar.cs: Don't expose AlgorithmType property in NET_2_1
Expand Down
146 changes: 96 additions & 50 deletions mcs/class/corlib/System.Globalization/CompareInfo.cs
Expand Up @@ -40,12 +40,11 @@

namespace System.Globalization
{
#if NET_2_0
[ComVisible (true)]
#endif
[Serializable]
public class CompareInfo : IDeserializationCallback
{
#if !NET_2_1 || MONOTOUCH
[ComVisible (true)]
public class CompareInfo : IDeserializationCallback {

static readonly bool useManagedCollation =
Environment.internalGetEnvironmentVariable ("MONO_DISABLE_MANAGED_COLLATION")
!= "yes" && MSCompatUnicodeTable.IsReady;
Expand All @@ -54,6 +53,57 @@ public class CompareInfo : IDeserializationCallback
get { return useManagedCollation; }
}

void IDeserializationCallback.OnDeserialization(object sender)
{
if (UseManagedCollation) {
collator = new SimpleCollator (new CultureInfo (culture));
} else {
/* This will build the ICU collator, and store
* the pointer in ICU_collator
*/
try {
this.construct_compareinfo (icu_name);
} catch {
// ICU_collator=IntPtr.Zero;
}
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern void construct_compareinfo (string locale);

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern void free_internal_collator ();

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern int internal_compare (string str1, int offset1,
int length1, string str2,
int offset2, int length2,
CompareOptions options);

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern void assign_sortkey (object key, string source,
CompareOptions options);

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern int internal_index (string source, int sindex,
int count, char value,
CompareOptions options,
bool first);

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern int internal_index (string source, int sindex,
int count, string value,
CompareOptions options,
bool first);

#else
public class CompareInfo {
internal static bool UseManagedCollation {
get { return true; }
}
#endif

// Keep in synch with MonoCompareInfo in the runtime.
private int culture;
[NonSerialized]
Expand Down Expand Up @@ -81,9 +131,6 @@ public class CompareInfo : IDeserializationCallback
/* Hide the .ctor() */
CompareInfo() {}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern void construct_compareinfo (string locale);

internal CompareInfo (CultureInfo ci)
{
this.culture = ci.LCID;
Expand All @@ -98,25 +145,21 @@ internal CompareInfo (CultureInfo ci)
}
}
} else {
#if !NET_2_1 || MONOTOUCH
this.icu_name = ci.IcuName;
this.construct_compareinfo (icu_name);
#endif
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern void free_internal_collator ();

~CompareInfo ()
{
#if !NET_2_1 || MONOTOUCH
free_internal_collator ();
#endif
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern int internal_compare (string str1, int offset1,
int length1, string str2,
int offset2, int length2,
CompareOptions options);

#if !NET_2_1 || MONOTOUCH
private int internal_compare_managed (string str1, int offset1,
int length1, string str2,
int offset2, int length2,
Expand All @@ -137,7 +180,16 @@ internal CompareInfo (CultureInfo ci)
internal_compare (str1, offset1, length1,
str2, offset2, length2, options);
}

#else
private int internal_compare_switch (string str1, int offset1,
int length1, string str2,
int offset2, int length2,
CompareOptions options)
{
return collator.Compare (str1, offset1, length1,
str2, offset2, length2, options);
}
#endif
public virtual int Compare (string string1, string string2)
{
if (string1 == null) {
Expand Down Expand Up @@ -421,10 +473,6 @@ public override int GetHashCode()
{
return(LCID);
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern void assign_sortkey (object key, string source,
CompareOptions options);

public virtual SortKey GetSortKey(string source)
{
Expand All @@ -441,6 +489,7 @@ public virtual SortKey GetSortKey(string source)
throw new ArgumentException ("Now allowed CompareOptions.", "options");
}
#endif
#if !NET_2_1 || MONOTOUCH
if (UseManagedCollation)
return collator.GetSortKey (source, options);
SortKey key=new SortKey (culture, source, options);
Expand All @@ -452,6 +501,9 @@ public virtual SortKey GetSortKey(string source)
assign_sortkey (key, source, options);

return(key);
#else
return collator.GetSortKey (source, options);
#endif
}

public virtual int IndexOf (string source, char value)
Expand Down Expand Up @@ -526,12 +578,7 @@ public virtual int IndexOf (string source, string value)
CompareOptions.None));
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern int internal_index (string source, int sindex,
int count, char value,
CompareOptions options,
bool first);

#if !NET_2_1 || MONOTOUCH
private int internal_index_managed (string s, int sindex,
int count, char c, CompareOptions opt,
bool first)
Expand All @@ -553,6 +600,16 @@ public virtual int IndexOf (string source, string value)
internal_index_managed (s, sindex, count, c, opt, first) :
internal_index (s, sindex, count, c, opt, first);
}
#else
private int internal_index_switch (string s, int sindex,
int count, char c, CompareOptions opt,
bool first)
{
return first ?
collator.IndexOf (s, c, sindex, count, opt) :
collator.LastIndexOf (s, c, sindex, count, opt);
}
#endif

public virtual int IndexOf (string source, char value,
int startIndex, int count,
Expand Down Expand Up @@ -591,12 +648,7 @@ public virtual int IndexOf (string source, string value)
}
}

[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern int internal_index (string source, int sindex,
int count, string value,
CompareOptions options,
bool first);

#if !NET_2_1 || MONOTOUCH
private int internal_index_managed (string s1, int sindex,
int count, string s2, CompareOptions opt,
bool first)
Expand All @@ -618,6 +670,16 @@ public virtual int IndexOf (string source, string value)
internal_index_managed (s1, sindex, count, s2, opt, first) :
internal_index (s1, sindex, count, s2, opt, first);
}
#else
private int internal_index_switch (string s1, int sindex,
int count, string s2, CompareOptions opt,
bool first)
{
return first ?
collator.IndexOf (s1, s2, sindex, count, opt) :
collator.LastIndexOf (s1, s2, sindex, count, opt);
}
#endif

public virtual int IndexOf (string source, string value,
int startIndex, int count,
Expand Down Expand Up @@ -860,22 +922,6 @@ public override string ToString()
return("CompareInfo - "+culture);
}

void IDeserializationCallback.OnDeserialization(object sender)
{
if (UseManagedCollation) {
collator = new SimpleCollator (new CultureInfo (culture));
} else {
/* This will build the ICU collator, and store
* the pointer in ICU_collator
*/
try {
this.construct_compareinfo (icu_name);
} catch {
// ICU_collator=IntPtr.Zero;
}
}
}

/* LAMESPEC: not mentioned in the spec, but corcompare
* shows it. Some documentation about what it does
* would be nice.
Expand Down

0 comments on commit e7702bf

Please sign in to comment.