We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- namespace System.Globalization
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
- using System;
- using System.Collections;
- using System.Reflection;
- using System.Runtime.Serialization;
- using System.Runtime.CompilerServices;
- using System.Runtime.ConstrainedExecution;
- using System.Threading;
- using System.Security.Permissions;
- using System.Runtime.InteropServices;
- using Microsoft.Win32;
-
-
-
-
-
-
-
-
-
- [Flags(), Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public enum CompareOptions
- {
-
- None = 0,
-
- IgnoreCase = 1,
-
- IgnoreNonSpace = 2,
-
- IgnoreSymbols = 4,
-
- IgnoreKanaType = 8,
-
- IgnoreWidth = 16,
-
- OrdinalIgnoreCase = 268435456,
-
- StringSort = 536870912,
-
- Ordinal = 1073741824
-
-
-
-
-
- }
-
-
- [Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public class CompareInfo : IDeserializationCallback
- {
-
-
- private const CompareOptions ValidIndexMaskOffFlags = ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType);
-
- private const CompareOptions ValidCompareMaskOffFlags = ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType | CompareOptions.StringSort);
-
- private const CompareOptions ValidHashCodeOfStringMaskOffFlags = ~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe static internal extern byte[] nativeCreateSortKey(void* pSortingFile, string pString, int dwFlags, int win32LCID);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe static internal extern int nativeGetGlobalizedHashCode(void* pSortingFile, string pString, int dwFlags, int win32LCID);
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe static internal extern bool nativeIsSortable(void* pSortingFile, string pString);
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- static internal extern int nativeCompareString(int lcid, string string1, int offset1, int length1, string string2, int offset2, int length2, int flags);
-
- private static object s_InternalSyncObject;
- private static object InternalSyncObject {
- get {
- if (s_InternalSyncObject == null) {
- object o = new object();
- Interlocked.CompareExchange(ref s_InternalSyncObject, o, null);
- }
- return s_InternalSyncObject;
- }
- }
-
-
-
-
-
-
- public static CompareInfo GetCompareInfo(int culture, Assembly assembly)
- {
-
- if (assembly == null) {
- throw new ArgumentNullException("assembly");
- }
-
- if (CultureTableRecord.IsCustomCultureId(culture)) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", "culture"));
- }
- if (assembly != typeof(object).Module.Assembly) {
- throw new ArgumentException(Environment.GetResourceString("Argument_OnlyMscorlib"));
- }
-
-
-
- GlobalizationAssembly ga = GlobalizationAssembly.GetGlobalizationAssembly(assembly);
- object compInfo = ga.compareInfoCache[culture];
- if (compInfo == null) {
- lock (InternalSyncObject) {
-
-
-
-
- if ((compInfo = ga.compareInfoCache[culture]) == null) {
- compInfo = new CompareInfo(ga, culture);
- System.Threading.Thread.MemoryBarrier();
- ga.compareInfoCache[culture] = compInfo;
- }
- }
- }
-
- return ((CompareInfo)compInfo);
- }
-
-
-
-
-
-
-
- private const int TraditionalChineseCultureId = 31748;
- private const int HongKongCultureId = 3076;
-
- private static CompareInfo GetCompareInfoByName(string name, Assembly assembly)
- {
- CultureInfo cultureInfo = CultureInfo.GetCultureInfo(name);
- if (cultureInfo.IsNeutralCulture && !CultureTableRecord.IsCustomCultureId(cultureInfo.cultureID)) {
- if (cultureInfo.cultureID == TraditionalChineseCultureId)
- cultureInfo = CultureInfo.GetCultureInfo(HongKongCultureId);
- else
- cultureInfo = CultureInfo.GetCultureInfo(cultureInfo.CompareInfoId);
- }
-
- CompareInfo compareInfo;
-
- if (assembly != null)
- compareInfo = GetCompareInfo(cultureInfo.CompareInfoId, assembly);
- else
- compareInfo = GetCompareInfo(cultureInfo.CompareInfoId);
-
-
- compareInfo.m_name = cultureInfo.SortName;
-
- return compareInfo;
- }
-
-
-
-
- public static CompareInfo GetCompareInfo(string name, Assembly assembly)
- {
- if (name == null || assembly == null) {
- throw new ArgumentNullException(name == null ? "name" : "assembly");
- }
-
- if (assembly != typeof(object).Module.Assembly) {
- throw new ArgumentException(Environment.GetResourceString("Argument_OnlyMscorlib"));
- }
-
- return GetCompareInfoByName(name, assembly);
- }
-
-
-
- public static CompareInfo GetCompareInfo(int culture)
- {
-
- if (CultureTableRecord.IsCustomCultureId(culture)) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", "culture"));
- }
-
-
- object compInfo = GlobalizationAssembly.DefaultInstance.compareInfoCache[culture];
- if (compInfo == null) {
- lock (InternalSyncObject) {
-
-
-
-
- if ((compInfo = GlobalizationAssembly.DefaultInstance.compareInfoCache[culture]) == null) {
- compInfo = new CompareInfo(GlobalizationAssembly.DefaultInstance, culture);
- System.Threading.Thread.MemoryBarrier();
- GlobalizationAssembly.DefaultInstance.compareInfoCache[culture] = compInfo;
- }
- }
- }
- return ((CompareInfo)compInfo);
- }
-
-
-
- public static CompareInfo GetCompareInfo(string name)
- {
- if (name == null) {
- throw new ArgumentNullException("name");
- }
-
- return GetCompareInfoByName(name, null);
- }
-
- [System.Runtime.InteropServices.ComVisible(false)]
- public static bool IsSortable(char ch)
- {
- return (IsSortable(ch.ToString()));
- }
-
- [System.Runtime.InteropServices.ComVisible(false)]
- public static bool IsSortable(string text)
- {
- if (text == null) {
-
- throw new ArgumentNullException("text");
- }
-
- if (0 == text.Length) {
-
- return (false);
- }
-
- unsafe {
- return (nativeIsSortable(CultureInfo.InvariantCulture.CompareInfo.m_pSortingTable, text));
- }
- }
-
- #region Serialization
- private int win32LCID;
-
- private int culture;
-
- [OnDeserializing()]
- private void OnDeserializing(StreamingContext ctx)
- {
- this.culture = -1;
- this.m_sortingLCID = -1;
- }
-
- unsafe private void OnDeserialized()
- {
- BCLDebug.Assert(this.culture >= 0, "[CompareInfo.OnDeserialized] - culture >= 0");
-
-
- if (m_sortingLCID <= 0) {
- m_sortingLCID = GetSortingLCID(this.culture);
- }
- if (m_pSortingTable == null && !IsSynthetic) {
- m_pSortingTable = InitializeCompareInfo(GlobalizationAssembly.DefaultInstance.pNativeGlobalizationAssembly, this.m_sortingLCID);
- }
- BCLDebug.Assert(IsSynthetic || m_pSortingTable != null, "m_pSortingTable != null");
-
- }
-
-
- [OnDeserialized()]
- private void OnDeserialized(StreamingContext ctx)
- {
- OnDeserialized();
- }
-
- [OnSerializing()]
- private void OnSerializing(StreamingContext ctx)
- {
- win32LCID = m_sortingLCID;
- }
- #endregion Serialization
-
- ///////////////////////////----- Name -----/////////////////////////////////
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
- [System.Runtime.InteropServices.ComVisible(false)]
- public virtual string Name {
- get {
- if (m_name == null) {
- m_name = CultureInfo.GetCultureInfo(culture).SortName;
- }
-
- return (m_name);
- }
- }
-
- internal void SetName(string name)
- {
- m_name = name;
- }
-
- static internal void ClearDefaultAssemblyCache()
- {
- lock (InternalSyncObject) {
- GlobalizationAssembly.DefaultInstance.compareInfoCache = new Hashtable(4);
- }
- }
-
-
- internal CultureTableRecord CultureTableRecord {
- get {
- if (m_cultureTableRecord == null) {
- m_cultureTableRecord = CultureInfo.GetCultureInfo(this.m_sortingLCID).m_cultureTableRecord;
- }
-
- return m_cultureTableRecord;
- }
- }
-
-
- private bool IsSynthetic {
- get { return CultureTableRecord.IsSynthetic; }
- }
-
-
-
-
- [NonSerialized()]
- unsafe internal void* m_pSortingTable;
- [NonSerialized()]
- private int m_sortingLCID;
-
- [NonSerialized()]
- private CultureTableRecord m_cultureTableRecord;
-
- [OptionalField(VersionAdded = 2)]
- private string m_name = null;
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
- unsafe internal CompareInfo(GlobalizationAssembly ga, int culture)
- {
- if (culture < 0) {
- throw new ArgumentOutOfRangeException("culture", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
- }
-
- this.m_sortingLCID = GetSortingLCID(culture);
-
-
-
-
-
-
-
- if (!IsSynthetic) {
- m_pSortingTable = InitializeCompareInfo(GlobalizationAssembly.DefaultInstance.pNativeGlobalizationAssembly, this.m_sortingLCID);
- }
-
- this.culture = culture;
-
- }
-
-
- internal int GetSortingLCID(int culture)
- {
- int sortingLCID = 0;
-
-
-
- CultureInfo cultureObj = CultureInfo.GetCultureInfo(culture);
-
-
- sortingLCID = cultureObj.CompareInfoId;
-
- int sortID = CultureInfo.GetSortID(culture);
- if (sortID != 0) {
-
- if (!cultureObj.m_cultureTableRecord.IsValidSortID(sortID)) {
- throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_CultureNotSupported"), culture), "culture");
- }
-
- sortingLCID |= sortID << 16;
- }
- return (sortingLCID);
-
- }
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- public virtual int Compare(string string1, string string2)
- {
- return (Compare(string1, string2, CompareOptions.None));
- }
-
-
- unsafe public virtual int Compare(string string1, string string2, CompareOptions options)
- {
-
- if (options == CompareOptions.OrdinalIgnoreCase) {
- return String.Compare(string1, string2, StringComparison.OrdinalIgnoreCase);
- }
-
-
- if ((options & CompareOptions.Ordinal) != 0) {
- if (options == CompareOptions.Ordinal) {
-
-
- if (string1 == null) {
- if (string2 == null) {
- return (0);
-
- }
- return (-1);
-
- }
- if (string2 == null) {
- return (1);
-
- }
-
- return String.nativeCompareOrdinal(string1, string2, false);
- }
- else {
- throw new ArgumentException(Environment.GetResourceString("Argument_CompareOptionOrdinal"), "options");
- }
- }
- if ((options & ValidCompareMaskOffFlags) != 0) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
- }
-
-
-
- if (string1 == null) {
- if (string2 == null) {
- return (0);
-
- }
- return (-1);
-
- }
- if (string2 == null) {
- return (1);
-
- }
-
-
- return (Compare(m_pSortingTable, this.m_sortingLCID, string1, string2, options));
- }
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern int Compare(void* pSortingTable, int sortingLCID, string string1, string string2, CompareOptions options);
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- unsafe public virtual int Compare(string string1, int offset1, int length1, string string2, int offset2, int length2)
- {
- return Compare(string1, offset1, length1, string2, offset2, length2, 0);
- }
-
-
- unsafe public virtual int Compare(string string1, int offset1, string string2, int offset2, CompareOptions options)
- {
- return Compare(string1, offset1, string1 == null ? 0 : string1.Length - offset1, string2, offset2, string2 == null ? 0 : string2.Length - offset2, options);
- }
-
-
- unsafe public virtual int Compare(string string1, int offset1, string string2, int offset2)
- {
- return Compare(string1, offset1, string2, offset2, 0);
- }
-
-
- unsafe public virtual int Compare(string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options)
- {
- if (options == CompareOptions.OrdinalIgnoreCase) {
- int result = String.Compare(string1, offset1, string2, offset2, length1 < length2 ? length1 : length2, StringComparison.OrdinalIgnoreCase);
- if ((length1 != length2) && result == 0)
- return (length1 > length2 ? 1 : -1);
- return (result);
- }
-
-
- if (length1 < 0 || length2 < 0) {
- throw new ArgumentOutOfRangeException((length1 < 0) ? "length1" : "length2", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
- }
- if (offset1 < 0 || offset2 < 0) {
- throw new ArgumentOutOfRangeException((offset1 < 0) ? "offset1" : "offset2", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
- }
- if (offset1 > (string1 == null ? 0 : string1.Length) - length1) {
- throw new ArgumentOutOfRangeException("string1", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength"));
- }
- if (offset2 > (string2 == null ? 0 : string2.Length) - length2) {
- throw new ArgumentOutOfRangeException("string2", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength"));
- }
- if ((options & CompareOptions.Ordinal) != 0) {
- if (options == CompareOptions.Ordinal) {
-
-
-
- if (string1 == null) {
- if (string2 == null) {
- return (0);
- }
- return (-1);
- }
- if (string2 == null) {
- return (1);
- }
-
- int result = String.nativeCompareOrdinalEx(string1, offset1, string2, offset2, (length1 < length2 ? length1 : length2));
- if ((length1 != length2) && result == 0) {
- return (length1 > length2 ? 1 : -1);
- }
- return (result);
- }
- else {
- throw new ArgumentException(Environment.GetResourceString("Argument_CompareOptionOrdinal"), "options");
- }
- }
- if ((options & ValidCompareMaskOffFlags) != 0) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
- }
-
-
-
-
- if (string1 == null) {
- if (string2 == null) {
- return (0);
- }
- return (-1);
- }
- if (string2 == null) {
- return (1);
- }
-
-
-
- return (CompareRegion(m_pSortingTable, this.m_sortingLCID, string1, offset1, length1, string2, offset2, length2, options));
- }
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern int CompareRegion(void* pSortingTable, int sortingLCID, string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options);
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- unsafe public virtual bool IsPrefix(string source, string prefix, CompareOptions options)
- {
- if (source == null || prefix == null) {
- throw new ArgumentNullException((source == null ? "source" : "prefix"), Environment.GetResourceString("ArgumentNull_String"));
- }
- int prefixLen = prefix.Length;
-
- if (prefixLen == 0) {
- return (true);
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase) {
- return source.StartsWith(prefix, StringComparison.OrdinalIgnoreCase);
- }
-
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal)) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
- }
-
-
- return (nativeIsPrefix(m_pSortingTable, this.m_sortingLCID, source, prefix, options));
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern bool nativeIsPrefix(void* pSortingTable, int sortingLCID, string source, string prefix, CompareOptions options);
-
-
- public virtual bool IsPrefix(string source, string prefix)
- {
- return (IsPrefix(source, prefix, 0));
- }
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- unsafe public virtual bool IsSuffix(string source, string suffix, CompareOptions options)
- {
- if (source == null || suffix == null) {
- throw new ArgumentNullException((source == null ? "source" : "suffix"), Environment.GetResourceString("ArgumentNull_String"));
- }
- int suffixLen = suffix.Length;
-
- if (suffixLen == 0) {
- return (true);
- }
-
- if (options == CompareOptions.OrdinalIgnoreCase) {
- return source.EndsWith(suffix, StringComparison.OrdinalIgnoreCase);
- }
-
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal)) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
- }
-
-
- return (nativeIsSuffix(m_pSortingTable, this.m_sortingLCID, source, suffix, options));
- }
-
-
- public virtual bool IsSuffix(string source, string suffix)
- {
- return (IsSuffix(source, suffix, 0));
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern bool nativeIsSuffix(void* pSortingTable, int sortingLCID, string source, string prefix, CompareOptions options);
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- unsafe public virtual int IndexOf(string source, char value)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, 0, source.Length, CompareOptions.None);
- }
-
-
- unsafe public virtual int IndexOf(string source, string value)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, 0, source.Length, CompareOptions.None);
- }
-
-
- unsafe public virtual int IndexOf(string source, char value, CompareOptions options)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, 0, source.Length, options);
- }
-
-
- unsafe public virtual int IndexOf(string source, string value, CompareOptions options)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, 0, source.Length, options);
- }
-
-
- unsafe public virtual int IndexOf(string source, char value, int startIndex)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None);
- }
-
-
- unsafe public virtual int IndexOf(string source, string value, int startIndex)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None);
- }
-
-
- unsafe public virtual int IndexOf(string source, char value, int startIndex, CompareOptions options)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, options);
- }
-
-
- unsafe public virtual int IndexOf(string source, string value, int startIndex, CompareOptions options)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
- return IndexOf(source, value, startIndex, source.Length - startIndex, options);
- }
-
-
- unsafe public virtual int IndexOf(string source, char value, int startIndex, int count)
- {
- return IndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
-
- unsafe public virtual int IndexOf(string source, string value, int startIndex, int count)
- {
- return IndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
-
- unsafe public virtual int IndexOf(string source, char value, int startIndex, int count, CompareOptions options)
- {
-
- if (source == null)
- throw new ArgumentNullException("source");
-
- if (startIndex < 0 || startIndex > source.Length)
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
-
- if (count < 0 || startIndex > source.Length - count)
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
-
- if (options == CompareOptions.OrdinalIgnoreCase) {
- return TextInfo.nativeIndexOfCharOrdinalIgnoreCase(TextInfo.InvariantNativeTextInfo, source, value, startIndex, count);
- }
-
-
-
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
-
-
- return IndexOfChar(m_pSortingTable, this.m_sortingLCID, source, value, startIndex, count, (int)options);
- }
-
-
- unsafe public virtual int IndexOf(string source, string value, int startIndex, int count, CompareOptions options)
- {
-
- if (source == null)
- throw new ArgumentNullException("source");
- if (value == null)
- throw new ArgumentNullException("value");
-
- if (startIndex > source.Length) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- if (source.Length == 0) {
- if (value.Length == 0) {
- return 0;
- }
- return -1;
- }
-
- if (startIndex < 0) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- if (count < 0 || startIndex > source.Length - count)
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
-
- if (options == CompareOptions.OrdinalIgnoreCase) {
- return TextInfo.IndexOfStringOrdinalIgnoreCase(source, value, startIndex, count);
- }
-
-
-
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
-
-
- return IndexOfString(m_pSortingTable, this.m_sortingLCID, source, value, startIndex, count, (int)options);
- }
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern int IndexOfChar(void* pSortingTable, int sortingLCID, string source, char value, int startIndex, int count, int options);
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe private static extern int IndexOfString(void* pSortingTable, int sortingLCID, string source, string value, int startIndex, int count, int options);
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- unsafe public virtual int LastIndexOf(string source, char value)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
-
- return LastIndexOf(source, value, source.Length - 1, source.Length, CompareOptions.None);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, string value)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
-
- return LastIndexOf(source, value, source.Length - 1, source.Length, CompareOptions.None);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, char value, CompareOptions options)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
-
- return LastIndexOf(source, value, source.Length - 1, source.Length, options);
- }
-
- unsafe public virtual int LastIndexOf(string source, string value, CompareOptions options)
- {
- if (source == null)
- throw new ArgumentNullException("source");
-
-
- return LastIndexOf(source, value, source.Length - 1, source.Length, options);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, char value, int startIndex)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, CompareOptions.None);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, string value, int startIndex)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, CompareOptions.None);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, char value, int startIndex, CompareOptions options)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, options);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, string value, int startIndex, CompareOptions options)
- {
- return LastIndexOf(source, value, startIndex, startIndex + 1, options);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, char value, int startIndex, int count)
- {
- return LastIndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, string value, int startIndex, int count)
- {
- return LastIndexOf(source, value, startIndex, count, CompareOptions.None);
- }
-
-
- unsafe public virtual int LastIndexOf(string source, char value, int startIndex, int count, CompareOptions options)
- {
-
- if (source == null)
- throw new ArgumentNullException("source");
-
-
-
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal) && (options != CompareOptions.OrdinalIgnoreCase))
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
-
-
- if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
- return -1;
-
-
- if (startIndex < 0 || startIndex > source.Length)
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
-
-
- if (startIndex == source.Length) {
- startIndex--;
- if (count > 0)
- count--;
- }
-
-
- if (count < 0 || startIndex - count + 1 < 0)
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
-
- if (options == CompareOptions.OrdinalIgnoreCase) {
- return TextInfo.nativeLastIndexOfCharOrdinalIgnoreCase(TextInfo.InvariantNativeTextInfo, source, value, startIndex, count);
- }
-
-
- return (LastIndexOfChar(m_pSortingTable, this.m_sortingLCID, source, value, startIndex, count, (int)options));
- }
-
-
- unsafe public virtual int LastIndexOf(string source, string value, int startIndex, int count, CompareOptions options)
- {
-
- if (source == null)
- throw new ArgumentNullException("source");
- if (value == null)
- throw new ArgumentNullException("value");
-
-
-
- if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal) && (options != CompareOptions.OrdinalIgnoreCase))
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
-
-
- if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
- return (value.Length == 0) ? 0 : -1;
-
-
- if (startIndex < 0 || startIndex > source.Length)
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
-
-
- if (startIndex == source.Length) {
- startIndex--;
- if (count > 0)
- count--;
-
-
- if (value.Length == 0 && count >= 0 && startIndex - count + 1 >= 0)
- return startIndex;
- }
-
-
- if (count < 0 || startIndex - count + 1 < 0)
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
-
- if (options == CompareOptions.OrdinalIgnoreCase) {
- return TextInfo.LastIndexOfStringOrdinalIgnoreCase(source, value, startIndex, count);
- }
-
-
- return (LastIndexOfString(m_pSortingTable, this.m_sortingLCID, source, value, startIndex, count, (int)options));
- }
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe static internal extern int LastIndexOfChar(void* pSortingTable, int sortingLCID, string source, char value, int startIndex, int count, int options);
-
-
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- unsafe static internal extern int LastIndexOfString(void* pSortingTable, int sortingLCID, string source, string value, int startIndex, int count, int options);
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- unsafe public virtual SortKey GetSortKey(string source, CompareOptions options)
- {
-
-
-
- return (new SortKey(m_pSortingTable, this.m_sortingLCID, source, options));
- }
-
-
- unsafe public virtual SortKey GetSortKey(string source)
- {
-
-
-
- return (new SortKey(m_pSortingTable, this.m_sortingLCID, source, CompareOptions.None));
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- public override bool Equals(object value)
- {
- CompareInfo that = value as CompareInfo;
-
- if (that != null) {
- return this.m_sortingLCID == that.m_sortingLCID && this.Name.Equals(that.Name);
- }
-
- return (false);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- public override int GetHashCode()
- {
- return (this.Name.GetHashCode());
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
- unsafe internal int GetHashCodeOfString(string source, CompareOptions options)
- {
-
-
-
- if (null == source) {
- throw new ArgumentNullException("source");
- }
-
- if ((options & ValidHashCodeOfStringMaskOffFlags) != 0) {
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options");
- }
-
- if (0 == source.Length) {
- return (0);
- }
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- return (nativeGetGlobalizedHashCode(m_pSortingTable, source, (int)options, this.m_sortingLCID));
- }
-
- ////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////
-
-
- public override string ToString()
- {
- return ("CompareInfo - " + this.culture);
- }
-
-
- public int LCID {
- get { return (this.culture); }
- }
-
-
-
-
-
-
- unsafe private static void* InitializeCompareInfo(void* pNativeGlobalizationAssembly, int sortingLCID)
- {
- }
-
- void* pTemp = null;
-
- bool tookLock = false;
- }
- }