예제 #1
0
            public int Compare(UnmanagedStringArray.UnmanagedString string1, UnmanagedStringArray.UnmanagedString string2)
            {
                Debug.Assert(string1.IsNull == false);
                Debug.Assert(string2.IsNull == false);

                var string1State = new AlphanumericStringComparisonState(string1);
                var string2State = new AlphanumericStringComparisonState(string2);

                // Walk through two the strings with two markers.
                while (string1State.CurPositionInString < string1State.StringLength &&
                       string2State.CurPositionInString < string2State.StringLength)
                {
                    string1State.ScanNextAlphabeticOrNumericSequence();
                    string2State.ScanNextAlphabeticOrNumericSequence();

                    var result = string1State.CompareWithAnotherState(string2State);

                    if (result != 0)
                    {
                        return(result);
                    }
                }

                if (string1State.CurPositionInString < string1State.StringLength)
                {
                    return(1);
                }
                if (string2State.CurPositionInString < string2State.StringLength)
                {
                    return(-1);
                }

                return(0);
            }
            public unsafe int Compare(string string1, string string2)
            {
                if (string1 == null)
                {
                    return(0);
                }

                if (string2 == null)
                {
                    return(0);
                }

                var string1State = new AlphanumericStringComparisonState(string1);
                var string2State = new AlphanumericStringComparisonState(string2);

                // Walk through two the strings with two markers.
                while (string1State.CurPositionInString < string1State.StringLength &&
                       string2State.CurPositionInString < string2State.StringLength)
                {
                    string1State.ScanNextAlphabeticOrNumericSequence();
                    string2State.ScanNextAlphabeticOrNumericSequence();

                    var result = string1State.CompareWithAnotherState(string2State);

                    if (result != 0)
                    {
                        return(result);
                    }
                }

                if (string1State.CurPositionInString < string1State.StringLength)
                {
                    return(1);
                }
                if (string2State.CurPositionInString < string2State.StringLength)
                {
                    return(-1);
                }

                return(0);
            }