Пример #1
0
        public int CompareTo(UnicodeString str)
        {
            //int result = String.CompareTo(str.String);
            int result = string.Compare(String, str.String, StringComparison.CurrentCulture);

            //As per the Equals method lets do this in stages
            if (result != 0)
            {
                return(result);
            }

            //OK string appears to be equal but now lets compare formatting Runs
            if (field_4_format_runs == null)
            {
                //Strings are equal, and there are no formatting runs. -> 0
                //Strings are equal, but one or the other has formatting runs -> 1
                return((str.field_4_format_runs == null) ? 0 : 1);
            }
            else if (str.field_4_format_runs == null)
            {
                //Strings are equal, but one or the other has formatting runs
                return(-1);
            }

            //Strings are Equal, so now compare formatting Runs.
            int size = field_4_format_runs.Count;

            if (size != str.field_4_format_runs.Count)
            {
                return(size - str.field_4_format_runs.Count);
            }

            for (int i = 0; i < size; i++)
            {
                FormatRun Run1 = field_4_format_runs[(i)];
                FormatRun run2 = str.field_4_format_runs[(i)];

                result = Run1.CompareTo(run2);
                if (result != 0)
                {
                    return(result);
                }
            }

            //Well the format Runs are equal as well!, better check the ExtRst data
            if (field_5_ext_rst == null)
            {
                return((str.field_5_ext_rst == null) ? 0 : 1);
            }
            else if (str.field_5_ext_rst == null)
            {
                return(-1);
            }
            else
            {
                return(field_5_ext_rst.CompareTo(str.field_5_ext_rst));
            }
        }
Пример #2
0
        public int CompareTo(object obj)
        {
            UnicodeString str    = (UnicodeString)obj;
            int           result = this.String.CompareTo(str.String);

            //As per the equals method lets do this in stages
            if (result != 0)
            {
                return(result);
            }

            //OK string appears to be equal but now lets compare formatting Runs
            if ((field_4_format_Runs == null) && (str.field_4_format_Runs == null))
            {
                //Strings are equal, and there are no formatting Runs.
                return(0);
            }

            if ((field_4_format_Runs == null) && (str.field_4_format_Runs != null))
            {
                //Strings are equal, but one or the other has formatting Runs
                return(1);
            }
            if ((field_4_format_Runs != null) && (str.field_4_format_Runs == null))
            {
                //Strings are equal, but one or the other has formatting Runs
                return(-1);
            }

            //Strings are equal, so now compare formatting Runs.
            int size = field_4_format_Runs.Count;

            if (size != str.field_4_format_Runs.Count)
            {
                return(size - str.field_4_format_Runs.Count);
            }

            for (int i = 0; i < size; i++)
            {
                FormatRun Run1 = field_4_format_Runs[i];
                FormatRun Run2 = str.field_4_format_Runs[i];

                result = Run1.CompareTo(Run2);
                if (result != 0)
                {
                    return(result);
                }
            }

            //Well the format Runs are equal as well!, better check the ExtRst data
            //Which by the way we don't know how to decode!
            if ((field_5_ext_rst == null) && (str.field_5_ext_rst == null))
            {
                return(0);
            }
            if ((field_5_ext_rst == null) && (str.field_5_ext_rst != null))
            {
                return(1);
            }
            if ((field_5_ext_rst != null) && (str.field_5_ext_rst == null))
            {
                return(-1);
            }

            size = field_5_ext_rst.Length;
            if (size != field_5_ext_rst.Length)
            {
                return(size - field_5_ext_rst.Length);
            }

            //Check individual bytes!
            for (int i = 0; i < size; i++)
            {
                if (field_5_ext_rst[i] != str.field_5_ext_rst[i])
                {
                    return(field_5_ext_rst[i] - str.field_5_ext_rst[i]);
                }
            }
            //Phew!! After all of that we have finally worked out that the strings
            //are identical.
            return(0);
        }
Пример #3
0
        public int CompareTo(UnicodeString str)
        {
            //int result = String.CompareTo(str.String);
            int result = string.Compare(String, str.String, StringComparison.CurrentCulture);

            //As per the Equals method lets do this in stages
            if (result != 0)
            {
                return(result);
            }

            //OK string appears to be equal but now lets compare formatting Runs
            if ((field_4_format_Runs == null) && (str.field_4_format_Runs == null))
            {
                //Strings are Equal, and there are no formatting Runs.
                return(0);
            }

            if ((field_4_format_Runs == null) && (str.field_4_format_Runs != null))
            {
                //Strings are Equal, but one or the other has formatting Runs
                return(1);
            }
            if ((field_4_format_Runs != null) && (str.field_4_format_Runs == null))
            {
                //Strings are Equal, but one or the other has formatting Runs
                return(-1);
            }

            //Strings are Equal, so now compare formatting Runs.
            int size = field_4_format_Runs.Count;

            if (size != str.field_4_format_Runs.Count)
            {
                return(size - str.field_4_format_Runs.Count);
            }

            for (int i = 0; i < size; i++)
            {
                FormatRun Run1 = field_4_format_Runs[(i)];
                FormatRun run2 = str.field_4_format_Runs[(i)];

                result = Run1.CompareTo(run2);
                if (result != 0)
                {
                    return(result);
                }
            }

            //Well the format Runs are equal as well!, better check the ExtRst data
            if ((field_5_ext_rst == null) && (str.field_5_ext_rst == null))
            {
                return(0);
            }
            if ((field_5_ext_rst == null) && (str.field_5_ext_rst != null))
            {
                return(1);
            }
            if ((field_5_ext_rst != null) && (str.field_5_ext_rst == null))
            {
                return(-1);
            }

            result = field_5_ext_rst.CompareTo(str.field_5_ext_rst);
            if (result != 0)
            {
                return(result);
            }

            //Phew!! After all of that we have finally worked out that the strings
            //are identical.
            return(0);
        }